wzyyy 3 лет назад
Родитель
Сommit
eac9e681df

+ 4 - 4
config/proxy.ts

@@ -12,11 +12,11 @@ export default {
       // target: 'http://192.168.32.28:8844/',
       // ws: 'ws://192.168.32.28:8844/',
       // 开发环境
-      target: 'http://120.79.18.123:8844/',
-      ws: 'ws://120.79.18.123:8844/',
+      // target: 'http://120.79.18.123:8844/',
+      // ws: 'ws://120.79.18.123:8844/',
       // 测试环境
-      // target: 'http://120.77.179.54:8844/',
-      // ws: 'ws://120.77.179.54:8844/',
+      target: 'http://120.77.179.54:8844/',
+      ws: 'ws://120.77.179.54:8844/',
       // target: 'http://192.168.66.5:8844/',
       // ws: 'ws://192.168.66.5:8844/',
       // ws: 'ws://demo.jetlinks.cn/jetlinks',

+ 1 - 1
src/pages/device/Instance/Import/index.tsx

@@ -210,7 +210,7 @@ const Import = (props: Props) => {
       });
       onFieldValueChange('upload', (field) => {
         if (!field.value) {
-          close();
+          // close();
         }
       });
     },

+ 25 - 2
src/pages/device/Instance/Process/index.tsx

@@ -1,6 +1,8 @@
 import { Badge, Modal } from 'antd';
 import { useEffect, useState } from 'react';
 import { EventSourcePolyfill } from 'event-source-polyfill';
+import { getMenuPathByParams, MENUS_CODE } from '@/utils/menu';
+import { useHistory } from 'umi';
 
 interface Props {
   api: string;
@@ -20,6 +22,9 @@ const Process = (props: Props) => {
   const [count, setCount] = useState<number>(0);
   const [flag, setFlag] = useState<boolean>(true);
   const [errMessage, setErrMessage] = useState<string>('');
+  const [isSource, setIsSource] = useState<boolean>(false);
+  const [id, setId] = useState<string>('');
+  const history = useHistory<Record<string, string>>();
   const { action } = props;
 
   const getData = () => {
@@ -29,13 +34,21 @@ const Process = (props: Props) => {
     setSource(source);
     source.onmessage = (e: any) => {
       const res = JSON.parse(e.data);
+      console.log(e.data);
       switch (action) {
         case 'active':
           if (res.success) {
             dt += res.total;
             setCount(dt);
           } else {
-            setErrMessage(res.message);
+            if (res.source) {
+              const msg = `${res.source.name}: ${res.message}`;
+              setErrMessage(msg);
+              setId(res.source.id);
+              setIsSource(true);
+            } else {
+              setErrMessage(res.message);
+            }
           }
           break;
         case 'sync':
@@ -89,7 +102,17 @@ const Process = (props: Props) => {
         <Badge status="success" text="已完成" />
       )}
       <p>总数量:{count}</p>
-      <p style={{ color: 'red' }}>{errMessage}</p>
+      <a
+        style={{ color: 'red' }}
+        onClick={() => {
+          if (isSource) {
+            const url = getMenuPathByParams(MENUS_CODE['device/Instance/Detail'], id);
+            history.push(url);
+          }
+        }}
+      >
+        {errMessage}
+      </a>
     </Modal>
   );
 };

+ 5 - 0
src/pages/device/Instance/service.ts

@@ -370,6 +370,11 @@ class Service extends BaseService<DeviceInstance> {
       method: 'POST',
       data,
     });
+  public saveMetadata = (id: string, data: any) =>
+    request(`/${SystemConst.API_BASE}/device/instance/${id}/metadata`, {
+      method: 'PUT',
+      data,
+    });
 }
 
 export default Service;

+ 12 - 4
src/pages/device/components/Metadata/Cat/index.tsx

@@ -26,25 +26,31 @@ const Cat = observer((props: Props) => {
   const [value, setValue] = useState(metadata);
   const _path = location.pathname.split('/');
   const id = _path[_path.length - 1];
+
   useEffect(() => {
     service.codecs().subscribe({
       next: (data) => {
         setCodecs([{ id: 'jetlinks', name: 'jetlinks' }].concat(data));
       },
     });
-
     if (props.type === 'device' && id) {
       instanceService.detail(id).then((resp) => {
         if (resp.status === 200) {
           InstanceModel.current = resp.result;
           const _metadata = resp.result?.metadata;
+          console.log(_metadata, '11111');
           setValue(_metadata);
         }
       });
     }
   }, [id]);
 
+  useEffect(() => {
+    console.log(value, '22222');
+  }, [value]);
+
   const convertMetadata = (key: string) => {
+    console.log(key);
     if (key === 'alink') {
       setValue('');
       if (metadata) {
@@ -55,6 +61,7 @@ const Cat = observer((props: Props) => {
         });
       }
     } else {
+      console.log(metadata, 'metadata');
       setValue(metadata);
     }
   };
@@ -62,7 +69,7 @@ const Cat = observer((props: Props) => {
     <Drawer
       maskClosable={false}
       title="查看物模型"
-      width={'40%'}
+      width={700}
       onClose={() => props.close()}
       visible={props.visible}
       extra={
@@ -92,11 +99,12 @@ const Cat = observer((props: Props) => {
       <Tabs onChange={convertMetadata}>
         {codecs?.map((item) => (
           <Tabs.TabPane tab={item.name} tabKey={item.id} key={item.id}>
-            <div style={{ border: '1px solid #eee' }}>
+            <div style={{ border: '1px solid #eee', height: 670, width: 650 }}>
               <MonacoEditor
-                height={670}
+                height={'100%'}
                 theme="vs"
                 language="json"
+                key={item.id}
                 value={value}
                 editorDidMount={(editor) => {
                   editor.getAction('editor.action.formatDocument').run();

+ 20 - 5
src/pages/device/components/Metadata/Import/index.tsx

@@ -288,7 +288,7 @@ const Import = (props: Props) => {
           onlyMessage('导入成功');
           const metadata = JSON.stringify(operateLimits(meta));
           if (props?.type === 'device') {
-            await deviceService.modify(param.id, { metadata: metadata });
+            await deviceService.saveMetadata(param.id, metadata);
           } else {
             await service.modify(param.id, { metadata: metadata });
           }
@@ -305,16 +305,31 @@ const Import = (props: Props) => {
           operateLimits(JSON.parse(data[props?.type === 'device' ? 'import' : data?.type] || '{}')),
         ),
       };
+      // const paramsDevice = {
+      //   id: param.id,
+      //   deriveMetadata: JSON.stringify(
+      //     operateLimits(JSON.parse(data[props?.type === 'device' ? 'import' : data?.type] || '{}')),
+      //   ),
+      // };
+      const paramsDevice = JSON.stringify(
+        operateLimits(JSON.parse(data[props?.type === 'device' ? 'import' : data?.type] || '{}')),
+      );
       let resp: any = undefined;
       if (props?.type === 'device') {
-        resp = await deviceService.modify(param.id, params);
+        resp = await deviceService.saveMetadata(param.id, paramsDevice);
       } else {
         resp = await service.modify(param.id, params);
       }
       if (resp.status === 200) {
-        const metadata: DeviceMetadata = JSON.parse(params?.metadata || '{}');
-        MetadataAction.insert(metadata);
-        onlyMessage('导入成功');
+        if (props?.type === 'device') {
+          const metadata: DeviceMetadata = JSON.parse(paramsDevice || '{}');
+          MetadataAction.insert(metadata);
+          onlyMessage('导入成功');
+        } else {
+          const metadata: DeviceMetadata = JSON.parse(params?.metadata || '{}');
+          MetadataAction.insert(metadata);
+          onlyMessage('导入成功');
+        }
       }
     }
     Store.set(SystemConst.GET_METADATA, true);

+ 6 - 0
src/pages/media/Device/Save/ProviderSelect.tsx

@@ -10,6 +10,7 @@ import { providerType, service } from '@/pages/media/Device';
 import { useCallback, useEffect, useRef, useState } from 'react';
 import { getMenuPathByCode, MENUS_CODE } from '@/utils/menu';
 import { useRequest } from '@@/plugin-request/request';
+import { CheckOutlined } from '@ant-design/icons';
 
 interface ProviderProps {
   value?: string;
@@ -134,6 +135,11 @@ export default (props: ProviderProps) => {
                   </div>
                 </div>
               </div>
+              <div className="checkedIcon">
+                <div>
+                  <CheckOutlined />
+                </div>
+              </div>
             </TableCard>
           </div>
         ))

+ 29 - 0
src/pages/media/Device/Save/providerSelect.less

@@ -4,9 +4,38 @@
   max-height: 450px;
   overflow-y: auto;
 
+  .checkedIcon {
+    position: absolute;
+    right: -22px;
+    bottom: -22px;
+    z-index: 2;
+    display: none;
+    width: 44px;
+    height: 44px;
+    color: #fff;
+    background-color: red;
+    background-color: #2f54eb;
+    transform: rotate(-45deg);
+
+    > div {
+      position: relative;
+      height: 100%;
+      transform: rotate(45deg);
+
+      > span {
+        position: absolute;
+        top: 6px;
+        left: 6px;
+        font-size: 12px;
+      }
+    }
+  }
   .active {
     .card-warp {
       border-color: @primary-color-active;
     }
+    .checkedIcon {
+      display: block;
+    }
   }
 }

+ 3 - 3
src/pages/system/Role/Detail/UserManage/index.tsx

@@ -128,7 +128,7 @@ const UserManage = () => {
           </Space>
         )}
         columnEmptyText={''}
-        toolBarRender={() => [
+        headerTitle={
           <Button
             onClick={() => {
               setBindUserVisible(true);
@@ -138,8 +138,8 @@ const UserManage = () => {
             type="primary"
           >
             添加
-          </Button>,
-        ]}
+          </Button>
+        }
         rowSelection={{
           selectedRowKeys: selectedRowKeys,
           onChange: (key) => {