xieyonghong 3 лет назад
Родитель
Сommit
ebbbbb433b

+ 0 - 1
src/components/SearchComponent/index.tsx

@@ -605,7 +605,6 @@ const SearchComponent = <T extends Record<string, any>>(props: Props<T>) => {
     const q = params.get('q');
     const _target = params.get('target');
     if (q && props.model !== 'simple') {
-      console.log(JSON.parse(q));
       if (_target) {
         if (props.target && _target === props.target) {
           form.setValues(JSON.parse(q));

+ 201 - 271
src/pages/device/Instance/Detail/Diagnose/Status/index.tsx

@@ -74,6 +74,10 @@ const Status = observer((props: Props) => {
     setArtificiaData({ ...params });
   };
 
+  const isExit = (arr1: any[], arr2: any[]) => {
+    return arr1.find((item) => arr2.includes(item));
+  };
+
   const modifyArrayList = (oldList: ListProps[], item: ListProps, index?: number) => {
     let newList: ListProps[] = [];
     if (index !== 0 && !index) {
@@ -95,6 +99,9 @@ const Status = observer((props: Props) => {
   // 网络信息
   const diagnoseNetwork = () =>
     new Promise((resolve) => {
+      if (!DiagnoseStatusModel.flag) {
+        resolve({});
+      }
       if (device.state?.value === 'online') {
         setTimeout(() => {
           DiagnoseStatusModel.list = modifyArrayList(DiagnoseStatusModel.list, {
@@ -211,6 +218,9 @@ const Status = observer((props: Props) => {
   // 设备接入网关
   const diagnoseGateway = () =>
     new Promise((resolve) => {
+      if (!DiagnoseStatusModel.flag) {
+        resolve({});
+      }
       const desc =
         providerType && ['child-device', 'cloud'].includes(providerType)
           ? '诊断设备接入网关状态是否正常,网关配置是否正确'
@@ -504,6 +514,9 @@ const Status = observer((props: Props) => {
   // 网关父设备
   const diagnoseParentDevice = () =>
     new Promise(async (resolve) => {
+      if (!DiagnoseStatusModel.flag) {
+        resolve({});
+      }
       if (device.state?.value === 'online') {
         setTimeout(() => {
           DiagnoseStatusModel.list = modifyArrayList(DiagnoseStatusModel.list, {
@@ -653,6 +666,9 @@ const Status = observer((props: Props) => {
   // 产品状态
   const diagnoseProduct = () =>
     new Promise((resolve) => {
+      if (!DiagnoseStatusModel.flag) {
+        resolve({});
+      }
       if (device.state?.value === 'online') {
         setTimeout(() => {
           DiagnoseStatusModel.list = modifyArrayList(DiagnoseStatusModel.list, {
@@ -742,6 +758,9 @@ const Status = observer((props: Props) => {
   // 设备状态
   const diagnoseDevice = () =>
     new Promise((resolve) => {
+      if (!DiagnoseStatusModel.flag) {
+        resolve({});
+      }
       if (device.state?.value === 'online') {
         setTimeout(() => {
           DiagnoseStatusModel.list = modifyArrayList(DiagnoseStatusModel.list, {
@@ -830,6 +849,9 @@ const Status = observer((props: Props) => {
   // 产品认证配置
   const diagnoseProductAuthConfig = () =>
     new Promise(async (resolve) => {
+      if (!DiagnoseStatusModel.flag) {
+        resolve({});
+      }
       if (device?.productId) {
         const response = await service.queryProductConfig(device.productId);
         if (response.status === 200 && response.result.length > 0) {
@@ -865,125 +887,12 @@ const Status = observer((props: Props) => {
                 DiagnoseStatusModel.count++;
                 resolve({});
               }, time);
-            } else if (properties.length > 0 && Object.keys(configuration).length > 0) {
-              if (
-                _.union(Object.keys(configuration), properties).length <
-                Object.keys(configuration).length + properties.length
-              ) {
-                setTimeout(() => {
-                  DiagnoseStatusModel.list = modifyArrayList(DiagnoseStatusModel.list, {
-                    key: `product-auth${i}`,
-                    name: `产品-${item?.name}`,
-                    desc: '诊断产品MQTT认证配置是否正确,错误的配置将导致连接失败',
-                    status: 'error',
-                    text: '可能存在异常',
-                    info: (
-                      <div>
-                        <div className={styles.infoItem}>
-                          <Badge
-                            status="default"
-                            text={
-                              <span>
-                                请
-                                <a
-                                  onClick={() => {
-                                    manualInspection({
-                                      type: 'product',
-                                      key: `product-auth${i}`,
-                                      name: `产品-${item?.name}`,
-                                      desc: '诊断产品MQTT认证配置是否正确,错误的配置将导致连接失败',
-                                      data: { ...item },
-                                      configuration,
-                                      productId: device.productId,
-                                    });
-                                  }}
-                                >
-                                  人工检查
-                                </a>
-                                产品{item.name}
-                                配置是否已填写正确,若您确定该项无需诊断可
-                                <Popconfirm
-                                  title="确认忽略?"
-                                  onConfirm={() => {
-                                    DiagnoseStatusModel.list = modifyArrayList(
-                                      DiagnoseStatusModel.list,
-                                      {
-                                        key: `product-auth${i}`,
-                                        name: `产品-${item?.name}`,
-                                        desc: '诊断产品MQTT认证配置是否正确,错误的配置将导致连接失败',
-                                        status: 'success',
-                                        text: '正常',
-                                        info: null,
-                                      },
-                                    );
-                                  }}
-                                >
-                                  <a>忽略</a>
-                                </Popconfirm>
-                              </span>
-                            }
-                          />
-                        </div>
-                      </div>
-                    ),
-                  });
-                  DiagnoseStatusModel.count++;
-                  resolve({});
-                }, time);
-              } else {
-                setTimeout(() => {
-                  DiagnoseStatusModel.list = modifyArrayList(DiagnoseStatusModel.list, {
-                    key: `product-auth${i}`,
-                    name: `产品-${item?.name}`,
-                    desc: '诊断产品MQTT认证配置是否正确,错误的配置将导致连接失败',
-                    status: 'error',
-                    text: '异常',
-                    info: (
-                      <div>
-                        <div className={styles.infoItem}>
-                          <Badge
-                            status="default"
-                            text={
-                              <span>
-                                请根据设备接入配置需要
-                                <a
-                                  onClick={() => {
-                                    jumpAccessConfig();
-                                  }}
-                                >
-                                  填写
-                                </a>
-                                ,若您确定该项无需诊断可
-                                <Popconfirm
-                                  title="确认忽略?"
-                                  onConfirm={() => {
-                                    DiagnoseStatusModel.list = modifyArrayList(
-                                      DiagnoseStatusModel.list,
-                                      {
-                                        key: `product-auth${i}`,
-                                        name: `产品-${item?.name}`,
-                                        desc: '诊断产品MQTT认证配置是否正确,错误的配置将导致连接失败',
-                                        status: 'success',
-                                        text: '正常',
-                                        info: null,
-                                      },
-                                    );
-                                  }}
-                                >
-                                  <a>忽略</a>
-                                </Popconfirm>
-                              </span>
-                            }
-                          />
-                        </div>
-                      </div>
-                    ),
-                  });
-                  DiagnoseStatusModel.count++;
-                  resolve({});
-                }, time);
-              }
-            } else if (properties.length > 0 && Object.keys(configuration).length === 0) {
+            } else if (
+              !isExit(
+                properties,
+                Object.keys(configuration).filter((k: string) => !!configuration[k]),
+              )
+            ) {
               setTimeout(() => {
                 DiagnoseStatusModel.list = modifyArrayList(DiagnoseStatusModel.list, {
                   key: `product-auth${i}`,
@@ -1035,6 +944,67 @@ const Status = observer((props: Props) => {
                 DiagnoseStatusModel.count++;
                 resolve({});
               }, time);
+            } else {
+              setTimeout(() => {
+                DiagnoseStatusModel.list = modifyArrayList(DiagnoseStatusModel.list, {
+                  key: `product-auth${i}`,
+                  name: `产品-${item?.name}`,
+                  desc: '诊断产品MQTT认证配置是否正确,错误的配置将导致连接失败',
+                  status: 'error',
+                  text: '可能存在异常',
+                  info: (
+                    <div>
+                      <div className={styles.infoItem}>
+                        <Badge
+                          status="default"
+                          text={
+                            <span>
+                              请
+                              <a
+                                onClick={() => {
+                                  manualInspection({
+                                    type: 'product',
+                                    key: `product-auth${i}`,
+                                    name: `产品-${item?.name}`,
+                                    desc: '诊断产品MQTT认证配置是否正确,错误的配置将导致连接失败',
+                                    data: { ...item },
+                                    configuration,
+                                    productId: device.productId,
+                                  });
+                                }}
+                              >
+                                人工检查
+                              </a>
+                              产品{item.name}
+                              配置是否已填写正确,若您确定该项无需诊断可
+                              <Popconfirm
+                                title="确认忽略?"
+                                onConfirm={() => {
+                                  DiagnoseStatusModel.list = modifyArrayList(
+                                    DiagnoseStatusModel.list,
+                                    {
+                                      key: `product-auth${i}`,
+                                      name: `产品-${item?.name}`,
+                                      desc: '诊断产品MQTT认证配置是否正确,错误的配置将导致连接失败',
+                                      status: 'success',
+                                      text: '正常',
+                                      info: null,
+                                    },
+                                  );
+                                }}
+                              >
+                                <a>忽略</a>
+                              </Popconfirm>
+                            </span>
+                          }
+                        />
+                      </div>
+                    </div>
+                  ),
+                });
+                DiagnoseStatusModel.count++;
+                resolve({});
+              }, time);
             }
           });
         } else {
@@ -1046,6 +1016,9 @@ const Status = observer((props: Props) => {
   // 设备认证配置
   const diagnoseDeviceAuthConfig = () =>
     new Promise(async (resolve) => {
+      if (!DiagnoseStatusModel.flag) {
+        resolve({});
+      }
       if (device?.id) {
         const response = await service.queryDeviceConfig(device.id);
         if (response.status === 200 && response.result.length > 0) {
@@ -1081,125 +1054,12 @@ const Status = observer((props: Props) => {
                 DiagnoseStatusModel.count++;
                 resolve({});
               }, time);
-            } else if (properties.length > 0 && Object.keys(configuration).length > 0) {
-              if (
-                _.union(Object.keys(configuration), properties).length <
-                Object.keys(configuration).length + properties.length
-              ) {
-                setTimeout(() => {
-                  DiagnoseStatusModel.list = modifyArrayList(DiagnoseStatusModel.list, {
-                    key: `device-auth${i}`,
-                    name: `设备-${item?.name}`,
-                    desc: '诊断设备MQTT认证配置是否正确,错误的配置将导致连接失败',
-                    status: 'error',
-                    text: '可能存在异常',
-                    info: (
-                      <div>
-                        <div className={styles.infoItem}>
-                          <Badge
-                            status="default"
-                            text={
-                              <span>
-                                请
-                                <a
-                                  onClick={() => {
-                                    manualInspection({
-                                      type: 'device',
-                                      key: `device-auth${i}`,
-                                      name: `设备-${item?.name}`,
-                                      desc: '诊断设备MQTT认证配置是否正确,错误的配置将导致连接失败',
-                                      data: { ...item },
-                                      configuration,
-                                      productId: device.productId,
-                                    });
-                                  }}
-                                >
-                                  人工检查
-                                </a>
-                                设备{item.name}
-                                配置是否已填写正确,若您确定该项无需诊断可
-                                <Popconfirm
-                                  title="确认忽略?"
-                                  onConfirm={() => {
-                                    DiagnoseStatusModel.list = modifyArrayList(
-                                      DiagnoseStatusModel.list,
-                                      {
-                                        key: `device-auth${i}`,
-                                        name: `设备-${item?.name}`,
-                                        desc: '诊断设备MQTT认证配置是否正确,错误的配置将导致连接失败',
-                                        status: 'success',
-                                        text: '正常',
-                                        info: null,
-                                      },
-                                    );
-                                  }}
-                                >
-                                  <a>忽略</a>
-                                </Popconfirm>
-                              </span>
-                            }
-                          />
-                        </div>
-                      </div>
-                    ),
-                  });
-                  DiagnoseStatusModel.count++;
-                  resolve({});
-                }, time);
-              } else {
-                setTimeout(() => {
-                  DiagnoseStatusModel.list = modifyArrayList(DiagnoseStatusModel.list, {
-                    key: `device-auth${i}`,
-                    name: `设备-${item?.name}`,
-                    desc: '诊断设备MQTT认证配置是否正确,错误的配置将导致连接失败',
-                    status: 'error',
-                    text: '异常',
-                    info: (
-                      <div>
-                        <div className={styles.infoItem}>
-                          <Badge
-                            status="default"
-                            text={
-                              <span>
-                                请根据设备接入配置需要
-                                <a
-                                  onClick={() => {
-                                    jumpDeviceConfig();
-                                  }}
-                                >
-                                  填写
-                                </a>
-                                ,若您确定该项无需诊断可
-                                <Popconfirm
-                                  title="确认忽略?"
-                                  onConfirm={() => {
-                                    DiagnoseStatusModel.list = modifyArrayList(
-                                      DiagnoseStatusModel.list,
-                                      {
-                                        key: `device-auth${i}`,
-                                        name: `设备-${item?.name}`,
-                                        desc: '诊断设备MQTT认证配置是否正确,错误的配置将导致连接失败',
-                                        status: 'success',
-                                        text: '正常',
-                                        info: null,
-                                      },
-                                    );
-                                  }}
-                                >
-                                  <a>忽略</a>
-                                </Popconfirm>
-                              </span>
-                            }
-                          />
-                        </div>
-                      </div>
-                    ),
-                  });
-                  DiagnoseStatusModel.count++;
-                  resolve({});
-                }, time);
-              }
-            } else if (properties.length > 0 && Object.keys(configuration).length === 0) {
+            } else if (
+              !isExit(
+                properties,
+                Object.keys(configuration).filter((k: string) => !!configuration[k]),
+              )
+            ) {
               setTimeout(() => {
                 DiagnoseStatusModel.list = modifyArrayList(DiagnoseStatusModel.list, {
                   key: `device-auth${i}`,
@@ -1251,6 +1111,67 @@ const Status = observer((props: Props) => {
                 DiagnoseStatusModel.count++;
                 resolve({});
               }, time);
+            } else {
+              setTimeout(() => {
+                DiagnoseStatusModel.list = modifyArrayList(DiagnoseStatusModel.list, {
+                  key: `device-auth${i}`,
+                  name: `设备-${item?.name}`,
+                  desc: '诊断设备MQTT认证配置是否正确,错误的配置将导致连接失败',
+                  status: 'error',
+                  text: '可能存在异常',
+                  info: (
+                    <div>
+                      <div className={styles.infoItem}>
+                        <Badge
+                          status="default"
+                          text={
+                            <span>
+                              请
+                              <a
+                                onClick={() => {
+                                  manualInspection({
+                                    type: 'device',
+                                    key: `device-auth${i}`,
+                                    name: `设备-${item?.name}`,
+                                    desc: '诊断设备MQTT认证配置是否正确,错误的配置将导致连接失败',
+                                    data: { ...item },
+                                    configuration,
+                                    productId: device.productId,
+                                  });
+                                }}
+                              >
+                                人工检查
+                              </a>
+                              设备{item.name}
+                              配置是否已填写正确,若您确定该项无需诊断可
+                              <Popconfirm
+                                title="确认忽略?"
+                                onConfirm={() => {
+                                  DiagnoseStatusModel.list = modifyArrayList(
+                                    DiagnoseStatusModel.list,
+                                    {
+                                      key: `device-auth${i}`,
+                                      name: `设备-${item?.name}`,
+                                      desc: '诊断设备MQTT认证配置是否正确,错误的配置将导致连接失败',
+                                      status: 'success',
+                                      text: '正常',
+                                      info: null,
+                                    },
+                                  );
+                                }}
+                              >
+                                <a>忽略</a>
+                              </Popconfirm>
+                            </span>
+                          }
+                        />
+                      </div>
+                    </div>
+                  ),
+                });
+                DiagnoseStatusModel.count++;
+                resolve({});
+              }, time);
             }
           });
         } else {
@@ -1462,6 +1383,9 @@ const Status = observer((props: Props) => {
   // onenet
   const diagnoseOnenet = () =>
     new Promise(async (resolve) => {
+      if (!DiagnoseStatusModel.flag) {
+        resolve({});
+      }
       if (device.accessProvider === 'OneNet') {
         const response = await service.queryDeviceConfig(device?.id || '');
         DiagnoseStatusModel.configuration.device = response.result;
@@ -1575,6 +1499,9 @@ const Status = observer((props: Props) => {
   // ctwing
   const diagnoseCTWing = () =>
     new Promise(async (resolve) => {
+      if (!DiagnoseStatusModel.flag) {
+        resolve({});
+      }
       if (device.accessProvider === 'Ctwing') {
         const response = await service.queryDeviceConfig(device?.id || '');
         DiagnoseStatusModel.configuration.device = response.result;
@@ -1862,6 +1789,12 @@ const Status = observer((props: Props) => {
     }
   }, [DiagnoseStatusModel.status, DiagnoseStatusModel.list]);
 
+  const percentChange = () => {
+    if (DiagnoseStatusModel.percent < 100) {
+      DiagnoseStatusModel.percent += 20;
+    }
+  };
+
   const handleSearch = async () => {
     DiagnoseStatusModel.gateway = {};
     DiagnoseStatusModel.product = {};
@@ -1872,46 +1805,36 @@ const Status = observer((props: Props) => {
     DiagnoseStatusModel.count = 0;
     DiagnoseStatusModel.status = 'loading';
     DiagnoseStatusModel.percent = 0;
+    let arr: any[] = [];
     if (providerType === 'network') {
       DiagnoseStatusModel.list = [...networkInitList];
-      await diagnoseNetwork();
-      DiagnoseStatusModel.percent = 20;
-      await diagnoseGateway();
-      DiagnoseStatusModel.percent = 40;
-      await diagnoseProduct();
-      await diagnoseDevice();
-      DiagnoseStatusModel.percent = 60;
-      await diagnoseProductAuthConfig();
-      await diagnoseDeviceAuthConfig();
+      arr = [
+        diagnoseNetwork,
+        diagnoseGateway,
+        diagnoseProduct,
+        diagnoseDevice,
+        diagnoseProductAuthConfig,
+        diagnoseDeviceAuthConfig,
+      ];
     } else if (providerType === 'child-device') {
       DiagnoseStatusModel.list = [...childInitList];
-      await diagnoseGateway();
-      DiagnoseStatusModel.percent = 20;
-      await diagnoseParentDevice();
-      await diagnoseProduct();
-      DiagnoseStatusModel.percent = 40;
-      await diagnoseDevice();
-      DiagnoseStatusModel.percent = 60;
-      await diagnoseProductAuthConfig();
-      await diagnoseDeviceAuthConfig();
-      DiagnoseStatusModel.percent = 80;
+      arr = [
+        diagnoseGateway,
+        diagnoseParentDevice,
+        diagnoseProduct,
+        diagnoseDevice,
+        diagnoseProductAuthConfig,
+        diagnoseDeviceAuthConfig,
+      ];
     } else if (providerType === 'media') {
       DiagnoseStatusModel.list = [...mediaInitList];
-      await diagnoseGateway();
-      DiagnoseStatusModel.percent = 40;
-      await diagnoseProduct();
-      await diagnoseDevice();
+      arr = [diagnoseGateway, diagnoseProduct, diagnoseDevice];
     } else if (providerType === 'cloud') {
       DiagnoseStatusModel.list = [...cloudInitList];
-      await diagnoseGateway();
-      DiagnoseStatusModel.percent = 40;
-      await diagnoseProduct();
-      await diagnoseDevice();
-      DiagnoseStatusModel.percent = 80;
-      await diagnoseCTWing();
-      await diagnoseOnenet();
+      arr = [diagnoseGateway, diagnoseProduct, diagnoseDevice, diagnoseCTWing, diagnoseOnenet];
     } else if (providerType === 'channel') {
       message.error('未开发');
+      return;
       // DiagnoseStatusModel.list = [...channelInitList];
       // await diagnoseGateway();
       // DiagnoseStatusModel.percent = 20;
@@ -1925,11 +1848,18 @@ const Status = observer((props: Props) => {
       // await diagnoseDataPointBind();
       // DiagnoseStatusModel.percent = 80;
     }
-    DiagnoseStatusModel.percent = 100;
-    DiagnoseStatusModel.status = 'finish';
+    if (arr.length > 0) {
+      for (let i = 0; i < arr.length; i++) {
+        await arr[i]();
+        percentChange();
+      }
+      DiagnoseStatusModel.percent = 100;
+      DiagnoseStatusModel.status = 'finish';
+    }
   };
 
   useEffect(() => {
+    DiagnoseStatusModel.flag = true;
     if (DiagnoseStatusModel.state === 'loading' && providerType) {
       handleSearch();
     }
@@ -1940,7 +1870,7 @@ const Status = observer((props: Props) => {
       <div className={styles.statusHeader}>
         <TitleComponent data={'连接详情'} />
         <Space>
-          {DiagnoseStatusModel.status === 'finish' && (
+          {DiagnoseStatusModel.status === 'finish' && device.state?.value !== 'online' && (
             <Button
               type="primary"
               onClick={async () => {

+ 3 - 1
src/pages/device/Instance/Detail/Diagnose/Status/model.ts

@@ -1,7 +1,7 @@
 import type { ProductItem } from '@/pages/device/Product/typings';
 import { model } from '@formily/reactive';
 import type { ReactNode } from 'react';
-import { DeviceInstance } from '../../../typings';
+import type { DeviceInstance } from '../../../typings';
 
 export const StatusMap = new Map();
 StatusMap.set('error', require('/public/images/diagnose/status/error.png'));
@@ -254,6 +254,7 @@ export const DiagnoseStatusModel = model<{
       status: 'loading' | 'success' | 'error';
     };
   };
+  flag: boolean; // 离开页面后让还未执行的方法停止
 }>({
   list: [],
   product: {},
@@ -280,6 +281,7 @@ export const DiagnoseStatusModel = model<{
       status: 'loading',
     },
   },
+  flag: true,
 });
 
 export const gatewayList = [

+ 1 - 0
src/pages/device/Instance/Detail/Diagnose/index.tsx

@@ -50,6 +50,7 @@ const Diagnose = observer(() => {
       DiagnoseStatusModel.percent = 0;
       DiagnoseStatusModel.status = 'loading';
       DiagnoseStatusModel.state = 'loading';
+      DiagnoseStatusModel.flag = false;
     };
   }, [InstanceModel.active]);
 

+ 14 - 2
src/pages/device/Product/Detail/Access/index.tsx

@@ -447,10 +447,20 @@ const Access = () => {
     });
   };
 
+  const flatObj = (obj: any, result: any) => {
+    Object.keys(obj).forEach((key: string) => {
+      if (typeof obj[key] === 'string') {
+        result[key] = obj[key];
+      } else {
+        flatObj(obj[key], result);
+      }
+    });
+  };
+
   const renderConfigCard = () => {
     const itemSchema: any = (metadata || []).map((item: any) => {
       return {
-        type: 'object',
+        type: 'void',
         properties: {
           grid: {
             type: 'void',
@@ -517,7 +527,9 @@ const Access = () => {
             type="primary"
             onClick={async () => {
               const values = (await form.submit()) as any;
-              const { storePolicy, ...extra } = values;
+              const result: any = {};
+              flatObj(values, result);
+              const { storePolicy, ...extra } = result;
               const resp = await productService.modify(id || '', {
                 id,
                 configuration: { ...extra },

+ 1 - 1
src/pages/link/Type/Detail/index.tsx

@@ -735,7 +735,7 @@ const Save = observer(() => {
             enum: [{ label: 'JavaScript', value: 'javascript' }],
           },
           script: {
-            title: '脚本解析',
+            title: '解析脚本',
             'x-component': 'FMonacoEditor',
             'x-decorator': 'FormItem',
             'x-decorator-props': {

+ 1 - 1
src/pages/notice/Template/index.tsx

@@ -104,7 +104,7 @@ const Template = observer(() => {
       dataIndex: 'provider',
       title: '通知方式',
       renderText: (text, record) => {
-        return typeList[record.type][record.provider];
+        return typeList[record?.type][record?.provider];
       },
       valueType: 'select',
       valueEnum: list[id],