Просмотр исходного кода

refactor(device): device -> log

Lind 4 лет назад
Родитель
Сommit
d35b86c4d8

+ 70 - 1
src/pages/device/Instance/Detail/Log/index.tsx

@@ -1,4 +1,73 @@
+import type { ProColumns } from '@jetlinks/pro-table';
+import ProTable from '@jetlinks/pro-table';
+import type { LogItem } from '@/pages/device/Instance/Detail/Log/typings';
+import moment from 'moment';
+import { Modal, Tooltip } from 'antd';
+import { EyeOutlined } from '@ant-design/icons';
+import { useIntl } from '@@/plugin-locale/localeExports';
+import { InstanceModel, service } from '@/pages/device/Instance';
+
 const Log = () => {
-  return <div>日志管理</div>;
+  const intl = useIntl();
+
+  const columns: ProColumns<LogItem>[] = [
+    {
+      dataIndex: 'index',
+      valueType: 'indexBorder',
+      width: 48,
+    },
+    {
+      title: '类型',
+      dataIndex: 'type',
+      renderText: (type) => type.text,
+      valueEnum: [], //TODO
+    },
+    {
+      title: '时间',
+      dataIndex: 'timestamp',
+      defaultSortOrder: 'descend',
+      renderText: (text: string) => moment(text).format('YYYY-MM-DD HH:mm:ss'),
+    },
+    {
+      title: intl.formatMessage({
+        id: 'pages.data.option',
+        defaultMessage: '操作',
+      }),
+      valueType: 'option',
+      align: 'center',
+      width: 200,
+      render: (text, record) => {
+        let content = '';
+        try {
+          content = JSON.stringify(JSON.parse(record.content), null, 2);
+        } catch (error) {
+          content = record.content;
+        }
+        return [
+          <a
+            key="editable"
+            onClick={() => Modal.info({ title: '详细信息', content: <pre>{content}</pre> })}
+          >
+            <Tooltip title="查看">
+              <EyeOutlined />
+            </Tooltip>
+          </a>,
+        ];
+      },
+    },
+  ];
+
+  return (
+    <ProTable<LogItem>
+      columns={columns}
+      defaultParams={{
+        deviceId: InstanceModel.detail.id,
+      }}
+      pagination={{
+        pageSize: 10,
+      }}
+      request={(params) => service.queryLog(InstanceModel.detail.id!, params)}
+    />
+  );
 };
 export default Log;

+ 12 - 0
src/pages/device/Instance/Detail/Log/typings.d.ts

@@ -0,0 +1,12 @@
+export type LogItem = {
+  id: string;
+  deviceId: string;
+  productId: string;
+  timestamp: number;
+  type: {
+    text: string;
+    value: string;
+  };
+  content: string;
+  createTime: number;
+};

+ 11 - 0
src/pages/device/Instance/service.ts

@@ -72,6 +72,17 @@ class Service extends BaseService<DeviceInstance> {
       method: 'POST',
       data,
     });
+
+  public queryLog = (deviceId: string, params: Record<string, unknown>) =>
+    request(`/${SystemConst.API_BASE}/device-instance/${deviceId}/logs`, {
+      method: 'GET',
+      params,
+    });
+
+  public getLogType = () =>
+    request(`/${SystemConst.API_BASE}/dictionary/device-log-type/items`, {
+      method: 'GET',
+    });
 }
 
 export default Service;