Procházet zdrojové kódy

fix: 修改协议管理

sun-chaochao před 3 roky
rodič
revize
42de777e8b

+ 23 - 5
src/pages/device/Instance/Detail/Diagnose/Message/index.tsx

@@ -31,6 +31,7 @@ const DatePicker1: any = DatePicker;
 const Message = (props: Props) => {
   const [subscribeTopic] = useSendWebsocketMessage();
   const [dialogList, setDialogList] = useState<any[]>([]);
+  const [tempList, setTempList] = useState<any[]>([]);
   const [logList, setLogList] = useState<any[]>([]);
   const [type, setType] = useState<'property' | 'function'>('function');
   const [input, setInput] = useState<any>({});
@@ -48,11 +49,6 @@ const Message = (props: Props) => {
     subscribeTopic!(id, topic, {})
       ?.pipe(map((res) => res.payload))
       .subscribe((payload: any) => {
-        if (payload.error) {
-          props.onChange(!payload.upstream ? 'down-error' : 'up-error');
-        } else {
-          props.onChange(!payload.upstream ? 'down-success' : 'up-success');
-        }
         if (payload.type === 'log') {
           logList.push({
             key: randomString(),
@@ -60,6 +56,26 @@ const Message = (props: Props) => {
           });
           setLogList([...logList]);
         } else {
+          tempList.push({
+            key: randomString(),
+            ...payload,
+          });
+          const flag = [...tempList]
+            .filter(
+              (i) =>
+                i.traceId === payload.traceId &&
+                (payload.downstream === i.downstream || payload.upstream === i.upstream),
+            )
+            .every((item) => {
+              return !item.error;
+            });
+          if (!flag) {
+            props.onChange(!payload.upstream ? 'down-error' : 'up-error');
+          } else {
+            props.onChange(!payload.upstream ? 'down-success' : 'up-success');
+          }
+          setTempList([...tempList]);
+          Store.set('temp', tempList);
           const t = dialogList.find(
             (item) =>
               item.traceId === payload.traceId &&
@@ -153,6 +169,8 @@ const Message = (props: Props) => {
     subscribeLog();
     const arr = Store.get('diagnose') || [];
     setDialogList(arr);
+    const temp = Store.get('temp') || [];
+    setTempList(temp);
   }, []);
 
   const form = createForm({

+ 42 - 40
src/pages/device/Instance/Detail/Diagnose/Status/index.tsx

@@ -80,6 +80,9 @@ const Status = observer((props: Props) => {
   const [diagnoseData, setDiagnoseData] = useState<any>({});
   const [artificiaData, setArtificiaData] = useState<any>({});
 
+  const [productTemp, setProductTemp] = useState<any>({});
+  const [gatewayTemp, setGatewayTemp] = useState<any>({});
+
   const getDetail = (id: string) => {
     service.detail(id).then((response) => {
       InstanceModel.detail = response?.result;
@@ -91,6 +94,7 @@ const Status = observer((props: Props) => {
       let data: any = {};
       if (InstanceModel.detail.state?.value === 'online' || !!InstanceModel.detail?.protocol) {
         data = { status: 'success', text: '正常', info: null };
+        DiagnoseStatusModel.status = { ...DiagnoseStatusModel.status };
       } else {
         data = {
           status: 'warning',
@@ -142,6 +146,7 @@ const Status = observer((props: Props) => {
       if (InstanceModel.detail.state?.value === 'online') {
         data = { status: 'success', text: '正常', info: null };
         DiagnoseStatusModel.status.network = data;
+        DiagnoseStatusModel.status = { ...DiagnoseStatusModel.status };
         setTimeout(
           () =>
             resolve({
@@ -242,6 +247,7 @@ const Status = observer((props: Props) => {
                     };
                   }
                   DiagnoseStatusModel.status.network = data;
+                  DiagnoseStatusModel.status = { ...DiagnoseStatusModel.status };
                   setTimeout(
                     () =>
                       resolve({
@@ -330,6 +336,7 @@ const Status = observer((props: Props) => {
                                 text: '正常',
                                 info: null,
                               };
+                              DiagnoseStatusModel.status = { ...DiagnoseStatusModel.status };
                             }
                           }}
                         >
@@ -384,6 +391,7 @@ const Status = observer((props: Props) => {
                               info: null,
                             };
                             getDetail(InstanceModel.detail?.id || '');
+                            DiagnoseStatusModel.status = { ...DiagnoseStatusModel.status };
                           }
                         }}
                       >
@@ -557,6 +565,7 @@ const Status = observer((props: Props) => {
                               text: '正常',
                               info: null,
                             };
+                            DiagnoseStatusModel.status = { ...DiagnoseStatusModel.status };
                           }
                         }}
                       >
@@ -607,20 +616,18 @@ const Status = observer((props: Props) => {
 
     let product: any = null;
     let gateway: any = null;
-    let productauth: any = null;
-    let deviceauth: any = null;
     diagnoseConfig()
       .then(() => diagnoseNetwork())
       .then((resp: any) => {
         product = resp?.product;
+        setProductTemp(resp?.product);
         gateway = resp?.gatewayDetail;
+        setGatewayTemp(resp?.gatewayDetail);
         diagnoseProduct(product)
           .then(() => diagnoseDevice())
           .then(() => diagnoseProductAuthConfig(product))
-          .then((res) => {
-            productauth = res;
-            diagnoseDeviceAuthConfig().then((dt) => {
-              deviceauth = dt;
+          .then(() => {
+            diagnoseDeviceAuthConfig().then(() => {
               diagnoseDeviceAccess(gateway).then(() => {
                 if (InstanceModel.detail.state?.value === 'online') {
                   const a = Object.keys(DiagnoseStatusModel.status).find((item: any) => {
@@ -636,39 +643,6 @@ const Status = observer((props: Props) => {
                     props.onChange('error');
                   }
                 } else {
-                  const data = { ...DiagnoseStatusModel.status };
-                  const flag = Object.keys(data).find((item: any) => {
-                    return item.status !== 'success';
-                  });
-                  if (!flag) {
-                    // 展示诊断建议
-                    if (
-                      gateway.provider !== 'mqtt-server-gateway' &&
-                      gatewayList.includes(gateway.provider)
-                    ) {
-                      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);
-                        });
-                    } else {
-                      setDiagnoseData({
-                        product: productauth,
-                        device: deviceauth,
-                        id: product.id,
-                        provider: '',
-                        routes: [],
-                      });
-                      setDiagnoseVisible(true);
-                    }
-                  }
                 }
               });
             });
@@ -689,6 +663,32 @@ const Status = observer((props: Props) => {
     }
   }, [devicePermission]);
 
+  useEffect(() => {
+    const data = { ...DiagnoseStatusModel.status };
+    const flag = Object.keys(data).every((item: any) => {
+      return data[item]?.status === 'success';
+    });
+    if (flag) {
+      // 展示诊断建议
+      if (
+        InstanceModel.detail.state?.value !== 'online' &&
+        gatewayTemp.provider !== 'mqtt-server-gateway' &&
+        gatewayList.includes(gatewayTemp.provider)
+      ) {
+        service.queryProcotolDetail(gatewayTemp.provider, gatewayTemp.transport).then((resp1) => {
+          setDiagnoseData({
+            product: productTemp,
+            device: InstanceModel.detail,
+            id: productTemp.id,
+            provider: gatewayTemp.provider,
+            routes: resp1.result?.routes || [],
+          });
+          setDiagnoseVisible(true);
+        });
+      }
+    }
+  }, [DiagnoseStatusModel.status]);
+
   return (
     <Row gutter={24}>
       <Col span={16}>
@@ -762,6 +762,7 @@ const Status = observer((props: Props) => {
                 text: '正常',
                 info: null,
               };
+              DiagnoseStatusModel.status = { ...DiagnoseStatusModel.status };
             } else {
               DiagnoseStatusModel.status[params.data.key] = {
                 status: 'error',
@@ -783,7 +784,8 @@ const Status = observer((props: Props) => {
                               const tab: any = window.open(`${origin}/#${url}?key=access`);
                               tab!.onTabSaveSuccess = (value: any) => {
                                 if (value) {
-                                  diagnoseConfig();
+                                  getDetail(InstanceModel.detail?.id || '');
+                                  handleSearch();
                                 }
                               };
                             }}

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

@@ -206,14 +206,14 @@ class Service extends BaseService<DeviceInstance> {
     });
   // 读取属性
   public readProperties = (deviceId: string, data: any) =>
-    request(`/${SystemConst.API_BASE}/device-instance/${deviceId}/properties/_read`, {
+    request(`/${SystemConst.API_BASE}/device/instance/${deviceId}/properties/_read`, {
       method: 'POST',
       data,
     });
   // 设置属性
   public settingProperties = (deviceId: string, data: any) =>
-    request(`/${SystemConst.API_BASE}//device-instance/${deviceId}/property`, {
-      method: 'POST',
+    request(`/${SystemConst.API_BASE}/device/instance/${deviceId}/property`, {
+      method: 'PUT',
       data,
     });
   //获取协议设置的默认物模型

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

@@ -338,7 +338,7 @@ const Access = () => {
                   请先
                   <Button
                     type="link"
-                    disabled={!!(productModel.current?.count && productModel.current?.count > 0)}
+                    // disabled={!!(productModel.current?.count && productModel.current?.count > 0)}
                     onClick={() => {
                       setConfigVisible(true);
                     }}

+ 1 - 0
src/pages/link/Protocol/index.tsx

@@ -294,6 +294,7 @@ const Protocol = () => {
           }}
           reload={() => {
             actionRef.current?.reload();
+            setVisible(false);
           }}
         />
       )}

+ 1 - 1
src/pages/link/Protocol/save/index.tsx

@@ -203,7 +203,7 @@ const Save = (props: Props) => {
   const save = async (deploy: boolean) => {
     const value = await form.submit<ProtocolItem>();
     let response = undefined;
-    if (props.data?.id) {
+    if (!props.data?.id) {
       response = await service.save(value);
     } else {
       response = await service.update(value);

+ 43 - 1
src/pages/system/Relationship/Save/index.tsx

@@ -1,6 +1,6 @@
 import { useIntl } from 'umi';
+import { onFieldValueChange, onFieldInputValueChange, createForm } from '@formily/core';
 import type { Field } from '@formily/core';
-import { createForm } from '@formily/core';
 import { createSchemaField } from '@formily/react';
 import React from 'react';
 import * as ICONS from '@ant-design/icons';
@@ -39,6 +39,16 @@ const Save = (props: Props) => {
     );
   };
 
+  const _validator = async (object: string, target: string, relation: string) => {
+    if (!relation || !target || !object) return;
+    const resp = await service.validator({
+      relation,
+      objectType: JSON.parse(object).objectType,
+      targetType: JSON.parse(target).targetType,
+    });
+    return resp?.result.passed;
+  };
+
   const form = createForm({
     validateFirst: true,
     initialValues: {
@@ -56,6 +66,38 @@ const Save = (props: Props) => {
           })
         : undefined,
     },
+    effects() {
+      onFieldInputValueChange('relation', async (field, f1) => {
+        const relation = field.value;
+        const target = (field.query('target').take() as Field).value;
+        const object = (field.query('object').take() as Field).value;
+        if (!relation || !target || !object) return;
+        const temp = await _validator(object, target, relation);
+        f1.setFieldState('relation', (state) => {
+          state.selfErrors = !temp ? ['关系标识已存在'] : undefined;
+        });
+      });
+      onFieldValueChange('target', async (field, f1) => {
+        const target = field.value;
+        const relation = (field.query('relation').take() as Field).value;
+        const object = (field.query('object').take() as Field).value;
+        if (!relation || !target || !object) return;
+        const temp = await _validator(object, target, relation);
+        f1.setFieldState('relation', (state) => {
+          state.selfErrors = !temp ? ['关系标识已存在'] : undefined;
+        });
+      });
+      onFieldValueChange('object', async (field, f1) => {
+        const object = field.value;
+        const target = (field.query('target').take() as Field).value;
+        const relation = (field.query('relation').take() as Field).value;
+        if (!relation || !target || !object) return;
+        const temp = await _validator(object, target, relation);
+        f1.setFieldState('relation', (state) => {
+          state.selfErrors = !temp ? ['关系标识已存在'] : undefined;
+        });
+      });
+    },
   });
 
   const SchemaField = createSchemaField({

+ 6 - 0
src/pages/system/Relationship/service.ts

@@ -7,6 +7,12 @@ class Service extends BaseService<ReationItem> {
     request(`/${SystemConst.API_BASE}/relation/types`, {
       method: 'GET',
     });
+
+  validator = (params: any) =>
+    request(`/${SystemConst.API_BASE}/relation/_validate?`, {
+      method: 'GET',
+      params,
+    });
 }
 
 export default Service;