wzyyy 3 lat temu
rodzic
commit
a3bb0414e2

+ 1 - 1
src/app.tsx

@@ -63,7 +63,7 @@ export async function getInitialState(): Promise<{
   };
   const getSettings = async () => {
     try {
-      const res = await Service.settingDetail('basis');
+      const res = await Service.settingDetail('front');
       return res.result;
     } catch (error) {
       history.push(loginPath);

+ 12 - 5
src/pages/device/Instance/Detail/Modbus/index.tsx

@@ -160,8 +160,8 @@ export default (props: Props) => {
     field.loading = true;
     api(field).then(
       action.bound!((resp: Response<any>) => {
-        const value = resp.result?.[0].parameter.quantity;
-        field.dataSource = [...new Array(value).keys()].map((item: any) => ({
+        const value = resp.result?.[0].parameter.quantity || '';
+        field.dataSource = [...new Array(value * 2).keys()].map((item: any) => ({
           label: item,
           value: item,
         }));
@@ -240,8 +240,15 @@ export default (props: Props) => {
             }
             return x;
           }, metadata);
-          setProperties(array);
-          setFilterList(array);
+          //删除物模型
+          const items = array.filter((item: any) => item.metadataName);
+          setProperties(items);
+          setFilterList(items);
+          const delList = array.filter((a: any) => !a.metadataName).map((b: any) => b.id);
+          //删除后解绑
+          if (delList && delList.length !== 0) {
+            service.removeDevicePoint(data.id, delList);
+          }
         }
       });
     } else {
@@ -307,7 +314,7 @@ export default (props: Props) => {
         );
         if ((field as Field).modified) {
           const readIndex = field.query(path).get('value');
-          const dataLength = field.query(path).get('dataSource')?.length * 2 - 1;
+          const dataLength = field.query(path).get('dataSource')?.length - 1;
           const length = lengthMap.get(value) + readIndex;
           console.log(length, dataLength);
           if (length > dataLength) {

+ 2 - 3
src/pages/link/Channel/Modbus/Export/index.tsx

@@ -9,13 +9,12 @@ import SystemConst from '@/utils/const';
 import { downloadFile } from '@/utils/util';
 
 interface Props {
-  visible: boolean;
   close: () => void;
   data: any;
 }
 
 const Export = (props: Props) => {
-  const { visible, close } = props;
+  const { close } = props;
   const [list, setList] = useState<any[]>([]);
   const SchemaField = createSchemaField({
     components: {
@@ -108,7 +107,7 @@ const Export = (props: Props) => {
   return (
     <Modal
       maskClosable={false}
-      visible={visible}
+      visible
       onCancel={() => close()}
       width="35vw"
       title="导出"

+ 2 - 3
src/pages/link/Channel/Modbus/import/index.tsx

@@ -10,7 +10,6 @@ import { UploadOutlined } from '@ant-design/icons';
 import { EventSourcePolyfill } from 'event-source-polyfill';
 
 interface Props {
-  visible: boolean;
   close: () => void;
   masterId: any;
 }
@@ -167,7 +166,7 @@ const NormalUpload = (props: any) => {
   );
 };
 const Import = (props: Props) => {
-  const { visible, close, masterId } = props;
+  const { close, masterId } = props;
 
   useEffect(() => {
     console.log(masterId);
@@ -220,7 +219,7 @@ const Import = (props: Props) => {
   return (
     <Modal
       maskClosable={false}
-      visible={visible}
+      visible
       onCancel={() => close()}
       width="35vw"
       title="导入"

+ 25 - 17
src/pages/link/Channel/Modbus/index.tsx

@@ -14,7 +14,7 @@ import {
   SearchOutlined,
   StopOutlined,
 } from '@ant-design/icons';
-import { useEffect, useRef, useState } from 'react';
+import { useEffect, useMemo, useRef, useState } from 'react';
 import { useIntl } from 'umi';
 import ChannelCard from '../channelCard';
 import { PageContainer } from '@ant-design/pro-layout';
@@ -354,6 +354,19 @@ const NewModbus = () => {
     return () => wsRef.current && wsRef.current?.unsubscribe();
   }, [pointList]);
 
+  const masterMemo = useMemo(
+    () => (
+      <Export
+        data={masterList}
+        close={() => {
+          setExportVisible(false);
+          actionRef.current?.reload();
+        }}
+      />
+    ),
+    [masterList],
+  );
+
   return (
     <PageContainer>
       <Card className="modbus" style={{ minHeight }}>
@@ -561,22 +574,17 @@ const NewModbus = () => {
           }}
         />
       )}
-      <Import
-        masterId={activeKey}
-        close={() => {
-          setImportVisible(false);
-          actionRef.current?.reload();
-        }}
-        visible={importVisible}
-      />
-      <Export
-        data={masterList}
-        close={() => {
-          setExportVisible(false);
-          actionRef.current?.reload();
-        }}
-        visible={exportVisible}
-      />
+      {importVisible && (
+        <Import
+          masterId={activeKey}
+          close={() => {
+            setImportVisible(false);
+            actionRef.current?.reload();
+          }}
+          // visible={importVisible}
+        />
+      )}
+      {exportVisible && masterMemo}
     </PageContainer>
   );
 };