wzyyy 3 лет назад
Родитель
Сommit
657d34f13d

+ 40 - 26
src/components/FSelectDevices/index.tsx

@@ -6,14 +6,15 @@ import { connect } from '@formily/react';
 import type { ActionType, ProColumns } from '@jetlinks/pro-table';
 import ProTable from '@jetlinks/pro-table';
 import type { DeviceInstance } from '@/pages/device/Instance/typings';
-import moment from 'moment';
 import { useIntl } from '@@/plugin-locale/localeExports';
 import Service from '@/pages/device/Instance/service';
 import SearchComponent from '../SearchComponent';
+import _ from 'lodash';
 
 interface Props {
   value: Partial<DeviceInstance>[];
   onChange: (data: Partial<DeviceInstance>[]) => void;
+  productId?: string;
 }
 
 export const service = new Service('device/instance');
@@ -24,14 +25,10 @@ const FSelectDevices = connect((props: Props) => {
   const actionRef = useRef<ActionType>();
   const [searchParam, setSearchParam] = useState({});
   const columns: ProColumns<DeviceInstance>[] = [
-    // {
-    //   dataIndex: 'index',
-    //   valueType: 'indexBorder',
-    //   width: 48,
-    // },
     {
       title: 'ID',
       dataIndex: 'id',
+      ellipsis: true,
     },
     {
       title: intl.formatMessage({
@@ -42,38 +39,32 @@ const FSelectDevices = connect((props: Props) => {
       ellipsis: true,
     },
     {
-      title: intl.formatMessage({
-        id: 'pages.table.productName',
-        defaultMessage: '产品名称',
-      }),
-      dataIndex: 'productName',
+      title: '固件版本',
+      dataIndex: 'firmwareInfo',
       ellipsis: true,
+      render: (text: any, record: any) => record?.version || '',
     },
     {
       title: intl.formatMessage({
         id: 'pages.device.instance.registrationTime',
         defaultMessage: '注册时间',
       }),
-      dataIndex: 'registryTime',
+      dataIndex: 'registerTime',
       width: '200px',
-      render: (text: any) => (text ? moment(text).format('YYYY-MM-DD HH:mm:ss') : ''),
-      sorter: true,
+      valueType: 'dateTime',
     },
-    // {
-    //   title: intl.formatMessage({
-    //     id: 'pages.table.description',
-    //     defaultMessage: '说明',
-    //   }),
-    //   dataIndex: 'description',
-    //   width: '15%',
-    //   ellipsis: true,
-    // },
   ];
 
-  const [data, setData] = useState<Partial<DeviceInstance>[]>(props.value);
+  const [data, setData] = useState<Partial<DeviceInstance>[]>(props?.value || []);
   const rowSelection = {
     onChange: (selectedRowKeys: Key[], selectedRows: DeviceInstance[]) => {
-      setData(selectedRows);
+      const list = [...data];
+      selectedRows.map((item) => {
+        if (!_.map(data, 'id').includes(item.id)) {
+          list.push(item);
+        }
+      });
+      setData(list);
     },
     selectedRowKeys: data?.map((item) => item.id) as Key[],
   };
@@ -103,6 +94,7 @@ const FSelectDevices = connect((props: Props) => {
             model="simple"
             onSearch={async (data1) => {
               setSearchParam(data1);
+              actionRef.current?.reset?.();
             }}
             target="choose-device"
           />
@@ -122,7 +114,29 @@ const FSelectDevices = connect((props: Props) => {
             params={searchParam}
             columns={columns}
             actionRef={actionRef}
-            request={(params) => service.query(params)}
+            request={async (params) => {
+              return service.queryDetailList({
+                context: {
+                  includeTags: false,
+                  includeBind: false,
+                  includeRelations: false,
+                },
+                ...params,
+                terms: [
+                  ...(params?.terms || []),
+                  {
+                    terms: [
+                      {
+                        column: 'productId',
+                        value: props?.productId,
+                      },
+                    ],
+                    type: 'and',
+                  },
+                ],
+                sorts: [{ name: 'createTime', order: 'desc' }],
+              });
+            }}
           />
         </Modal>
       )}

+ 7 - 3
src/pages/device/Firmware/Task/Detail/index.tsx

@@ -185,12 +185,16 @@ const Detail = observer(() => {
     {
       title: '所属产品',
       ellipsis: true,
-      dataIndex: 'productName',
+      dataIndex: 'productId',
       valueType: 'select',
+      render: (text: any, record: any) => record?.productName,
       request: async () => {
-        const res: any = await service.queryProduct();
+        const res: any = await service.queryProduct({
+          paging: false,
+          sorts: [{ name: 'name', order: 'desc' }],
+        });
         if (res.status === 200) {
-          return res.result.map((pItem: any) => ({ label: pItem.name, value: pItem.name }));
+          return res.result.map((pItem: any) => ({ label: pItem.name, value: pItem.id }));
         }
         return [];
       },

+ 4 - 1
src/pages/device/Firmware/Task/Save/index.tsx

@@ -25,7 +25,7 @@ const Save = (props: Props) => {
     () =>
       createForm({
         validateFirst: true,
-        initialValues: data,
+        initialValues: {},
         effects() {
           onFormInit(async (form1) => {
             if (!data?.id) return;
@@ -241,6 +241,9 @@ const Save = (props: Props) => {
             title: '选择设备',
             'x-decorator': 'FormItem',
             'x-component': 'FSelectDevices',
+            'x-component-props': {
+              productId: ids?.productId || '',
+            },
             'x-visible': false,
             required: true,
             'x-reactions': {

+ 13 - 8
src/pages/device/Firmware/Task/index.tsx

@@ -108,6 +108,7 @@ const Task = observer(() => {
       ellipsis: true,
       // hideInSearch: true,
       dataIndex: 'progress',
+      valueType: 'digit',
     },
     {
       title: intl.formatMessage({
@@ -147,14 +148,18 @@ const Task = observer(() => {
                   })
             }
             onConfirm={async () => {
-              await service.deleteTask(record.id);
-              onlyMessage(
-                intl.formatMessage({
-                  id: 'pages.data.option.success',
-                  defaultMessage: '操作成功!',
-                }),
-              );
-              actionRef.current?.reload();
+              const resp = await service.deleteTask(record.id);
+              if (resp.status === 200) {
+                onlyMessage(
+                  intl.formatMessage({
+                    id: 'pages.data.option.success',
+                    defaultMessage: '操作成功!',
+                  }),
+                );
+                actionRef.current?.reload();
+              } else {
+                message.error(resp?.message || '删除失败!');
+              }
             }}
           >
             <Tooltip

+ 23 - 11
src/pages/device/Firmware/index.tsx

@@ -1,7 +1,7 @@
 import { PageContainer } from '@ant-design/pro-layout';
 import type { ActionType, ProColumns } from '@jetlinks/pro-table';
 import ProTable from '@jetlinks/pro-table';
-import { Popconfirm } from 'antd';
+import { message, Popconfirm } from 'antd';
 import { useRef, useState } from 'react';
 import { useIntl } from '@@/plugin-locale/localeExports';
 import { DeleteOutlined, EditOutlined, NodeExpandOutlined, PlusOutlined } from '@ant-design/icons';
@@ -16,6 +16,7 @@ import useDomFullHeight from '@/hooks/document/useDomFullHeight';
 import usePermissions from '@/hooks/permission';
 import SearchComponent from '@/components/SearchComponent';
 import { getMenuPathByParams, MENUS_CODE } from '@/utils/menu';
+import { onlyMessage } from '@/utils/util';
 
 export const service = new Service('firmware');
 
@@ -56,24 +57,25 @@ const Firmware = observer(() => {
         defaultMessage: '所属产品',
       }),
       ellipsis: true,
-      dataIndex: 'productName',
+      dataIndex: 'productId',
       valueType: 'select',
+      render: (text: any, record: any) => record?.productName,
       request: () =>
         service
           .queryProduct({
             paging: false,
-            terms: [
-              {
-                column: 'state',
-                value: 1,
-              },
-            ],
+            // terms: [
+            //   {
+            //     column: 'state',
+            //     value: 1,
+            //   },
+            // ],
             sorts: [{ name: 'name', order: 'desc' }],
           })
           .then((resp: any) =>
             (resp?.result || []).map((item: any) => ({
               label: item.name,
-              value: item.name,
+              value: item.id,
             })),
           ),
     },
@@ -167,8 +169,18 @@ const Firmware = observer(() => {
         >
           <Popconfirm
             onConfirm={async () => {
-              await service.remove(record.id);
-              actionRef.current?.reload();
+              const resp: any = await service.remove(record.id);
+              if (resp.status === 200) {
+                onlyMessage(
+                  intl.formatMessage({
+                    id: 'pages.data.option.success',
+                    defaultMessage: '操作成功!',
+                  }),
+                );
+                actionRef.current?.reload();
+              } else {
+                message.error(resp?.message || '删除失败!');
+              }
             }}
             title="确认删除?"
           >

+ 1 - 1
src/pages/device/Firmware/service.ts

@@ -56,7 +56,7 @@ class Service extends BaseService<FirmwareItem> {
     });
 
   queryProduct = (params?: any) =>
-    request(`/${SystemConst.API_BASE}/device/product/detail/_query/no-paging`, {
+    request(`/${SystemConst.API_BASE}/device-product/detail/_query/no-paging`, {
       method: 'POST',
       data: params,
     });

+ 332 - 291
src/pages/device/Instance/Detail/Diagnose/Status/index.tsx

@@ -25,6 +25,7 @@ import ManualInspection from './ManualInspection';
 import useHistory from '@/hooks/route/useHistory';
 import DiagnosticAdvice from './DiagnosticAdvice';
 import BindParentDevice from '@/components/BindParentDevice';
+import { useRequest } from 'ahooks';
 interface Props {
   providerType: 'network' | 'child-device' | 'media' | 'cloud' | 'channel' | undefined;
 }
@@ -96,9 +97,46 @@ const Status = observer((props: Props) => {
     return newList;
   };
 
+  const { run: gatewayRun, cancel: gatewayCancel } = useRequest(service.queryGatewayState, {
+    manual: true,
+  });
+  const { run: startNetworkRun, cancel: startNetworkCancel } = useRequest(service.startNetwork, {
+    manual: true,
+  });
+  const { run: getGatewayDetailRun, cancel: getGatewayDetailCancel } = useRequest(
+    service.getGatewayDetail,
+    { manual: true },
+  );
+  const { run: startGatewayRun, cancel: startGatewayCancel } = useRequest(service.startGateway, {
+    manual: true,
+  });
+  const { run: detailRun, cancel: detailCancel } = useRequest(service.detail, { manual: true });
+  const { run: deployDeviceRun, cancel: deployDeviceCancel } = useRequest(service.deployDevice, {
+    manual: true,
+  });
+  const { run: queryProductStateRun, cancel: queryProductStateCancel } = useRequest(
+    service.queryProductState,
+    { manual: true },
+  );
+  const { run: deployProductRun, cancel: deployProductCancel } = useRequest(service.deployProduct, {
+    manual: true,
+  });
+  const { run: queryProductConfigRun, cancel: queryProductConfigCancel } = useRequest(
+    service.queryProductConfig,
+    { manual: true },
+  );
+  const { run: queryDeviceConfigRun, cancel: queryDeviceConfigCancel } = useRequest(
+    service.queryDeviceConfig,
+    { manual: true },
+  );
+  const { run: queryProcotolDetailRun, cancel: queryProcotolDetailCancel } = useRequest(
+    service.queryProcotolDetail,
+    { manual: true },
+  );
+
   // 网络信息
   const diagnoseNetwork = () =>
-    new Promise((resolve) => {
+    new Promise(async (resolve) => {
       if (!DiagnoseStatusModel.flag) {
         resolve({});
       }
@@ -116,106 +154,105 @@ const Status = observer((props: Props) => {
         }, time);
       } else {
         if (device?.accessId) {
-          service.queryGatewayState(device.accessId).then((response: any) => {
-            if (response.status === 200) {
-              DiagnoseStatusModel.gateway = response.result;
-              const address = response.result?.channelInfo?.addresses || [];
-              const _label = address.some((i: any) => i.health === -1);
-              const __label = address.every((i: any) => i.health === 1);
-              const health = _label ? -1 : __label ? 1 : 0;
-              let item: ListProps | undefined = undefined;
-              if (health === 1) {
-                item = {
-                  key: 'network',
-                  name: '网络组件',
-                  desc: '诊断网络组件配置是否正确,配置错误将导致设备连接失败',
-                  status: 'success',
-                  text: '正常',
-                  info: null,
-                };
-              } else {
-                item = {
-                  key: 'network',
-                  name: '网络组件',
-                  desc: '诊断网络组件配置是否正确,配置错误将导致设备连接失败',
-                  status: 'error',
-                  text: '异常',
-                  info:
-                    health === -1 ? (
-                      <div>
-                        <div className={styles.infoItem}>
-                          <Badge
-                            status="default"
-                            text={
-                              networkPermission.action ? (
-                                <span>
-                                  网络组件已禁用,请先
-                                  <Popconfirm
-                                    title="确认启用"
-                                    onConfirm={async () => {
-                                      const res = await service.startNetwork(
-                                        DiagnoseStatusModel.gateway?.channelId,
+          const response = await gatewayRun(device.accessId);
+          if (response.status === 200) {
+            DiagnoseStatusModel.gateway = response.result;
+            const address = response.result?.channelInfo?.addresses || [];
+            const _label = address.some((i: any) => i.health === -1);
+            const __label = address.every((i: any) => i.health === 1);
+            const health = _label ? -1 : __label ? 1 : 0;
+            let item: ListProps | undefined = undefined;
+            if (health === 1) {
+              item = {
+                key: 'network',
+                name: '网络组件',
+                desc: '诊断网络组件配置是否正确,配置错误将导致设备连接失败',
+                status: 'success',
+                text: '正常',
+                info: null,
+              };
+            } else {
+              item = {
+                key: 'network',
+                name: '网络组件',
+                desc: '诊断网络组件配置是否正确,配置错误将导致设备连接失败',
+                status: 'error',
+                text: '异常',
+                info:
+                  health === -1 ? (
+                    <div>
+                      <div className={styles.infoItem}>
+                        <Badge
+                          status="default"
+                          text={
+                            networkPermission.action ? (
+                              <span>
+                                网络组件已禁用,请先
+                                <Popconfirm
+                                  title="确认启用"
+                                  onConfirm={async () => {
+                                    const res = await startNetworkRun(
+                                      DiagnoseStatusModel.gateway?.channelId,
+                                    );
+                                    if (res.status === 200) {
+                                      onlyMessage('操作成功!');
+                                      DiagnoseStatusModel.list = modifyArrayList(
+                                        DiagnoseStatusModel.list,
+                                        {
+                                          key: 'network',
+                                          name: '网络组件',
+                                          desc: '诊断网络组件配置是否正确,配置错误将导致设备连接失败',
+                                          status: 'success',
+                                          text: '正常',
+                                          info: null,
+                                        },
                                       );
-                                      if (res.status === 200) {
-                                        onlyMessage('操作成功!');
-                                        DiagnoseStatusModel.list = modifyArrayList(
-                                          DiagnoseStatusModel.list,
-                                          {
-                                            key: 'network',
-                                            name: '网络组件',
-                                            desc: '诊断网络组件配置是否正确,配置错误将导致设备连接失败',
-                                            status: 'success',
-                                            text: '正常',
-                                            info: null,
-                                          },
-                                        );
-                                      }
-                                    }}
-                                  >
-                                    <a>启用</a>
-                                  </Popconfirm>
-                                </span>
-                              ) : (
-                                '暂无权限,请联系管理员'
-                              )
-                            }
-                          />
-                        </div>
+                                    }
+                                  }}
+                                >
+                                  <a>启用</a>
+                                </Popconfirm>
+                              </span>
+                            ) : (
+                              '暂无权限,请联系管理员'
+                            )
+                          }
+                        />
                       </div>
-                    ) : (
-                      <div>
-                        <div className={styles.infoItem}>
-                          <Badge
-                            status="default"
-                            text="请检查服务器端口是否开放,如未开放,请开放后尝试重新连接"
-                          />
-                        </div>
-                        <div className={styles.infoItem}>
-                          <Badge
-                            status="default"
-                            text="请检查服务器防火策略,如有开启防火墙,请关闭防火墙或调整防火墙策略后重试"
-                          />
-                        </div>
+                    </div>
+                  ) : (
+                    <div>
+                      <div className={styles.infoItem}>
+                        <Badge
+                          status="default"
+                          text="请检查服务器端口是否开放,如未开放,请开放后尝试重新连接"
+                        />
                       </div>
-                    ),
-                };
+                      <div className={styles.infoItem}>
+                        <Badge
+                          status="default"
+                          text="请检查服务器防火策略,如有开启防火墙,请关闭防火墙或调整防火墙策略后重试"
+                        />
+                      </div>
+                    </div>
+                  ),
+              };
+            }
+            setTimeout(() => {
+              if (item) {
+                DiagnoseStatusModel.list = modifyArrayList(DiagnoseStatusModel.list, item);
               }
-              setTimeout(() => {
-                if (item) {
-                  DiagnoseStatusModel.list = modifyArrayList(DiagnoseStatusModel.list, item);
-                }
-                resolve({});
-              }, time);
-            } else {
               resolve({});
-            }
-          });
+            }, time);
+          } else {
+            resolve({});
+          }
         }
       }
     });
   // 设备接入网关
   const diagnoseGateway = () =>
-    new Promise((resolve) => {
+    new Promise(async (resolve) => {
       if (!DiagnoseStatusModel.flag) {
         resolve({});
       }
@@ -239,141 +276,138 @@ const Status = observer((props: Props) => {
         let item: ListProps | undefined = undefined;
         if (Object.keys(DiagnoseStatusModel.gateway).length === 0) {
           if (device.accessId) {
-            service.queryGatewayState(device.accessId).then((response: any) => {
-              if (response.status === 200) {
-                DiagnoseStatusModel.gateway = response.result;
-                if (response.result?.state?.value === 'enabled') {
-                  if (providerType === 'cloud' || device?.accessProvider === 'gb28181-2016') {
-                    item = {
-                      key: 'gateway',
-                      name: '设备接入网关',
-                      desc: desc,
-                      status: 'error',
-                      text: '可能存在异常',
-                      info: (
-                        <div>
-                          <div className={styles.infoItem}>
-                            <Badge
-                              status="default"
-                              text={
-                                <span>
-                                  请
-                                  <a
-                                    onClick={async () => {
-                                      const config = await service.getGatewayDetail(
-                                        response.result?.id || '',
-                                      );
-                                      if (config.status === 200) {
-                                        manualInspection({
-                                          type: providerType,
-                                          key: `gateway`,
-                                          name: `设备接入网关`,
-                                          desc: desc,
-                                          data: { name: `${device?.accessProvider}配置` },
-                                          configuration: { ...config.result },
-                                        });
-                                      }
-                                    }}
-                                  >
-                                    人工检查
-                                  </a>
-                                  网关配置是否已填写正确,若您确定该项无需诊断可
-                                  <Popconfirm
-                                    title="确认忽略?"
-                                    onConfirm={() => {
-                                      DiagnoseStatusModel.list = modifyArrayList(
-                                        DiagnoseStatusModel.list,
-                                        {
-                                          key: 'gateway',
-                                          name: '设备接入网关',
-                                          desc: desc,
-                                          status: 'success',
-                                          text: '正常',
-                                          info: null,
-                                        },
-                                      );
-                                    }}
-                                  >
-                                    <a>忽略</a>
-                                  </Popconfirm>
-                                </span>
-                              }
-                            />
-                          </div>
-                        </div>
-                      ),
-                    };
-                  } else {
-                    item = {
-                      key: 'gateway',
-                      name: '设备接入网关',
-                      desc: desc,
-                      status: 'success',
-                      text: '正常',
-                      info: null,
-                    };
-                  }
-                } else {
+            const response = await gatewayRun(device.accessId);
+            if (response.status === 200) {
+              DiagnoseStatusModel.gateway = response.result;
+              if (response.result?.state?.value === 'enabled') {
+                if (providerType === 'cloud' || device?.accessProvider === 'gb28181-2016') {
                   item = {
                     key: 'gateway',
                     name: '设备接入网关',
                     desc: desc,
                     status: 'error',
-                    text: '异常',
+                    text: '可能存在异常',
                     info: (
                       <div>
                         <div className={styles.infoItem}>
                           <Badge
                             status="default"
                             text={
-                              accessPermission.action ? (
-                                <span>
-                                  设备接入网关已禁用,请先
-                                  <Popconfirm
-                                    title="确认启用"
-                                    onConfirm={async () => {
-                                      const resp = await service.startGateway(
-                                        device.accessId || '',
-                                      );
-                                      if (resp.status === 200) {
-                                        onlyMessage('操作成功!');
-                                        DiagnoseStatusModel.list = modifyArrayList(
-                                          DiagnoseStatusModel.list,
-                                          {
-                                            key: 'gateway',
-                                            name: '设备接入网关',
-                                            desc: desc,
-                                            status: 'success',
-                                            text: '正常',
-                                            info: null,
-                                          },
-                                        );
-                                      }
-                                    }}
-                                  >
-                                    <a>启用</a>
-                                  </Popconfirm>
-                                </span>
-                              ) : (
-                                '暂无权限,请联系管理员处理'
-                              )
+                              <span>
+                                请
+                                <a
+                                  onClick={async () => {
+                                    const config = await getGatewayDetailRun(
+                                      response.result?.id || '',
+                                    );
+                                    if (config.status === 200) {
+                                      manualInspection({
+                                        type: providerType,
+                                        key: `gateway`,
+                                        name: `设备接入网关`,
+                                        desc: desc,
+                                        data: { name: `${device?.accessProvider}配置` },
+                                        configuration: { ...config.result },
+                                      });
+                                    }
+                                  }}
+                                >
+                                  人工检查
+                                </a>
+                                网关配置是否已填写正确,若您确定该项无需诊断可
+                                <Popconfirm
+                                  title="确认忽略?"
+                                  onConfirm={() => {
+                                    DiagnoseStatusModel.list = modifyArrayList(
+                                      DiagnoseStatusModel.list,
+                                      {
+                                        key: 'gateway',
+                                        name: '设备接入网关',
+                                        desc: desc,
+                                        status: 'success',
+                                        text: '正常',
+                                        info: null,
+                                      },
+                                    );
+                                  }}
+                                >
+                                  <a>忽略</a>
+                                </Popconfirm>
+                              </span>
                             }
                           />
                         </div>
                       </div>
                     ),
                   };
+                } else {
+                  item = {
+                    key: 'gateway',
+                    name: '设备接入网关',
+                    desc: desc,
+                    status: 'success',
+                    text: '正常',
+                    info: null,
+                  };
                 }
-                setTimeout(() => {
-                  if (item) {
-                    DiagnoseStatusModel.list = modifyArrayList(DiagnoseStatusModel.list, item);
-                  }
-                  resolve({});
-                }, time);
               } else {
-                resolve({});
+                item = {
+                  key: 'gateway',
+                  name: '设备接入网关',
+                  desc: desc,
+                  status: 'error',
+                  text: '异常',
+                  info: (
+                    <div>
+                      <div className={styles.infoItem}>
+                        <Badge
+                          status="default"
+                          text={
+                            accessPermission.action ? (
+                              <span>
+                                设备接入网关已禁用,请先
+                                <Popconfirm
+                                  title="确认启用"
+                                  onConfirm={async () => {
+                                    const resp = await startGatewayRun(device.accessId || '');
+                                    if (resp.status === 200) {
+                                      onlyMessage('操作成功!');
+                                      DiagnoseStatusModel.list = modifyArrayList(
+                                        DiagnoseStatusModel.list,
+                                        {
+                                          key: 'gateway',
+                                          name: '设备接入网关',
+                                          desc: desc,
+                                          status: 'success',
+                                          text: '正常',
+                                          info: null,
+                                        },
+                                      );
+                                    }
+                                  }}
+                                >
+                                  <a>启用</a>
+                                </Popconfirm>
+                              </span>
+                            ) : (
+                              '暂无权限,请联系管理员处理'
+                            )
+                          }
+                        />
+                      </div>
+                    </div>
+                  ),
+                };
               }
-            });
+              setTimeout(() => {
+                if (item) {
+                  DiagnoseStatusModel.list = modifyArrayList(DiagnoseStatusModel.list, item);
+                }
+                resolve({});
+              }, time);
+            } else {
+              resolve({});
+            }
           }
         } else {
           if (DiagnoseStatusModel.gateway?.state?.value === 'enabled') {
@@ -394,7 +428,7 @@ const Status = observer((props: Props) => {
                             <a
                               onClick={async () => {
-                                const config = await service.getGatewayDetail(
+                                const config = await getGatewayDetailRun(
                                   DiagnoseStatusModel.gateway?.id || '',
                                 );
                                 if (config.status === 200) {
@@ -466,7 +500,7 @@ const Status = observer((props: Props) => {
                             <Popconfirm
                               title="确认启用"
                               onConfirm={async () => {
-                                const resp = await service.startGateway(device.accessId || '');
+                                const resp = await startGatewayRun(device.accessId || '');
                                 if (resp.status === 200) {
                                   onlyMessage('操作成功!');
                                   DiagnoseStatusModel.list = modifyArrayList(
@@ -560,7 +594,7 @@ const Status = observer((props: Props) => {
           }, time);
         } else {
           let item: ListProps | undefined = undefined;
-          const response = await service.detail(device?.parentId);
+          const response = await detailRun(device?.parentId);
           DiagnoseStatusModel.parent = response.result;
           if (response.status === 200) {
             if (response?.result?.state?.value === 'notActive') {
@@ -582,9 +616,7 @@ const Status = observer((props: Props) => {
                               <Popconfirm
                                 title="确认启用"
                                 onConfirm={async () => {
-                                  const resp = await service.deployDevice(
-                                    response?.result?.id || '',
-                                  );
+                                  const resp = await deployDeviceRun(response?.result?.id || '');
                                   if (resp.status === 200) {
                                     onlyMessage('操作成功!');
                                     DiagnoseStatusModel.list = modifyArrayList(
@@ -657,7 +689,7 @@ const Status = observer((props: Props) => {
 
   // 产品状态
   const diagnoseProduct = () =>
-    new Promise((resolve) => {
+    new Promise(async (resolve) => {
       if (!DiagnoseStatusModel.flag) {
         resolve({});
       }
@@ -675,72 +707,69 @@ const Status = observer((props: Props) => {
         }, time);
       } else {
         if (device?.productId) {
-          service.queryProductState(device.productId).then((response: any) => {
-            if (response.status === 200) {
-              DiagnoseStatusModel.product = response.result;
-              let item: ListProps | undefined = undefined;
-              const state = response.result?.state;
-              item = {
-                key: 'product',
-                name: '产品状态',
-                desc: '诊断产品状态是否正常,禁用状态将导致设备连接失败',
-                status: state === 1 ? 'success' : 'error',
-                text: state === 1 ? '正常' : '异常',
-                info:
-                  state === 1 ? null : (
-                    <div>
-                      <div className={styles.infoItem}>
-                        <Badge
-                          status="default"
-                          text={
-                            productPermission.action ? (
-                              <span>
-                                产品已禁用,请
-                                <Popconfirm
-                                  title="确认启用"
-                                  onConfirm={async () => {
-                                    const resp = await service.deployProduct(
-                                      device.productId || '',
+          const response = await queryProductStateRun(device.productId);
+          if (response.status === 200) {
+            DiagnoseStatusModel.product = response.result;
+            let item: ListProps | undefined = undefined;
+            const state = response.result?.state;
+            item = {
+              key: 'product',
+              name: '产品状态',
+              desc: '诊断产品状态是否正常,禁用状态将导致设备连接失败',
+              status: state === 1 ? 'success' : 'error',
+              text: state === 1 ? '正常' : '异常',
+              info:
+                state === 1 ? null : (
+                  <div>
+                    <div className={styles.infoItem}>
+                      <Badge
+                        status="default"
+                        text={
+                          productPermission.action ? (
+                            <span>
+                              产品已禁用,请
+                              <Popconfirm
+                                title="确认启用"
+                                onConfirm={async () => {
+                                  const resp = await deployProductRun(device.productId || '');
+                                  if (resp.status === 200) {
+                                    onlyMessage('操作成功!');
+                                    DiagnoseStatusModel.list = modifyArrayList(
+                                      DiagnoseStatusModel.list,
+                                      {
+                                        key: 'product',
+                                        name: '产品状态',
+                                        desc: '诊断产品状态是否正常,禁用状态将导致设备连接失败',
+                                        status: 'success',
+                                        text: '正常',
+                                        info: null,
+                                      },
                                     );
-                                    if (resp.status === 200) {
-                                      onlyMessage('操作成功!');
-                                      DiagnoseStatusModel.list = modifyArrayList(
-                                        DiagnoseStatusModel.list,
-                                        {
-                                          key: 'product',
-                                          name: '产品状态',
-                                          desc: '诊断产品状态是否正常,禁用状态将导致设备连接失败',
-                                          status: 'success',
-                                          text: '正常',
-                                          info: null,
-                                        },
-                                      );
-                                    }
-                                  }}
-                                >
-                                  <a>启用</a>
-                                </Popconfirm>
-                                产品
-                              </span>
-                            ) : (
-                              '暂无权限,请联系管理员处理'
-                            )
-                          }
-                        />
-                      </div>
+                                  }
+                                }}
+                              >
+                                <a>启用</a>
+                              </Popconfirm>
+                              产品
+                            </span>
+                          ) : (
+                            '暂无权限,请联系管理员处理'
+                          )
+                        }
+                      />
                     </div>
-                  ),
-              };
-              setTimeout(() => {
-                if (item) {
-                  DiagnoseStatusModel.list = modifyArrayList(DiagnoseStatusModel.list, item);
-                }
-                resolve({});
-              }, time);
-            } else {
+                  </div>
+                ),
+            };
+            setTimeout(() => {
+              if (item) {
+                DiagnoseStatusModel.list = modifyArrayList(DiagnoseStatusModel.list, item);
+              }
               resolve({});
-            }
-          });
+            }, time);
+          } else {
+            resolve({});
+          }
         }
       }
     });
@@ -784,7 +813,7 @@ const Status = observer((props: Props) => {
                           <Popconfirm
                             title="确认启用"
                             onConfirm={async () => {
-                              const resp = await service.deployDevice(device?.id || '');
+                              const resp = await deployDeviceRun(device?.id || '');
                               if (resp.status === 200) {
                                 InstanceModel.detail.state = { value: 'offline', text: '离线' };
                                 onlyMessage('操作成功!');
@@ -841,7 +870,7 @@ const Status = observer((props: Props) => {
         resolve({});
       }
       if (device?.productId) {
-        const response = await service.queryProductConfig(device.productId);
+        const response = await queryProductConfigRun(device.productId);
         if (response.status === 200 && response.result.length > 0) {
           DiagnoseStatusModel.configuration.product = response.result;
           const list = [...DiagnoseStatusModel.list];
@@ -1005,7 +1034,7 @@ const Status = observer((props: Props) => {
         resolve({});
       }
       if (device?.id) {
-        const response = await service.queryDeviceConfig(device.id);
+        const response = await queryDeviceConfigRun(device.id);
         if (response.status === 200 && response.result.length > 0) {
           DiagnoseStatusModel.configuration.device = response.result;
           const list = [...DiagnoseStatusModel.list];
@@ -1366,7 +1395,7 @@ const Status = observer((props: Props) => {
         resolve({});
       }
       if (device.accessProvider === 'OneNet') {
-        const response = await service.queryDeviceConfig(device?.id || '');
+        const response = await queryDeviceConfigRun(device?.id || '');
         DiagnoseStatusModel.configuration.device = response.result;
         const configuration = device?.configuration || {};
         let item: ListProps | undefined = undefined;
@@ -1481,7 +1510,7 @@ const Status = observer((props: Props) => {
         resolve({});
       }
       if (device.accessProvider === 'Ctwing') {
-        const response = await service.queryDeviceConfig(device?.id || '');
+        const response = await queryDeviceConfigRun(device?.id || '');
         DiagnoseStatusModel.configuration.device = response.result;
         const configuration = device?.configuration || {};
         let item: ListProps | undefined = undefined;
@@ -1633,7 +1662,7 @@ const Status = observer((props: Props) => {
           device?.accessProvider &&
           gatewayList.includes(device?.accessProvider)
         ) {
-          const response = await service.queryProcotolDetail(device.protocol, 'MQTT');
+          const response = await queryProcotolDetailRun(device.protocol, 'MQTT');
           if (response.status === 200) {
             if ((response.result?.routes || []).length > 0) {
               item.push(
@@ -1843,6 +1872,20 @@ const Status = observer((props: Props) => {
     if (DiagnoseStatusModel.state === 'loading' && providerType) {
       handleSearch();
     }
+
+    return () => {
+      gatewayCancel();
+      startNetworkCancel();
+      getGatewayDetailCancel();
+      startGatewayCancel();
+      detailCancel();
+      deployDeviceCancel();
+      queryProductStateCancel();
+      deployProductCancel();
+      queryProductConfigCancel();
+      queryDeviceConfigCancel();
+      queryProcotolDetailCancel();
+    };
   }, [DiagnoseStatusModel.state, providerType]);
 
   return (
@@ -1858,7 +1901,7 @@ const Status = observer((props: Props) => {
                   Object.keys(DiagnoseStatusModel.gateway).length > 0 &&
                   DiagnoseStatusModel.gateway?.state?.value !== 'enabled'
                 ) {
-                  const resp = await service.startGateway(device.accessId || '');
+                  const resp = await startGatewayRun(device.accessId || '');
                   if (resp.status === 200) {
                     DiagnoseStatusModel.list = modifyArrayList(DiagnoseStatusModel.list, {
                       key: 'gateway',
@@ -1871,7 +1914,7 @@ const Status = observer((props: Props) => {
                   }
                 }
                 if (DiagnoseStatusModel.product?.state !== 1) {
-                  const resp = await service.deployProduct(device.productId || '');
+                  const resp = await deployProductRun(device.productId || '');
                   if (resp.status === 200) {
                     DiagnoseStatusModel.list = modifyArrayList(DiagnoseStatusModel.list, {
                       key: 'product',
@@ -1884,7 +1927,7 @@ const Status = observer((props: Props) => {
                   }
                 }
                 if (device?.state?.value === 'notActive') {
-                  const resp = await service.deployDevice(device?.id || '');
+                  const resp = await deployDeviceRun(device?.id || '');
                   if (resp.status === 200) {
                     InstanceModel.detail.state = { value: 'offline', text: '离线' };
                     DiagnoseStatusModel.list = modifyArrayList(DiagnoseStatusModel.list, {
@@ -1903,7 +1946,7 @@ const Status = observer((props: Props) => {
                   const __label = address.every((i: any) => i.health === 1);
                   const health = _label ? -1 : __label ? 1 : 0;
                   if (health === -1 && DiagnoseStatusModel.gateway?.channelId) {
-                    const res = await service.startNetwork(DiagnoseStatusModel.gateway?.channelId);
+                    const res = await startNetworkRun(DiagnoseStatusModel.gateway?.channelId);
                     if (res.status === 200) {
                       DiagnoseStatusModel.list = modifyArrayList(DiagnoseStatusModel.list, {
                         key: 'network',
@@ -1918,7 +1961,7 @@ const Status = observer((props: Props) => {
                 }
                 if (providerType === 'child-device' && device?.parentId) {
                   if (DiagnoseStatusModel.parent?.state?.value === 'notActive') {
-                    const resp = await service.deployDevice(device?.parentId || '');
+                    const resp = await deployDeviceRun(device?.parentId || '');
                     if (resp.status === 200) {
                       DiagnoseStatusModel.list = modifyArrayList(DiagnoseStatusModel.list, {
                         key: 'parent-device',
@@ -2004,7 +2047,7 @@ const Status = observer((props: Props) => {
           }}
           onOk={async (parentId: string) => {
             let item: ListProps | undefined = undefined;
-            const response = await service.detail(parentId);
+            const response = await detailRun(parentId);
             if (response.status === 200) {
               if (response?.result?.state?.value === 'notActive') {
                 item = {
@@ -2025,9 +2068,7 @@ const Status = observer((props: Props) => {
                                 <Popconfirm
                                   title="确认启用"
                                   onConfirm={async () => {
-                                    const resp = await service.deployDevice(
-                                      response?.result?.id || '',
-                                    );
+                                    const resp = await deployDeviceRun(response?.result?.id || '');
                                     if (resp.status === 200) {
                                       onlyMessage('操作成功!');
                                       DiagnoseStatusModel.list = modifyArrayList(

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

@@ -365,6 +365,11 @@ class Service extends BaseService<DeviceInstance> {
     request(`/${SystemConst.API_BASE}/gateway/device/${id}`, {
       method: 'GET',
     });
+  public queryDetailList = (data: any) =>
+    request(`/${SystemConst.API_BASE}/device-instance/detail/_query`, {
+      method: 'POST',
+      data,
+    });
 }
 
 export default Service;

+ 37 - 27
src/pages/link/Type/Detail/index.tsx

@@ -15,7 +15,7 @@ import {
 } from '@formily/antd';
 import type { ISchema } from '@formily/json-schema';
 import { useEffect, useMemo, useRef } from 'react';
-import type { Field, FieldDataSource } from '@formily/core';
+import { Field, FieldDataSource, onFormInit } from '@formily/core';
 import { createForm, onFieldReact, onFieldValueChange } from '@formily/core';
 import { Card, Col, Row } from 'antd';
 import styles from './index.less';
@@ -28,6 +28,7 @@ import { PermissionButton } from '@/components';
 import usePermissions from '@/hooks/permission';
 import { action } from '@formily/reactive';
 import FMonacoEditor from '@/components/FMonacoEditor';
+import { useParams } from 'umi';
 
 /**
  *  根据类型过滤配置信息
@@ -53,7 +54,7 @@ const filterConfigByType = (data: any[], type: string) => {
   });
 };
 const Save = observer(() => {
-  // const param = useParams<{ id: string }>();
+  const param = useParams<{ id: string }>();
 
   const configRef = useRef([]);
 
@@ -120,6 +121,12 @@ const Save = observer(() => {
         // readPretty: true,
         // initialValues: {},
         effects() {
+          onFormInit(async (form1) => {
+            if (param?.id && param.id !== ':id') {
+              const resp = await service.detail(param.id);
+              form1.setInitialValues({ ...resp?.result });
+            }
+          });
           onFieldValueChange('type', (field, f) => {
             const value = (field as Field).value;
             if (f.modified) {
@@ -171,6 +178,10 @@ const Save = observer(() => {
                 f5.setFieldState('grid.cluster.cluster', (state) => {
                   state.value = [{}];
                 });
+                f5.setFieldState('grid.cluster.cluster.*.layout2.host', (state) => {
+                  state.value = undefined;
+                  state.disabled = false;
+                });
               }
             }
           });
@@ -192,36 +203,27 @@ const Save = observer(() => {
               state.dataSource = _ports?.ports?.map((i: any) => ({ label: i, value: i }));
             });
           });
-          // onFieldValueChange('grid.cluster.cluster.*.layout2.host', async (field, f4) => {
-          //   const host = (field as Field).value;
-          //   const value = (field.query('.serverId').take() as Field).value;
-          //   const type = (field.query('type').take() as Field).value;
-          //   const response = await getResourceById(value, type);
-          //   const _ports = response.find((item) => item.host === host);
-          //   f4.setFieldState(field.query('.port').take(), async (state) => {
-          //     state.dataSource = _ports?.ports?.map((i: any) => ({ label: i, value: i }));
-          //   });
-          // });
         },
       }),
     [],
   );
 
   useEffect(() => {
-    const subscription = Store.subscribe('current-network-data', (data) => {
-      if (!data) return;
-      // form.readPretty = true;
-      const _data = _.cloneDeep(data);
-      // 处理一下集群模式数据
-      if (!_data.shareCluster) {
-        _data.cluster = _data.cluster?.map((item: any) => ({ ...item.configuration }));
-      }
-      form.setValues({ ..._data });
-    });
-    return () => {
-      subscription.unsubscribe();
-      Store.set('current-network-data', undefined);
-    };
+    console.log(Store.get('current-network-data'));
+    // const subscription = Store.subscribe('current-network-data', (data) => {
+    //   if (!data) return;
+    //   // form.readPretty = true;
+    //   const _data = _.cloneDeep(data);
+    //   // 处理一下集群模式数据
+    //   if (!_data.shareCluster) {
+    //     _data.cluster = _data.cluster?.map((item: any) => ({ ...item.configuration }));
+    //   }
+    //   form.setValues({ ..._data });
+    // });
+    // return () => {
+    //   subscription.unsubscribe();
+    //   // Store.set('current-network-data', undefined);
+    // };
   }, []);
 
   const SchemaField = createSchemaField({
@@ -290,6 +292,8 @@ const Save = observer(() => {
         'x-component-props': {
           placeholder: '请选择本地地址',
         },
+        default: '0.0.0.0',
+        'x-disabled': true,
         'x-decorator-props': {
           gridSpan: 1,
           labelAlign: 'left',
@@ -350,7 +354,13 @@ const Save = observer(() => {
         'x-decorator-props': {
           gridSpan: 1,
           labelAlign: 'left',
-          tooltip: '对外提供访问的地址,内网环境是填写服务器的内网IP地址',
+          tooltip: (
+            <span>
+              对外提供访问的地址,
+              <br />
+              内网环境时填写服务器的内网IP地址
+            </span>
+          ),
           layout: 'vertical',
         },
         required: true,

+ 8 - 4
src/pages/link/Type/index.tsx

@@ -1,6 +1,6 @@
 import { useRef, useState } from 'react';
 import type { ActionType, ProColumns } from '@jetlinks/pro-table';
-import { Badge, Popconfirm, Tooltip } from 'antd';
+import { Badge, message, Popconfirm, Tooltip } from 'antd';
 import {
   CloseCircleOutlined,
   DeleteOutlined,
@@ -15,7 +15,6 @@ import SearchComponent from '@/components/SearchComponent';
 import { getMenuPathByParams, MENUS_CODE } from '@/utils/menu';
 import { history } from 'umi';
 import Service from '@/pages/link/service';
-import { Store } from 'jetlinks-store';
 import { PermissionButton, ProTableCard } from '@/components';
 import NetworkCard from '@/components/ProTableCard/CardItems/networkCard';
 import usePermissions from '@/hooks/permission';
@@ -168,7 +167,7 @@ const Network = () => {
           // disabled={getButtonPermission('link/Type', ['view'])}
           key="edit"
           onClick={() => {
-            Store.set('current-network-data', record);
+            // Store.set('current-network-data', record);
             pageJump(record.id);
           }}
         >
@@ -207,6 +206,7 @@ const Network = () => {
         </PermissionButton>,
         <PermissionButton
           type="link"
+          key={'delete'}
           style={{ padding: 0 }}
           isPermission={networkPermission.delete}
           disabled={record.state.value === 'enabled'}
@@ -227,6 +227,8 @@ const Network = () => {
               if (response.status === 200) {
                 onlyMessage('删除成功');
                 actionRef.current?.reload();
+              } else {
+                message.error(response?.message || '删除失败');
               }
             }}
           >
@@ -294,7 +296,7 @@ const Network = () => {
                 isPermission={networkPermission.update}
                 key="edit"
                 onClick={() => {
-                  Store.set('current-network-data', record);
+                  // Store.set('current-network-data', record);
                   pageJump(record.id);
                 }}
               >
@@ -351,6 +353,8 @@ const Network = () => {
                     if (response.status === 200) {
                       onlyMessage('删除成功');
                       actionRef.current?.reload();
+                    } else {
+                      message.error(response?.message || '删除失败');
                     }
                   },
                 }}

+ 3 - 1
src/pages/media/Cascade/Publish/index.tsx

@@ -25,6 +25,7 @@ const Publish = (props: Props) => {
     const source = new EventSourcePolyfill(activeAPI);
     source.onmessage = (e: any) => {
       const res = JSON.parse(e.data);
+      console.log(res);
       if (res.successful) {
         dt += 1;
         setCount(dt);
@@ -35,7 +36,8 @@ const Publish = (props: Props) => {
         setErrMessage(res.message);
       }
     };
-    source.onerror = () => {
+    source.onerror = (e: any) => {
+      console.log(e, 'error');
       source.close();
     };
     source.onopen = () => {};

+ 3 - 3
src/pages/rule-engine/Alarm/Configuration/index.tsx

@@ -105,7 +105,7 @@ const Configuration = () => {
     },
     {
       title: '关联场景联动',
-      dataIndex: 'sceneName',
+      dataIndex: 'sceneId',
       width: 250,
       render: (text: any, record: any) => (
         <PermissionButton
@@ -130,7 +130,7 @@ const Configuration = () => {
               textOverflow: 'ellipsis',
             }}
           >
-            {text}
+            {record?.sceneName}
           </span>
         </PermissionButton>
       ),
@@ -142,7 +142,7 @@ const Configuration = () => {
           }),
         );
         if (res.status === 200) {
-          return res.result.map((item: any) => ({ label: item.name, value: item.name }));
+          return res.result.map((item: any) => ({ label: item.name, value: item.id }));
         }
         return [];
       },