wzyyy пре 3 година
родитељ
комит
5f4879ab51

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

@@ -26,7 +26,6 @@ const SaveChild = (props: Props) => {
   };
 
   useEffect(() => {
-    // console.log(props.childData)
     getProductList();
     if (props.childData?.id) {
       setVisible(true);

+ 30 - 21
src/pages/device/Instance/Detail/ChildDevice/index.tsx

@@ -25,6 +25,7 @@ interface Props {
 }
 
 const ChildDevice = (props: Props) => {
+  console.log(props.data);
   const intl = useIntl();
   const [visible, setVisible] = useState<boolean>(false);
   const actionRef = useRef<ActionType>();
@@ -138,16 +139,20 @@ const ChildDevice = (props: Props) => {
             </Tooltip>
           </Popconfirm>
         </a>,
-        <a
-          onClick={() => {
-            setCurrent(record);
-            setChildVisible(true);
-          }}
-        >
-          <Tooltip title={'编辑'} key={'edit'}>
-            <EditOutlined />
-          </Tooltip>
-        </a>,
+        <>
+          {props.data.accessProvider === 'official-edge-gateway' && (
+            <a
+              onClick={() => {
+                setCurrent(record);
+                setChildVisible(true);
+              }}
+            >
+              <Tooltip title={'编辑'} key={'edit'}>
+                <EditOutlined />
+              </Tooltip>
+            </a>
+          )}
+        </>,
       ],
     },
   ];
@@ -198,17 +203,21 @@ const ChildDevice = (props: Props) => {
               },
             }}
             toolBarRender={() => [
-              <Button
-                onClick={() => {
-                  // actionRef.current?.reset?.();
-                  setCurrent({});
-                  setChildVisible(true);
-                }}
-                key="save"
-                type="primary"
-              >
-                新增并绑定
-              </Button>,
+              <>
+                {props.data.accessProvider === 'official-edge-gateway' && (
+                  <Button
+                    onClick={() => {
+                      // actionRef.current?.reset?.();
+                      setCurrent({});
+                      setChildVisible(true);
+                    }}
+                    key="save"
+                    type="primary"
+                  >
+                    新增并绑定
+                  </Button>
+                )}
+              </>,
               <Button
                 onClick={() => {
                   setVisible(true);

+ 19 - 3
src/pages/device/Instance/Detail/EdgeMap/mapTable/index.tsx

@@ -28,6 +28,7 @@ const MapTable = (props: Props) => {
   const { metaData, deviceId, reload, edgeId, productList } = props;
   const [visible, setVisible] = useState<boolean>(false);
   const [channelList, setChannelList] = useState<any>([]);
+  const [deviceData, seyDeviceData] = useState<any>({});
 
   const remove = async (params: any) => {
     const res = await service.removeMap(edgeId, {
@@ -425,8 +426,18 @@ const MapTable = (props: Props) => {
         {props.title && <TitleComponent data={props.title} />}
         <Button
           style={{ marginRight: 10 }}
-          onClick={() => {
-            setVisible(true);
+          onClick={async () => {
+            const value = await props.formRef.validateFields();
+            if (value) {
+              const formData = {
+                ...value,
+                productName: productList.find((item: any) => item.id === value.productId).name,
+                parentId: edgeId,
+                // id: deviceId ? deviceId : undefined,
+              };
+              seyDeviceData(formData);
+              setVisible(true);
+            }
           }}
         >
           批量映射
@@ -460,11 +471,16 @@ const MapTable = (props: Props) => {
         <MapTree
           close={() => {
             setVisible(false);
-            reload('map');
+            if (props.formRef) {
+              props.close();
+            } else {
+              reload('map');
+            }
           }}
           deviceId={deviceId || ''}
           edgeId={edgeId}
           metaData={metaData}
+          addDevice={deviceData}
         />
       )}
     </div>

+ 30 - 12
src/pages/device/Instance/Detail/EdgeMap/mapTree/index.tsx

@@ -10,6 +10,7 @@ interface Props {
   deviceId: string;
   edgeId: string;
   metaData: any;
+  addDevice?: any;
 }
 
 const MapTree = (props: Props) => {
@@ -62,21 +63,38 @@ const MapTree = (props: Props) => {
       }));
       params.push(...array);
     });
-
-    // console.log(params)
-    const res = await service.saveMap(edgeId, {
-      deviceId: deviceId,
-      provider: params[0].provider,
-      requestList: params,
-    });
-    if (res.status === 200) {
-      onlyMessage('保存成功');
-      close();
+    const filterParms = params.filter((item) => !!item.metadataId);
+    if (deviceId) {
+      if (filterParms && filterParms.length !== 0) {
+        const res = await service.saveMap(edgeId, {
+          deviceId: deviceId,
+          provider: filterParms[0].provider,
+          requestList: filterParms,
+        });
+        if (res.status === 200) {
+          onlyMessage('保存成功');
+          close();
+        }
+      } else {
+        onlyMessage('暂无属性映射', 'warning');
+      }
+    } else {
+      const res = await service.addDevice(props.addDevice);
+      if (res.status === 200) {
+        const resp = await service.saveMap(edgeId, {
+          deviceId: res.result.id,
+          provider: filterParms[0].provider,
+          requestList: filterParms,
+        });
+        if (resp.status === 200) {
+          onlyMessage('保存成功');
+          close();
+        }
+      }
     }
   };
 
   useEffect(() => {
-    console.log(metaData);
     service.treeMap(edgeId).then((res) => {
       if (res.status === 200) {
         console.log(res.result?.[0], 'data');
@@ -98,7 +116,6 @@ const MapTree = (props: Props) => {
         close();
       }}
       onOk={() => {
-        //  close();
         save();
       }}
       width="900px"
@@ -136,6 +153,7 @@ const MapTree = (props: Props) => {
           </Card>
           <div>
             <Button
+              disabled={checked && checked.length === 0}
               onClick={() => {
                 const item = filterTree(data, checked);
                 setData(item);