Browse Source

fix(cloud): update cloud

Lind 4 years atrás
parent
commit
5c5da44d40

+ 128 - 1
src/pages/cloud/Aliyun/index.tsx

@@ -1,6 +1,133 @@
 import { PageContainer } from '@ant-design/pro-layout';
 import { PageContainer } from '@ant-design/pro-layout';
+import BaseService from '@/utils/BaseService';
+import { useRef } from 'react';
+import type { ActionType, ProColumns } from '@jetlinks/pro-table';
+import { useIntl } from '@@/plugin-locale/localeExports';
+import BaseCrud from '@/components/BaseCrud';
+import { message, Popconfirm, Tooltip } from 'antd';
+import {
+  CloseCircleOutlined,
+  EditOutlined,
+  EyeOutlined,
+  PlayCircleOutlined,
+} from '@ant-design/icons';
+import { CurdModel } from '@/components/BaseCrud/model';
+import type { AliyunItem } from '@/pages/cloud/Aliyun/typings';
+
+export const service = new BaseService<AliyunItem>('device/aliyun/bridge');
+
+const stateIconMap = {
+  enabled: <CloseCircleOutlined />,
+  disabled: <PlayCircleOutlined />,
+};
 
 
 const Aliyun = () => {
 const Aliyun = () => {
-  return <PageContainer>Aliyun</PageContainer>;
+  const intl = useIntl();
+  const actionRef = useRef<ActionType>();
+  const columns: ProColumns<AliyunItem>[] = [
+    {
+      dataIndex: 'index',
+      valueType: 'indexBorder',
+      width: 48,
+    },
+    {
+      title: '名称',
+      align: 'center',
+      dataIndex: 'name',
+    },
+    {
+      title: '说明',
+      align: 'center',
+      dataIndex: 'description',
+    },
+    {
+      title: intl.formatMessage({
+        id: 'pages.searchTable.titleStatus',
+        defaultMessage: '状态',
+      }),
+      dataIndex: 'state',
+      render: (value: any) => value.text,
+    },
+    {
+      title: intl.formatMessage({
+        id: 'pages.data.option',
+        defaultMessage: '操作',
+      }),
+      valueType: 'option',
+      align: 'center',
+      width: 200,
+      render: (text, record) => [
+        <a>
+          <Tooltip
+            title={intl.formatMessage({
+              id: 'pages.data.option.detail',
+              defaultMessage: '查看',
+            })}
+            key={'detail'}
+          >
+            <EyeOutlined />
+          </Tooltip>
+        </a>,
+        <a key="editable" onClick={() => CurdModel.update(record)}>
+          <Tooltip
+            title={intl.formatMessage({
+              id: 'pages.data.option.edit',
+              defaultMessage: '编辑',
+            })}
+          >
+            <EditOutlined />
+          </Tooltip>
+        </a>,
+        <a key="status">
+          <Popconfirm
+            title={intl.formatMessage({
+              id: `pages.data.option.${
+                record.state.value === 'disabled' ? 'enabled' : 'disabled'
+              }.tips`,
+              defaultMessage: `确认${record.state.value === 'disabled' ? '启' : '禁'}用?`,
+            })}
+            onConfirm={async () => {
+              // const state = record.state.value === 'disabled' ? 'enable' : 'disable';
+              // await service.changeStatus(record.id, state);
+              message.success(
+                intl.formatMessage({
+                  id: 'pages.data.option.success',
+                  defaultMessage: '操作成功!',
+                }),
+              );
+              actionRef.current?.reload();
+            }}
+          >
+            <Tooltip
+              title={intl.formatMessage({
+                id: `pages.data.option.${
+                  record.state.value === 'enabled' ? 'disabled' : 'enabled'
+                }`,
+                defaultMessage: record.state.text,
+              })}
+            >
+              {stateIconMap[record.state.value]}
+            </Tooltip>
+          </Popconfirm>
+        </a>,
+      ],
+    },
+  ];
+  const schema = {};
+
+  return (
+    <PageContainer>
+      <BaseCrud<AliyunItem>
+        columns={columns}
+        service={service}
+        title={intl.formatMessage({
+          id: 'pages.cloud.aliyun',
+          defaultMessage: '阿里云',
+        })}
+        schema={schema}
+        actionRef={actionRef}
+      />
+    </PageContainer>
+  );
 };
 };
 export default Aliyun;
 export default Aliyun;

+ 22 - 4
src/pages/cloud/Aliyun/typings.d.ts

@@ -1,4 +1,22 @@
-type Item = {
-  id: string;
-  name: string;
-};
+import type { BaseItem, State } from '@/utils/typings';
+
+type AliyunItem = {
+  accessConfig: {
+    bridgeDeviceName: string;
+    bridgeDeviceSecret: string;
+    bridgeProductKey: string;
+    http2Endpoint: string;
+    serverId: string;
+  };
+  bridgeConfigs: {
+    accessKeyId: string;
+    accessSecret: string;
+    apiEndpoint: string;
+    authEndpoint: string;
+    productKey: string;
+    regionId: string;
+  };
+  codecProtocol: string;
+  createTime: number;
+  state: State;
+} & BaseItem;

+ 112 - 1
src/pages/cloud/Ctwing/index.tsx

@@ -1,6 +1,117 @@
+import BaseCrud from '@/components/BaseCrud';
+import { CurdModel } from '@/components/BaseCrud/model';
+import BaseService from '@/utils/BaseService';
+import { CloseCircleOutlined, EditOutlined, PlayCircleOutlined } from '@ant-design/icons';
 import { PageContainer } from '@ant-design/pro-layout';
 import { PageContainer } from '@ant-design/pro-layout';
+import type { ActionType, ProColumns } from '@jetlinks/pro-table';
+import { message, Popconfirm, Tooltip } from 'antd';
+import { useRef } from 'react';
+import { useIntl } from '@@/plugin-locale/localeExports';
+import type { CtwingItem } from '@/pages/cloud/Ctwing/typings';
+
+export const service = new BaseService<CtwingItem>('ctwing/product');
+
+const stateIconMap = {
+  enabled: <CloseCircleOutlined />,
+  disabled: <PlayCircleOutlined />,
+};
 
 
 const Ctwing = () => {
 const Ctwing = () => {
-  return <PageContainer>Ctwing</PageContainer>;
+  const intl = useIntl();
+  const actionRef = useRef<ActionType>();
+  const columns: ProColumns<CtwingItem>[] = [
+    {
+      dataIndex: 'index',
+      valueType: 'indexBorder',
+      width: 48,
+    },
+    {
+      title: '名称',
+      align: 'center',
+      dataIndex: 'name',
+    },
+    {
+      title: intl.formatMessage({
+        id: 'pages.searchTable.titleStatus',
+        defaultMessage: '状态',
+      }),
+      dataIndex: 'state',
+      render: (value: any) => value.text,
+    },
+    {
+      title: '说明',
+      align: 'center',
+      dataIndex: 'description',
+    },
+    {
+      title: intl.formatMessage({
+        id: 'pages.data.option',
+        defaultMessage: '操作',
+      }),
+      valueType: 'option',
+      align: 'center',
+      width: 200,
+      render: (text, record) => [
+        <a key="editable" onClick={() => CurdModel.update(record)}>
+          <Tooltip
+            title={intl.formatMessage({
+              id: 'pages.data.option.edit',
+              defaultMessage: '编辑',
+            })}
+          >
+            <EditOutlined />
+          </Tooltip>
+        </a>,
+        <a key="status">
+          <Popconfirm
+            title={intl.formatMessage({
+              id: `pages.data.option.${
+                record.state.value === 'disabled' ? 'enabled' : 'disabled'
+              }.tips`,
+              defaultMessage: `确认${record.state.value === 'disabled' ? '启' : '禁'}用?`,
+            })}
+            onConfirm={async () => {
+              // const state = record.state.value === 'disabled' ? 'enable' : 'disable';
+              // await service.changeStatus(record.id, state);
+              message.success(
+                intl.formatMessage({
+                  id: 'pages.data.option.success',
+                  defaultMessage: '操作成功!',
+                }),
+              );
+              actionRef.current?.reload();
+            }}
+          >
+            <Tooltip
+              title={intl.formatMessage({
+                id: `pages.data.option.${
+                  record.state.value === 'enabled' ? 'disabled' : 'enabled'
+                }`,
+                defaultMessage: record.state.text,
+              })}
+            >
+              {stateIconMap[record.state.value]}
+            </Tooltip>
+          </Popconfirm>
+        </a>,
+      ],
+    },
+  ];
+  const schema = {};
+
+  return (
+    <PageContainer>
+      <BaseCrud<CtwingItem>
+        columns={columns}
+        service={service}
+        title={intl.formatMessage({
+          id: 'pages.cloud.ctwing',
+          defaultMessage: 'ctwing',
+        })}
+        schema={schema}
+        actionRef={actionRef}
+      />
+    </PageContainer>
+  );
 };
 };
 export default Ctwing;
 export default Ctwing;

+ 9 - 4
src/pages/cloud/Ctwing/typings.d.ts

@@ -1,4 +1,9 @@
-type Item = {
-  id: string;
-  name: string;
-};
+import type { BaseItem, State } from '@/utils/typings';
+
+type CtwingItem = {
+  apiAddress: string;
+  appKey: string;
+  appSecret: string;
+  masterKey: string;
+  state: State;
+} & BaseItem;

+ 82 - 1
src/pages/cloud/DuerOS/index.tsx

@@ -1,6 +1,87 @@
+import BaseService from '@/utils/BaseService';
+import type { ProColumns, ActionType } from '@jetlinks/pro-table';
+import { useIntl } from '@@/plugin-locale/localeExports';
 import { PageContainer } from '@ant-design/pro-layout';
 import { PageContainer } from '@ant-design/pro-layout';
+import BaseCrud from '@/components/BaseCrud';
+import { useRef } from 'react';
+import { Tooltip } from 'antd';
+import { EditOutlined, MinusOutlined } from '@ant-design/icons';
+import type { DuerOSItem } from '@/pages/cloud/DuerOS/typings';
 
 
+export const service = new BaseService<DuerOSItem>('dueros/product');
 const DuerOS = () => {
 const DuerOS = () => {
-  return <PageContainer>Aliyun</PageContainer>;
+  const intl = useIntl();
+  const actionRef = useRef<ActionType>();
+  const columns: ProColumns<DuerOSItem>[] = [
+    {
+      dataIndex: 'index',
+      valueType: 'indexBorder',
+      width: 48,
+    },
+    {
+      title: '名称',
+      dataIndex: 'name',
+    },
+    {
+      title: '设备类型',
+      dataIndex: 'applianceType',
+    },
+    {
+      title: '厂商名称',
+      dataIndex: 'manufacturerName',
+    },
+    {
+      title: '动作数量',
+      dataIndex: 'version',
+    },
+    {
+      title: '操作',
+      valueType: 'option',
+      align: 'center',
+      width: 200,
+      render: (text, record) => [
+        <a
+          onClick={() => {
+            console.log(record);
+          }}
+        >
+          <Tooltip
+            title={intl.formatMessage({
+              id: 'pages.data.option.edit',
+              defaultMessage: '编辑',
+            })}
+          >
+            <EditOutlined />
+          </Tooltip>
+        </a>,
+        <a>
+          <Tooltip
+            title={intl.formatMessage({
+              id: 'pages.data.option.remove',
+              defaultMessage: '删除',
+            })}
+          >
+            <MinusOutlined />
+          </Tooltip>
+        </a>,
+      ],
+    },
+  ];
+  const schema = {};
+
+  return (
+    <PageContainer>
+      <BaseCrud<DuerOSItem>
+        columns={columns}
+        service={service}
+        title={intl.formatMessage({
+          id: 'pages.cloud.duerOS',
+          defaultMessage: 'DuerOS',
+        })}
+        schema={schema}
+        actionRef={actionRef}
+      />
+    </PageContainer>
+  );
 };
 };
 export default DuerOS;
 export default DuerOS;

+ 15 - 4
src/pages/cloud/DuerOS/typings.d.ts

@@ -1,4 +1,15 @@
-type Item = {
-  id: string;
-  name: string;
-};
+import type { BaseItem } from '@/utils/typings';
+
+type Action = {
+  arg: unknown[];
+} & BaseItem;
+
+type Mode = BaseItem;
+
+type Property = BaseItem;
+
+type DuerOSItem = {
+  actions: Action[];
+  modes: Mode[];
+  properties: Property[];
+} & BaseItem;

+ 123 - 1
src/pages/cloud/Onenet/index.tsx

@@ -1,6 +1,128 @@
 import { PageContainer } from '@ant-design/pro-layout';
 import { PageContainer } from '@ant-design/pro-layout';
+import BaseService from '@/utils/BaseService';
+import { useIntl } from '@@/plugin-locale/localeExports';
+import { useRef } from 'react';
+import type { ActionType, ProColumns } from '@jetlinks/pro-table';
+import { message, Popconfirm, Tooltip } from 'antd';
+import {
+  CloseCircleOutlined,
+  EditOutlined,
+  MinusOutlined,
+  PlayCircleOutlined,
+} from '@ant-design/icons';
+import BaseCrud from '@/components/BaseCrud';
+import { CurdModel } from '@/components/BaseCrud/model';
+import type { OnenetItem } from '@/pages/cloud/Onenet/typings';
+
+export const service = new BaseService<OnenetItem>('one-net/product');
+
+const stateIconMap = {
+  enabled: <CloseCircleOutlined />,
+  disabled: <PlayCircleOutlined />,
+};
 
 
 const Onenet = () => {
 const Onenet = () => {
-  return <PageContainer>Onenet</PageContainer>;
+  const intl = useIntl();
+  const actionRef = useRef<ActionType>();
+  const columns: ProColumns<OnenetItem>[] = [
+    {
+      dataIndex: 'index',
+      valueType: 'indexBorder',
+      width: 48,
+    },
+    {
+      title: '名称',
+      align: 'center',
+      dataIndex: 'name',
+    },
+    {
+      title: '状态',
+      align: 'center',
+      dataIndex: 'state.text',
+    },
+    {
+      title: '说明',
+      align: 'center',
+      dataIndex: 'description',
+    },
+    {
+      title: intl.formatMessage({
+        id: 'pages.data.option',
+        defaultMessage: '',
+      }),
+      valueType: 'option',
+      align: 'center',
+      width: 200,
+      render: (text, record) => [
+        <a key="editable" onClick={() => CurdModel.update(record)}>
+          <Tooltip
+            title={intl.formatMessage({
+              id: 'pages.data.option.edit',
+              defaultMessage: '编辑',
+            })}
+          >
+            <EditOutlined />
+          </Tooltip>
+        </a>,
+        <a key="status">
+          <Popconfirm
+            title={intl.formatMessage({
+              id: `pages.data.option.${
+                record.state.value === 'disabled' ? 'enabled' : 'disabled'
+              }.tips`,
+              defaultMessage: `确认${record.state.value === 'disabled' ? '启' : '禁'}用?`,
+            })}
+            onConfirm={async () => {
+              // const state = record.state.value === 'disabled' ? 'enable' : 'disable';
+              // await service.changeStatus(record.id, state);
+              message.success(
+                intl.formatMessage({
+                  id: 'pages.data.option.success',
+                  defaultMessage: '操作成功!',
+                }),
+              );
+              actionRef.current?.reload();
+            }}
+          >
+            <Tooltip
+              title={intl.formatMessage({
+                id: `pages.data.option.${
+                  record.state.value === 'enabled' ? 'disabled' : 'enabled'
+                }`,
+                defaultMessage: record.state.text,
+              })}
+            >
+              {stateIconMap[record.state.value]}
+            </Tooltip>
+          </Popconfirm>
+        </a>,
+        <a>
+          <Tooltip
+            title={intl.formatMessage({
+              id: 'pages.data.option.remove',
+              defaultMessage: '删除',
+            })}
+          >
+            <MinusOutlined />
+          </Tooltip>
+        </a>,
+      ],
+    },
+  ];
+  const schema = {};
+  return (
+    <PageContainer>
+      <BaseCrud<OnenetItem>
+        columns={columns}
+        service={service}
+        title={intl.formatMessage({
+          id: 'pages.cloud.onenet',
+          defaultMessage: 'Onenet',
+        })}
+        schema={schema}
+        actionRef={actionRef}
+      />
+    </PageContainer>
+  );
 };
 };
 export default Onenet;
 export default Onenet;

+ 10 - 4
src/pages/cloud/Onenet/typings.d.ts

@@ -1,4 +1,10 @@
-type Item = {
-  id: string;
-  name: string;
-};
+import type { BaseItem, State } from '@/utils/typings';
+
+type OnenetItem = {
+  aesKey: string;
+  apiAddress: string;
+  apiKey: string;
+  description: string;
+  state: State;
+  validateToken: string;
+} & BaseItem;