Bläddra i källkod

feat(merge): merge sc

fix: 诊断错误和设备接入
Lind 3 år sedan
förälder
incheckning
b9d866ea88

+ 19 - 13
src/pages/device/Instance/Detail/Diagnose/Status/ManualInspection.tsx

@@ -1,6 +1,5 @@
 import { createForm } from '@formily/core';
 import { createSchemaField } from '@formily/react';
-import { InstanceModel } from '@/pages/device/Instance';
 import type { ISchema } from '@formily/json-schema';
 import { Form, FormGrid, FormItem, Input, Password, PreviewText } from '@formily/antd';
 import { Modal } from 'antd';
@@ -21,7 +20,7 @@ const ManualInspection = (props: Props) => {
 
   const form = createForm({
     validateFirst: true,
-    initialValues: InstanceModel.detail?.configuration,
+    initialValues: {},
   });
 
   const SchemaField = createSchemaField({
@@ -88,22 +87,29 @@ const ManualInspection = (props: Props) => {
       }}
       onOk={async () => {
         const values = (await form.submit()) as any;
-        let flag = true;
-        Object.keys(values).forEach((key) => {
-          if (values[key] !== metadata?.check[key]) {
-            flag = false;
-          }
-        });
-        if (flag) {
+        if (metadata?.check) {
           props.ok({
-            status: 'success',
+            status: 'error',
             data: metadata,
           });
         } else {
-          props.ok({
-            status: 'error',
-            data: metadata,
+          let flag = true;
+          Object.keys(values).forEach((key) => {
+            if (values[key] !== metadata?.check[key]) {
+              flag = false;
+            }
           });
+          if (flag) {
+            props.ok({
+              status: 'success',
+              data: metadata,
+            });
+          } else {
+            props.ok({
+              status: 'error',
+              data: metadata,
+            });
+          }
         }
       }}
       visible

+ 24 - 20
src/pages/device/Instance/Detail/Diagnose/Status/index.tsx

@@ -61,7 +61,6 @@ const Status = observer((props: Props) => {
       desc: '诊断设备接入网关状态是否已启用,未启用的状态将导致连接失败',
     },
   ];
-  const [list, setList] = useState<any[]>([...initlist]);
   const gatewayList = [
     'websocket-server',
     'http-server-gateway',
@@ -129,8 +128,10 @@ const Status = observer((props: Props) => {
           ),
         };
       }
-      DiagnoseStatusModel.status.config = data;
-      setTimeout(() => resolve(data), time);
+      setTimeout(() => {
+        DiagnoseStatusModel.status.config = data;
+        resolve(data);
+      }, time);
     });
   //网络信息
   const diagnoseNetwork = () =>
@@ -155,7 +156,7 @@ const Status = observer((props: Props) => {
               service.queryGatewayState(resp.result.accessId).then((response: any) => {
                 if (response.status === 200) {
                   const product: any = resp.result;
-                  const address = response.result?.channelInfo?.addresses[0];
+                  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;
@@ -414,6 +415,7 @@ const Status = observer((props: Props) => {
             if (resp.result.length > 0) {
               resp.result.map((item: any, index: number) => {
                 let data: any = {};
+                const list = [...DiagnoseStatusModel.list];
                 if (!list.find((i) => i.key === `product-auth${index}`)) {
                   list.splice(list.length - 1, 0, {
                     key: `product-auth${index}`,
@@ -421,7 +423,7 @@ const Status = observer((props: Props) => {
                     data: `productAuth${index}`,
                     desc: `诊断产品${item?.name}是否正确,错误的配置将导致连接失败`,
                   });
-                  setList([...list]);
+                  DiagnoseStatusModel.list = [...list];
                 }
                 data = {
                   status: 'error',
@@ -435,7 +437,6 @@ const Status = observer((props: Props) => {
                             进行
                             <a
                               onClick={() => {
-                                console.log(proItem);
                                 setArtificialVisible(true);
                                 setArtificiaData({
                                   data: item,
@@ -474,6 +475,7 @@ const Status = observer((props: Props) => {
             if (resp.result.length > 0) {
               resp.result.map((item: any, index: number) => {
                 let data: any = {};
+                const list = [...DiagnoseStatusModel.list];
                 if (!list.find((i) => i.key === `device-auth${index}`)) {
                   list.splice(list.length - 1, 0, {
                     key: `device-auth${index}`,
@@ -481,7 +483,7 @@ const Status = observer((props: Props) => {
                     data: `deviceAuth${index}`,
                     desc: `诊断设备${item?.name}是否正确,错误的配置将导致连接失败`,
                   });
-                  setList([...list]);
+                  DiagnoseStatusModel.list = [...list];
                 }
                 data = {
                   status: 'error',
@@ -570,7 +572,7 @@ const Status = observer((props: Props) => {
 
   const handleSearch = () => {
     props.onChange('loading');
-    setList([...initlist]);
+    DiagnoseStatusModel.list = [...initlist];
     DiagnoseStatusModel.status = {
       config: {
         status: 'loading',
@@ -622,7 +624,7 @@ const Status = observer((props: Props) => {
                   });
                   if (!!a) {
                     Store.set('diagnose-status', {
-                      list,
+                      list: DiagnoseStatusModel.list,
                       status: DiagnoseStatusModel.status,
                     });
                     props.onChange('success');
@@ -640,16 +642,18 @@ const Status = observer((props: Props) => {
                       gateway.provider !== 'mqtt-server-gateway' &&
                       gatewayList.includes(gateway.provider)
                     ) {
-                      service.queryProcotolDetail(gateway.provider).then((resp1) => {
-                        setDiagnoseData({
-                          product: productauth,
-                          device: deviceauth,
-                          id: product.id,
-                          provider: gateway.provider,
-                          routes: resp1.result?.routes || [],
+                      service
+                        .queryProcotolDetail(gateway.provider, gateway.transport)
+                        .then((resp1) => {
+                          setDiagnoseData({
+                            product: productauth,
+                            device: deviceauth,
+                            id: product.id,
+                            provider: gateway.provider,
+                            routes: resp1.result?.routes || [],
+                          });
+                          setDiagnoseVisible(true);
                         });
-                        setDiagnoseVisible(true);
-                      });
                     } else {
                       setDiagnoseData({
                         product: productauth,
@@ -674,7 +678,7 @@ const Status = observer((props: Props) => {
     } else {
       const dt = Store.get('diagnose-status');
       DiagnoseStatusModel.status = dt?.status;
-      setList(dt?.list || []);
+      DiagnoseStatusModel.list = dt?.list || [];
       props.onChange('success');
     }
   }, []);
@@ -694,7 +698,7 @@ const Status = observer((props: Props) => {
             </Button>
           </div>
           <div className={styles.statusContent}>
-            {list.map((item) => (
+            {DiagnoseStatusModel.list.map((item) => (
               <div key={item.key} className={styles.statusItem}>
                 <div className={styles.statusLeft}>
                   <div className={styles.statusImg}>

+ 34 - 0
src/pages/device/Instance/Detail/Diagnose/Status/model.ts

@@ -7,6 +7,13 @@ type StatusProps = {
   info: null | ReactNode;
 };
 
+type ListProps = {
+  key: string;
+  name: string;
+  data: string;
+  desc: string;
+};
+
 export const DiagnoseStatusModel = model<{
   status: {
     config?: StatusProps;
@@ -18,6 +25,7 @@ export const DiagnoseStatusModel = model<{
     deviceAccess?: StatusProps;
     other?: StatusProps;
   };
+  list: ListProps[];
 }>({
   status: {
     config: {
@@ -51,4 +59,30 @@ export const DiagnoseStatusModel = model<{
       info: null,
     },
   },
+  list: [
+    {
+      key: 'config',
+      name: '设备接入配置',
+      data: 'config',
+      desc: '诊断设备接入配置是否正确,配置错误将导致连接失败。',
+    },
+    {
+      key: 'network',
+      name: '网络信息',
+      data: 'network',
+      desc: '诊断网络组件配置是否正确,配置错误将导致连接失败。',
+    },
+    {
+      key: 'product',
+      name: '产品状态',
+      data: 'product',
+      desc: '诊断产品状态是否已发布,未发布的状态将导致连接失败。',
+    },
+    {
+      key: 'device',
+      name: '设备状态',
+      data: 'device',
+      desc: '诊断设备状态是否已启用,未启用的状态将导致连接失败。',
+    },
+  ],
 });

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

@@ -244,8 +244,8 @@ class Service extends BaseService<DeviceInstance> {
       method: 'GET',
     });
   //
-  public queryProcotolDetail = (type: string) =>
-    request(`/${SystemConst.API_BASE}/protocol/${type}/transport/MQTT`, {
+  public queryProcotolDetail = (type: string, transport: string) =>
+    request(`/${SystemConst.API_BASE}/protocol/${type}/transport/${transport}`, {
       method: 'GET',
     });
 

+ 5 - 0
src/pages/link/AccessConfig/service.ts

@@ -9,6 +9,11 @@ class Service extends BaseService<AccessItem> {
       method: 'POST',
       data,
     });
+  public queryList = (data: any) =>
+    request(`/${SystemConst.API_BASE}/gateway/device/detail/_query`, {
+      method: 'POST',
+      data,
+    });
   public startUp = (id: string) =>
     request(`/${SystemConst.API_BASE}/gateway/device/${id}/_startup`, {
       method: 'POST',