Lind 3 лет назад
Родитель
Сommit
54355256d0

+ 154 - 141
src/pages/device/Instance/Detail/ChildDevice/BindChildDevice/index.tsx

@@ -1,158 +1,171 @@
-import { Badge, Button, Modal } from "antd";
+import { Badge, Button, Modal } from 'antd';
 import type { DeviceInstance } from '@/pages/device/Instance/typings';
-import SearchComponent from "@/components/SearchComponent";
-import type { ActionType, ProColumns } from "@jetlinks/pro-table";
-import ProTable from "@jetlinks/pro-table";
-import { useRef, useState } from "react";
+import SearchComponent from '@/components/SearchComponent';
+import type { ActionType, ProColumns } from '@jetlinks/pro-table';
+import ProTable from '@jetlinks/pro-table';
+import { useRef, useState } from 'react';
 import { InstanceModel, service } from '@/pages/device/Instance';
-import { useIntl } from "umi";
-import moment from "moment";
-
+import { useIntl } from 'umi';
+import moment from 'moment';
 
 interface Props {
-    visible: boolean;
-    data: Partial<DeviceInstance>;
-    onCancel: () => void;
+  visible: boolean;
+  data: Partial<DeviceInstance>;
+  onCancel: () => void;
 }
+
 const BindChildDevice = (props: Props) => {
-    const { visible } = props;
-    const intl = useIntl();
-    const statusMap = new Map();
+  const { visible } = props;
+  const intl = useIntl();
+  const statusMap = new Map();
 
-    statusMap.set('在线', 'success');
-    statusMap.set('离线', 'error');
-    statusMap.set('未激活', 'processing');
-    statusMap.set('online', 'success');
-    statusMap.set('offline', 'error');
-    statusMap.set('notActive', 'processing');
+  statusMap.set('在线', 'success');
+  statusMap.set('离线', 'error');
+  statusMap.set('未激活', 'processing');
+  statusMap.set('online', 'success');
+  statusMap.set('offline', 'error');
+  statusMap.set('notActive', 'processing');
 
-    const actionRef = useRef<ActionType>();
-    const [searchParams, setSearchParams] = useState<any>({});
-    const [bindKeys, setBindKeys] = useState<any[]>([]);
+  const actionRef = useRef<ActionType>();
+  const [searchParams, setSearchParams] = useState<any>({});
+  const [bindKeys, setBindKeys] = useState<any[]>([]);
 
-    const columns: ProColumns<DeviceInstance>[] = [
-        {
-            dataIndex: 'index',
-            valueType: 'indexBorder',
-            width: 48,
-        },
-        {
-            title: 'ID',
-            dataIndex: 'id'
+  const columns: ProColumns<DeviceInstance>[] = [
+    {
+      dataIndex: 'index',
+      valueType: 'indexBorder',
+      width: 48,
+    },
+    {
+      title: 'ID',
+      dataIndex: 'id',
+    },
+    {
+      title: '设备名称',
+      dataIndex: 'name',
+    },
+    {
+      title: '所属产品',
+      dataIndex: 'productName',
+    },
+    {
+      title: '注册时间',
+      dataIndex: 'registryTime',
+      width: '200px',
+      render: (text: any) => (!!text ? moment(text).format('YYYY-MM-DD HH:mm:ss') : '/'),
+      sorter: true,
+    },
+    {
+      title: '状态',
+      dataIndex: 'state',
+      renderText: (record) =>
+        record ? <Badge status={statusMap.get(record.value)} text={record.text} /> : '',
+      valueType: 'select',
+      valueEnum: {
+        notActive: {
+          text: intl.formatMessage({
+            id: 'pages.device.instance.status.notActive',
+            defaultMessage: '未启用',
+          }),
+          value: 'notActive',
         },
-        {
-            title: '设备名称',
-            dataIndex: 'name'
+        offline: {
+          text: intl.formatMessage({
+            id: 'pages.device.instance.status.offLine',
+            defaultMessage: '离线',
+          }),
+          value: 'offline',
         },
-        {
-            title: '所属产品',
-            dataIndex: 'productName'
+        online: {
+          text: intl.formatMessage({
+            id: 'pages.device.instance.status.onLine',
+            defaultMessage: '在线',
+          }),
+          value: 'online',
         },
-        {
-            title: '注册时间',
-            dataIndex: 'registryTime',
-            width: '200px',
-            render: (text: any) => (!!text ? moment(text).format('YYYY-MM-DD HH:mm:ss') : '/'),
-            sorter: true,
-        },
-        {
-            title: '状态',
-            dataIndex: 'state',
-            renderText: (record) =>
-                record ? <Badge status={statusMap.get(record.value)} text={record.text} /> : '',
-            valueType: 'select',
-            valueEnum: {
-                'notActive': {
-                    text: intl.formatMessage({
-                        id: 'pages.device.instance.status.notActive',
-                        defaultMessage: '未启用',
-                    }),
-                    value: 'notActive',
-                },
-                'offline': {
-                    text: intl.formatMessage({
-                        id: 'pages.device.instance.status.offLine',
-                        defaultMessage: '离线',
-                    }),
-                    value: 'offline',
-                },
-                'online': {
-                    text: intl.formatMessage({
-                        id: 'pages.device.instance.status.onLine',
-                        defaultMessage: '在线',
-                    }),
-                    value: 'online',
-                },
-            }
-        }
-    ];
+      },
+    },
+  ];
 
-    const submitBtn = async () => {
-        const resp = await service.bindDevice(InstanceModel.detail.id!, bindKeys)
-        if (resp.status === 200) {
-            props.onCancel();
-            setBindKeys([])
-            actionRef.current?.reset?.();
-        }
+  const submitBtn = async () => {
+    const resp = await service.bindDevice(InstanceModel.detail.id!, bindKeys);
+    if (resp.status === 200) {
+      props.onCancel();
+      setBindKeys([]);
+      actionRef.current?.reset?.();
     }
+  };
 
-    return (
-        <Modal
-            title="绑定子设备"
-            visible={visible}
-            width={1000}
-            onOk={() => { submitBtn() }}
-            onCancel={() => {
-                props.onCancel();
-                setBindKeys([])
-            }}
-            footer={[
-                <Button key="back" onClick={() => {
-                    props.onCancel()
-                    setBindKeys([])
-                    actionRef.current?.reset?.();
-                }}>
-                    取消
-                </Button>,
-                <Button disabled={!(bindKeys.length > 0)} key="submit" type="primary" onClick={() => { submitBtn() }}>
-                    确认
-                </Button>
-            ]}
+  return (
+    <Modal
+      title="绑定子设备"
+      visible={visible}
+      width={1000}
+      onOk={() => {
+        submitBtn();
+      }}
+      onCancel={() => {
+        props.onCancel();
+        setBindKeys([]);
+      }}
+      footer={[
+        <Button
+          key="back"
+          onClick={() => {
+            props.onCancel();
+            setBindKeys([]);
+            actionRef.current?.reset?.();
+          }}
+        >
+          取消
+        </Button>,
+        <Button
+          disabled={!(bindKeys.length > 0)}
+          key="submit"
+          type="primary"
+          onClick={() => {
+            submitBtn();
+          }}
         >
-            <SearchComponent<DeviceInstance>
-                field={[...columns]}
-                target="child-device-bind"
-                pattern={'simple'}
-                defaultParam={[{ column: 'parentId$isnull', value: '1' }]}
-                onSearch={(param) => {
-                    actionRef.current?.reset?.();
-                    setSearchParams(param);
-                }}
-                onReset={() => {// 重置分页及搜索参数
-                    actionRef.current?.reset?.();
-                    setSearchParams({});
-                }}
-            />
-            <ProTable<DeviceInstance>
-                search={false}
-                columns={columns}
-                size="small"
-                rowSelection={{
-                    selectedRowKeys: bindKeys,
-                    onChange: (selectedRowKeys, selectedRows) => {
-                        setBindKeys(selectedRows.map((item) => item.id))
-                    },
-                }}
-                actionRef={actionRef}
-                params={searchParams}
-                rowKey="id"
-                toolBarRender={false}
-                pagination={{
-                    pageSize: 10,
-                }}
-                request={(params) => service.query({ ...params })}
-            />
-        </Modal>
-    );
+          确认
+        </Button>,
+      ]}
+    >
+      <SearchComponent<DeviceInstance>
+        field={[...columns]}
+        target="child-device-bind"
+        pattern={'simple'}
+        defaultParam={[{ column: 'parentId$isnull', value: '1' }]}
+        onSearch={(param) => {
+          actionRef.current?.reset?.();
+          setSearchParams(param);
+        }}
+        onReset={() => {
+          // 重置分页及搜索参数
+          actionRef.current?.reset?.();
+          setSearchParams({});
+        }}
+      />
+      <ProTable<DeviceInstance>
+        search={false}
+        columns={columns}
+        size="small"
+        rowSelection={{
+          selectedRowKeys: bindKeys,
+          onChange: (selectedRowKeys, selectedRows) => {
+            setBindKeys(selectedRows.map((item) => item.id));
+          },
+        }}
+        actionRef={actionRef}
+        params={searchParams}
+        rowKey="id"
+        toolBarRender={false}
+        pagination={{
+          pageSize: 10,
+        }}
+        request={(params) => service.query({ ...params })}
+      />
+    </Modal>
+  );
 };
-export default BindChildDevice
+export default BindChildDevice;

+ 178 - 172
src/pages/device/Instance/Detail/ChildDevice/index.tsx

@@ -7,187 +7,193 @@ import { useIntl } from '@@/plugin-locale/localeExports';
 import { InstanceModel, service } from '@/pages/device/Instance';
 import { useRef, useState } from 'react';
 import SearchComponent from '@/components/SearchComponent';
-import BindChildDevice from './BindChildDevice'
+import BindChildDevice from './BindChildDevice';
 import moment from 'moment';
 import { Link } from 'umi';
 
 const ChildDevice = () => {
-    const intl = useIntl();
-    const [visible, setVisible] = useState<boolean>(false)
-    const statusMap = new Map();
-    statusMap.set('在线', 'success');
-    statusMap.set('离线', 'error');
-    statusMap.set('未激活', 'processing');
-    statusMap.set('online', 'success');
-    statusMap.set('offline', 'error');
-    statusMap.set('notActive', 'processing');
+  const intl = useIntl();
+  const [visible, setVisible] = useState<boolean>(false);
+  const statusMap = new Map();
+  statusMap.set('在线', 'success');
+  statusMap.set('离线', 'error');
+  statusMap.set('未激活', 'processing');
+  statusMap.set('online', 'success');
+  statusMap.set('offline', 'error');
+  statusMap.set('notActive', 'processing');
 
-    const actionRef = useRef<ActionType>();
-    const [searchParams, setSearchParams] = useState<any>({});
-    const [bindKeys, setBindKeys] = useState<any[]>([]);
+  const actionRef = useRef<ActionType>();
+  const [searchParams, setSearchParams] = useState<any>({});
+  const [bindKeys, setBindKeys] = useState<any[]>([]);
 
-    const unBindSingleDevice = async (id: string) => {
-        const resp = await service.unbindDevice(InstanceModel.detail.id!, id, {})
-        if (resp.status === 200) {
-            actionRef.current?.reset?.();
-            message.success('操作成功!')
-        }
+  const unBindSingleDevice = async (id: string) => {
+    const resp = await service.unbindDevice(InstanceModel.detail.id!, id, {});
+    if (resp.status === 200) {
+      actionRef.current?.reset?.();
+      message.success('操作成功!');
     }
+  };
 
-    const columns: ProColumns<LogItem>[] = [
-        {
-            dataIndex: 'index',
-            valueType: 'indexBorder',
-            width: 48,
+  const columns: ProColumns<LogItem>[] = [
+    {
+      dataIndex: 'index',
+      valueType: 'indexBorder',
+      width: 48,
+    },
+    {
+      title: 'ID',
+      dataIndex: 'id',
+    },
+    {
+      title: '设备名称',
+      dataIndex: 'name',
+    },
+    {
+      title: '所属产品',
+      dataIndex: 'productName',
+    },
+    {
+      title: '注册时间',
+      dataIndex: 'registryTime',
+      width: '200px',
+      render: (text: any) => (!!text ? moment(text).format('YYYY-MM-DD HH:mm:ss') : '/'),
+      sorter: true,
+    },
+    {
+      title: '状态',
+      dataIndex: 'state',
+      renderText: (record) =>
+        record ? <Badge status={statusMap.get(record.value)} text={record.text} /> : '',
+      valueType: 'select',
+      valueEnum: {
+        notActive: {
+          text: intl.formatMessage({
+            id: 'pages.device.instance.status.notActive',
+            defaultMessage: '未启用',
+          }),
+          value: 'notActive',
         },
-        {
-            title: 'ID',
-            dataIndex: 'id'
+        offline: {
+          text: intl.formatMessage({
+            id: 'pages.device.instance.status.offLine',
+            defaultMessage: '离线',
+          }),
+          value: 'offline',
         },
-        {
-            title: '设备名称',
-            dataIndex: 'name'
+        online: {
+          text: intl.formatMessage({
+            id: 'pages.device.instance.status.onLine',
+            defaultMessage: '在线',
+          }),
+          value: 'online',
         },
-        {
-            title: '所属产品',
-            dataIndex: 'productName'
-        },
-        {
-            title: '注册时间',
-            dataIndex: 'registryTime',
-            width: '200px',
-            render: (text: any) => (!!text ? moment(text).format('YYYY-MM-DD HH:mm:ss') : '/'),
-            sorter: true,
-        },
-        {
-            title: '状态',
-            dataIndex: 'state',
-            renderText: (record) =>
-                record ? <Badge status={statusMap.get(record.value)} text={record.text} /> : '',
-            valueType: 'select',
-            valueEnum: {
-                'notActive': {
-                    text: intl.formatMessage({
-                        id: 'pages.device.instance.status.notActive',
-                        defaultMessage: '未启用',
-                    }),
-                    value: 'notActive',
-                },
-                'offline': {
-                    text: intl.formatMessage({
-                        id: 'pages.device.instance.status.offLine',
-                        defaultMessage: '离线',
-                    }),
-                    value: 'offline',
-                },
-                'online': {
-                    text: intl.formatMessage({
-                        id: 'pages.device.instance.status.onLine',
-                        defaultMessage: '在线',
-                    }),
-                    value: 'online',
-                },
-            }
-        },
-        {
-            title: intl.formatMessage({
-                id: 'pages.data.option',
-                defaultMessage: '操作',
-            }),
-            valueType: 'option',
-            align: 'center',
-            width: 200,
-            render: (text, record) => [
-                <Link
-                    to={`/device/instance/detail/${record.id}`}
-                    key="link"
-                >
-                    <Tooltip
-                        title={intl.formatMessage({
-                            id: 'pages.data.option.detail',
-                            defaultMessage: '查看',
-                        })}
-                        key={'detail'}
-                    >
-                        <SearchOutlined />
-                    </Tooltip>
-                </Link>,
-                <a key="unbind">
-                    <Popconfirm
-                        onConfirm={() => {
-                            unBindSingleDevice(record.id)
-                        }}
-                        title={'确认解绑吗?'}
-                    >
-                        <DisconnectOutlined />
-                    </Popconfirm>
-                </a>
-            ],
-        },
-    ];
+      },
+    },
+    {
+      title: intl.formatMessage({
+        id: 'pages.data.option',
+        defaultMessage: '操作',
+      }),
+      valueType: 'option',
+      align: 'center',
+      width: 200,
+      render: (text, record) => [
+        <Link to={`/device/instance/detail/${record.id}`} key="link">
+          <Tooltip
+            title={intl.formatMessage({
+              id: 'pages.data.option.detail',
+              defaultMessage: '查看',
+            })}
+            key={'detail'}
+          >
+            <SearchOutlined />
+          </Tooltip>
+        </Link>,
+        <a key="unbind">
+          <Popconfirm
+            onConfirm={() => {
+              unBindSingleDevice(record.id);
+            }}
+            title={'确认解绑吗?'}
+          >
+            <DisconnectOutlined />
+          </Popconfirm>
+        </a>,
+      ],
+    },
+  ];
 
-    return (
-        <Card>
-            <SearchComponent<LogItem>
-                field={[...columns]}
-                target="child-device"
-                pattern={'simple'}
-                defaultParam={[{ column: 'parentId', value: InstanceModel?.detail?.id || '', termType: 'eq' }]}
-                onSearch={(param) => {
-                    actionRef.current?.reset?.();
-                    setSearchParams(param);
-                }}
-                onReset={() => {// 重置分页及搜索参数
-                    actionRef.current?.reset?.();
-                    setSearchParams({});
-                }}
-            />
-            <ProTable<LogItem>
-                search={false}
-                columns={columns}
-                size="small"
-                actionRef={actionRef}
-                params={searchParams}
-                rowKey="id"
-                rowSelection={{
-                    selectedRowKeys: bindKeys,
-                    onChange: (selectedRowKeys, selectedRows) => {
-                        setBindKeys(selectedRows.map((item) => item.id))
-                    },
-                }}
-                toolBarRender={() => [
-                    <Button
-                        onClick={() => {
-                            setVisible(true)
-                            actionRef.current?.reset?.();
-                        }}
-                        key="bind"
-                        type="primary"
-                    >
-                        绑定
-                    </Button>,
-                    <Popconfirm
-                        key="unbind"
-                        onConfirm={async () => {
-                            const resp = await service.unbindBatchDevice(InstanceModel.detail.id!, bindKeys)
-                            if (resp.status === 200) {
-                                message.success('操作成功!')
-                                setBindKeys([])
-                                actionRef.current?.reset?.();
-                            }
-                        }}
-                        title={'确认解绑吗?'}
-                    >
-                        <Button>批量解绑</Button>
-                    </Popconfirm>
-                ]}
-                pagination={{
-                    pageSize: 10,
-                }}
-                request={(params) => service.query(params)}
-            />
-            <BindChildDevice visible={visible} data={{}} onCancel={() => { setVisible(false) }} />
-        </Card>
-    );
-}
-export default ChildDevice;
+  return (
+    <Card>
+      <SearchComponent<LogItem>
+        field={[...columns]}
+        target="child-device"
+        pattern={'simple'}
+        defaultParam={[
+          { column: 'parentId', value: InstanceModel?.detail?.id || '', termType: 'eq' },
+        ]}
+        onSearch={(param) => {
+          actionRef.current?.reset?.();
+          setSearchParams(param);
+        }}
+        onReset={() => {
+          // 重置分页及搜索参数
+          actionRef.current?.reset?.();
+          setSearchParams({});
+        }}
+      />
+      <ProTable<LogItem>
+        search={false}
+        columns={columns}
+        size="small"
+        actionRef={actionRef}
+        params={searchParams}
+        rowKey="id"
+        rowSelection={{
+          selectedRowKeys: bindKeys,
+          onChange: (selectedRowKeys, selectedRows) => {
+            setBindKeys(selectedRows.map((item) => item.id));
+          },
+        }}
+        toolBarRender={() => [
+          <Button
+            onClick={() => {
+              setVisible(true);
+              actionRef.current?.reset?.();
+            }}
+            key="bind"
+            type="primary"
+          >
+            绑定
+          </Button>,
+          <Popconfirm
+            key="unbind"
+            onConfirm={async () => {
+              const resp = await service.unbindBatchDevice(InstanceModel.detail.id!, bindKeys);
+              if (resp.status === 200) {
+                message.success('操作成功!');
+                setBindKeys([]);
+                actionRef.current?.reset?.();
+              }
+            }}
+            title={'确认解绑吗?'}
+          >
+            <Button>批量解绑</Button>
+          </Popconfirm>,
+        ]}
+        pagination={{
+          pageSize: 10,
+        }}
+        request={(params) => service.query(params)}
+      />
+      <BindChildDevice
+        visible={visible}
+        data={{}}
+        onCancel={() => {
+          setVisible(false);
+        }}
+      />
+    </Card>
+  );
+};
+export default ChildDevice;

+ 5 - 4
src/pages/device/Instance/Detail/Log/index.tsx

@@ -41,7 +41,7 @@ const Log = () => {
       dataIndex: 'type',
       renderText: (text) => text.text,
       valueType: 'select',
-      valueEnum: type
+      valueEnum: type,
     },
     {
       title: '时间',
@@ -56,7 +56,7 @@ const Log = () => {
       dataIndex: 'content',
       valueType: 'option',
       ellipsis: true,
-      render: (text, record) => <span>{String(record.content)}</span>
+      render: (text, record) => <span>{String(record.content)}</span>,
     },
     {
       title: intl.formatMessage({
@@ -97,7 +97,8 @@ const Log = () => {
           actionRef.current?.reset?.();
           setSearchParams(param);
         }}
-        onReset={() => {// 重置分页及搜索参数
+        onReset={() => {
+          // 重置分页及搜索参数
           actionRef.current?.reset?.();
           setSearchParams({});
         }}
@@ -114,7 +115,7 @@ const Log = () => {
           pageSize: 10,
         }}
         request={async (params) => {
-          return service.queryLog(InstanceModel.detail.id!, params)
+          return service.queryLog(InstanceModel.detail.id!, params);
         }}
       />
     </Card>

+ 4 - 7
src/pages/device/Instance/Detail/Running/Event/index.tsx

@@ -9,6 +9,7 @@ import { Form, Modal } from 'antd';
 import { SearchOutlined } from '@ant-design/icons';
 import { useRef, useState } from 'react';
 import MonacoEditor from 'react-monaco-editor';
+
 interface Props {
   data: Partial<EventMetadata>;
 }
@@ -110,13 +111,9 @@ const EventLog = (props: Props) => {
           param.pageIndex = param.current - 1;
           delete param.current;
           delete param.total;
-          return service.getEventCount(
-            params.id,
-            data.id!,
-            {
-              ...param,
-            }
-          );
+          return service.getEventCount(params.id, data.id!, {
+            ...param,
+          });
         }}
         pagination={{
           pageSize: 10,

+ 2 - 2
src/pages/device/Instance/Detail/index.tsx

@@ -11,7 +11,7 @@ import Alarm from '@/pages/device/components/Alarm';
 import Info from '@/pages/device/Instance/Detail/Info';
 import Functions from '@/pages/device/Instance/Detail/Functions';
 import Running from '@/pages/device/Instance/Detail/Running';
-import ChildDevice from '@/pages/device/Instance/Detail/ChildDevice'
+import ChildDevice from '@/pages/device/Instance/Detail/ChildDevice';
 import { useIntl } from '@@/plugin-locale/localeExports';
 import Metadata from '../../components/Metadata';
 import type { DeviceMetadata } from '@/pages/device/Product/typings';
@@ -97,7 +97,7 @@ const InstanceDetail = observer(() => {
     // 产品类型为网关的情况下才显示此模块
     {
       key: 'child-device',
-      tab: "子设备",
+      tab: '子设备',
       component: <ChildDevice />,
     },
     {

+ 3 - 3
src/pages/device/Instance/service.ts

@@ -86,17 +86,17 @@ class Service extends BaseService<DeviceInstance> {
   public bindDevice = (deviceId: string, data: string[]) =>
     request(`/${SystemConst.API_BASE}/device/gateway/${deviceId}/bind`, {
       method: 'POST',
-      data
+      data,
     });
   public unbindDevice = (deviceId: string, childrenId: string, data: Record<string, unknown>) =>
     request(`/${SystemConst.API_BASE}/device/gateway/${deviceId}/unbind/${childrenId}`, {
       method: 'POST',
-      data
+      data,
     });
   public unbindBatchDevice = (deviceId: string, data: string[]) =>
     request(`/${SystemConst.API_BASE}/device/gateway/${deviceId}/unbind`, {
       method: 'POST',
-      data
+      data,
     });
 }
 

+ 2 - 2
src/pages/notice/Config/index.tsx

@@ -12,7 +12,7 @@ import { useMemo, useRef, useState } from 'react';
 import BaseCrud from '@/components/BaseCrud';
 import { useIntl } from '@@/plugin-locale/localeExports';
 import type { ISchema } from '@formily/json-schema';
-import { downObject, useAsyncDataSource } from '@/utils/util';
+import { downloadObject, useAsyncDataSource } from '@/utils/util';
 import { CurdModel } from '@/components/BaseCrud/model';
 import Service from '@/pages/notice/Config/service';
 import { createForm, onFieldValueChange } from '@formily/core';
@@ -222,7 +222,7 @@ const Config = observer(() => {
             <EditOutlined />
           </Tooltip>
         </a>,
-        <a onClick={() => downObject(record, '通知配置')} key="download">
+        <a onClick={() => downloadObject(record, '通知配置')} key="download">
           <Tooltip
             title={intl.formatMessage({
               id: 'pages.data.option.download',