Selaa lähdekoodia

fix: opcua,modbus修复

wzyyy 3 vuotta sitten
vanhempi
commit
496e084461

+ 13 - 7
src/pages/device/Instance/Detail/Modbus/index.tsx

@@ -134,7 +134,7 @@ const Modbus = () => {
                     id: 'pages.data.option.remove',
                     defaultMessage: '删除',
                   })
-                : '请先禁用该组件,再删除。',
+                : '请先禁用该点位,再删除。',
           }}
           popConfirm={{
             title: '确认删除',
@@ -161,14 +161,20 @@ const Modbus = () => {
     },
   ];
 
-  const getModbus = () => {
+  const getModbus = (id: string) => {
     service
-      .query({
+      .queryMetadatabyId({
         paging: false,
+        terms: [
+          {
+            column: 'id$bind-modbus',
+            value: id,
+          },
+        ],
       })
       .then((res) => {
-        setBindList(res.result.data);
-        setOpcId(res.result?.data?.[0].id);
+        setBindList(res.result);
+        setOpcId(res.result?.[0]?.id);
       });
   };
 
@@ -176,7 +182,7 @@ const Modbus = () => {
     const { id } = InstanceModel.detail;
     setDeviceId(id);
     if (id) {
-      getModbus();
+      getModbus(id);
     }
   }, [visible]);
 
@@ -261,7 +267,7 @@ const Modbus = () => {
                           onConfirm: async () => {
                             const resp: any = await service.remove(item.id);
                             if (resp.status === 200) {
-                              getModbus();
+                              getModbus(deviceId);
                               message.success(
                                 intl.formatMessage({
                                   id: 'pages.data.option.success',

+ 5 - 2
src/pages/link/Channel/Modbus/Access/addPoint/index.tsx

@@ -29,10 +29,10 @@ const AddPoint = (props: Props) => {
           props.close();
         }
       });
-    console.log(formData);
   };
 
   useEffect(() => {
+    console.log(props.data);
     service.deviceDetail(props.deviceId).then((res: any) => {
       if (res.result.metadata) {
         const item = JSON.parse(res.result?.metadata);
@@ -56,7 +56,10 @@ const AddPoint = (props: Props) => {
         layout="vertical"
         initialValues={{
           ...props.data,
-          // readIndex:props.data?.readIndex || 0,
+          codecConfig: {
+            readIndex: props.data?.codecConfig?.readIndex || 0,
+            scaleFactor: props.data?.codecConfig?.scaleFactor || 1,
+          },
         }}
       >
         <Row gutter={[24, 24]}>

+ 10 - 6
src/pages/link/Channel/Modbus/Access/bindDevice/index.tsx

@@ -52,12 +52,16 @@ const BindDevice = (props: Props) => {
   ];
 
   const save = () => {
-    service.bind(keys, props.id).then((res) => {
-      if (res.status === 200) {
-        message.success('绑定成功');
-        props.close();
-      }
-    });
+    if (keys && keys.length !== 0) {
+      service.bind(keys, props.id).then((res) => {
+        if (res.status === 200) {
+          message.success('绑定成功');
+          props.close();
+        }
+      });
+    } else {
+      message.error('请勾选数据');
+    }
   };
 
   return (

+ 9 - 9
src/pages/link/Channel/Modbus/Access/index.tsx

@@ -97,14 +97,14 @@ const Access = () => {
           popConfirm={{
             title: intl.formatMessage({
               id: `pages.data.option.${
-                record.state.value !== 'disabled' ? 'disabled' : 'enabled'
+                record.state?.value !== 'disabled' ? 'disabled' : 'enabled'
               }.tips`,
               defaultMessage: '确认禁用?',
             }),
             onConfirm: async () => {
               const item = {
                 ...record,
-                state: record.state.value === 'enabled' ? 'disabled' : 'enabled',
+                state: record.state?.value === 'enabled' ? 'disabled' : 'enabled',
               };
               await service.saveMetadataConfig(opcUaId, deviceId, item);
               message.success(
@@ -120,24 +120,24 @@ const Access = () => {
           tooltip={{
             title: intl.formatMessage({
               id: `pages.data.option.${record.state.value !== 'disabled' ? 'disabled' : 'enabled'}`,
-              defaultMessage: record.state.value !== 'disabled' ? '禁用' : '启用',
+              defaultMessage: record.state?.value !== 'disabled' ? '禁用' : '启用',
             }),
           }}
         >
-          {record.state.value !== 'disabled' ? <StopOutlined /> : <PlayCircleOutlined />}
+          {record.state?.value !== 'disabled' ? <StopOutlined /> : <PlayCircleOutlined />}
         </PermissionButton>,
         <PermissionButton
           isPermission={permission.delete}
           style={{ padding: 0 }}
-          disabled={record.state.value === 'enabled'}
+          disabled={record.state?.value === 'enabled'}
           tooltip={{
             title:
-              record.state.value === 'disabled'
+              record.state?.value === 'disabled'
                 ? intl.formatMessage({
                     id: 'pages.data.option.remove',
                     defaultMessage: '删除',
                   })
-                : '请先禁用该组件,再删除。',
+                : '请先禁用该点位,再删除。',
           }}
           popConfirm={{
             title: '确认删除',
@@ -264,8 +264,8 @@ const Access = () => {
                               }
                             });
                           }}
-                          okText="Yes"
-                          cancelText="No"
+                          okText=""
+                          cancelText=""
                         >
                           <DisconnectOutlined className={styles.icon} />
                         </Popconfirm>

+ 6 - 0
src/pages/link/Channel/Modbus/service.ts

@@ -46,6 +46,12 @@ class Service extends BaseService<OpaUa> {
     request(`/${SystemConst.API_BASE}/modbus/master/metadata/${metadataId}`, {
       method: 'DELETE',
     });
+  //设备id查modbus通道
+  queryMetadatabyId = (data: any) =>
+    request(`/${SystemConst.API_BASE}/modbus/master/_query/no-paging`, {
+      method: 'POST',
+      data,
+    });
 }
 
 export default Service;

+ 17 - 13
src/pages/link/Channel/Opcua/Access/bindDevice/index.tsx

@@ -53,19 +53,23 @@ const BindDevice = (props: Props) => {
   ];
 
   const save = () => {
-    const params = bindDevice.map((item: any) => ({
-      opcUaId: props.id,
-      deviceId: item.id,
-      deviceName: item.name,
-      productId: item.productId,
-      productName: item.productName,
-    }));
-    service.bind(params).then((res) => {
-      if (res.status === 200) {
-        message.success('绑定成功');
-        props.close();
-      }
-    });
+    if (bindDevice && bindDevice.length !== 0) {
+      const params = bindDevice.map((item: any) => ({
+        opcUaId: props.id,
+        deviceId: item.id,
+        deviceName: item.name,
+        productId: item.productId,
+        productName: item.productName,
+      }));
+      service.bind(params).then((res) => {
+        if (res.status === 200) {
+          message.success('绑定成功');
+          props.close();
+        }
+      });
+    } else {
+      message.error('请勾选数据');
+    }
   };
 
   useEffect(() => {

+ 2 - 2
src/pages/link/Channel/Opcua/Access/index.tsx

@@ -267,8 +267,8 @@ const Access = () => {
                               }
                             });
                           }}
-                          okText="Yes"
-                          cancelText="No"
+                          okText=""
+                          cancelText=""
                         >
                           <DisconnectOutlined className={styles.icon} />
                         </Popconfirm>

+ 1 - 1
src/pages/link/Channel/Opcua/Save/index.tsx

@@ -94,7 +94,7 @@ const Save = (props: Props) => {
               {
                 pattern:
                   '(opc.tcp|http|https|opc.http|opc.https|opc.ws|opc.wss)://([^:/]+|\\[.*])(:\\d+)?(/.*)?',
-                message: '格式错误(opc.tcp://127.0.0.1:49320)',
+                message: '以固定协议(http,https,opc.tcp等)字段开头,并用://与IP地址连接',
               },
             ],
             name: 'endpoint',

+ 1 - 1
src/pages/link/Channel/Opcua/index.tsx

@@ -244,7 +244,7 @@ const Opcua = () => {
           </PermissionButton>
         }
         request={async (params) =>
-          service.query({ ...params, sorts: [{ name: 'createTime', order: 'desc' }] })
+          service.query({ ...params, sorts: [{ name: 'id', order: 'desc' }] })
         }
       />
       {visible && (