浏览代码

feat(metadata): device metadata data design

Lind 4 年之前
父节点
当前提交
deab276920

+ 0 - 15
src/pages/device/Instance/Detail/Metadata/ItemDetail/index.tsx

@@ -75,21 +75,6 @@ const ItemDetail = observer(() => {
           { label: 'geoPoint(地理位置)', value: 'geoPoint' },
         ],
       },
-      json: {
-        type: 'object',
-        title: 'JSON对象',
-        'x-display': 'none',
-        'x-decorator': 'FormItem',
-        'x-component': 'JsonParamComponent',
-        'x-reactions': {
-          dependencies: ['dataType'],
-          fulfill: {
-            state: {
-              display: '{{($deps[0]==="object")?"visible":"none"}}',
-            },
-          },
-        },
-      },
       readOnly: {
         type: 'string',
         title: '只读',

+ 13 - 2
src/pages/device/Instance/Detail/Metadata/ItemParam/index.tsx

@@ -19,20 +19,24 @@ import { InstanceModel, service } from '@/pages/device/Instance';
 import type { Unit } from '@/pages/device/Instance/typings';
 import type { ISchema } from '@formily/json-schema';
 import ProCard from '@ant-design/pro-card';
+import { useState } from 'react';
 
 const ItemParam = observer(() => {
+  const [cardId, setCardId] = useState<string>('');
   const form = createForm({
     validateFirst: true,
-    readPretty: true,
+    readPretty: InstanceModel.active === cardId,
     effects() {
       onFieldValueChange('type', (field) => {
         const type = field.query('type').value();
         const id = field.query('id').value();
+        setCardId(`${id}-$${InstanceModel.params.size}`);
         const temp = Array.from(InstanceModel.params).map((item) => item.split('-$')[0]);
         const includes = new Set(temp).has(id);
         if (includes && type !== 'object') {
           InstanceModel.params.delete(`${id}-$${InstanceModel.params.size - 1}`);
         } else if (id && type === 'object') {
+          InstanceModel.active = `${id}-$${InstanceModel.params.size}`;
           InstanceModel.params.add(`${id}-$${InstanceModel.params.size}`);
         }
       });
@@ -166,9 +170,16 @@ const ItemParam = observer(() => {
       },
     },
   };
+
+  const saveParam = async () => {
+    console.log(cardId, InstanceModel.params);
+    const values = await form.submit();
+    console.log(values, 'vv');
+    InstanceModel.params.delete(cardId);
+  };
   return (
     <ProCard
-      extra={<a>保存</a>}
+      extra={<a onClick={saveParam}>保存</a>}
       bordered={true}
       colSpan={500}
       style={{ height: '40vh', marginRight: 10 }}