Преглед изворни кода

feat(metadata): handle metadata component data

Lind пре 4 година
родитељ
комит
8f5706c2e9

+ 34 - 38
src/components/Metadata/ArrayParam/index.tsx

@@ -62,7 +62,7 @@ const ArrayParam = () => {
               },
               },
             },
             },
           },
           },
-          units: {
+          unit: {
             title: '单位',
             title: '单位',
             'x-decorator': 'FormItem',
             'x-decorator': 'FormItem',
             'x-component': 'Select',
             'x-component': 'Select',
@@ -77,23 +77,47 @@ const ArrayParam = () => {
               },
               },
             },
             },
           },
           },
-          maxLength: {
-            title: '最大长度',
+          format: {
+            title: '时间格式',
             'x-decorator': 'FormItem',
             'x-decorator': 'FormItem',
-            'x-component': 'NumberPicker',
+            'x-component': 'Select',
+            enum: DateTypeList,
             'x-reactions': {
             'x-reactions': {
               dependencies: ['.type'],
               dependencies: ['.type'],
               fulfill: {
               fulfill: {
                 state: {
                 state: {
-                  visible: "{{['string'].includes($deps[0])}}",
+                  visible: "{{['date'].includes($deps[0])}}",
+                },
+              },
+            },
+          },
+          expands: {
+            type: 'object',
+            properties: {
+              maxLength: {
+                title: '最大长度',
+                'x-decorator': 'FormItem',
+                'x-component': 'NumberPicker',
+                'x-decorator-props': {
+                  tooltip: '字节',
+                },
+                'x-reactions': {
+                  dependencies: ['..type'],
+                  fulfill: {
+                    state: {
+                      visible: "{{['string','password'].includes($deps[0])}}",
+                    },
+                  },
                 },
                 },
               },
               },
             },
             },
           },
           },
+
           booleanConfig: {
           booleanConfig: {
             title: '布尔值',
             title: '布尔值',
             'x-decorator': 'FormItem',
             'x-decorator': 'FormItem',
             'x-component': 'BooleanEnum',
             'x-component': 'BooleanEnum',
+            type: 'void',
             'x-reactions': {
             'x-reactions': {
               dependencies: ['.type'],
               dependencies: ['.type'],
               fulfill: {
               fulfill: {
@@ -105,6 +129,7 @@ const ArrayParam = () => {
           },
           },
           enumConfig: {
           enumConfig: {
             title: '枚举项',
             title: '枚举项',
+            type: 'void',
             'x-decorator': 'FormItem',
             'x-decorator': 'FormItem',
             'x-component': 'EnumParam',
             'x-component': 'EnumParam',
             'x-reactions': {
             'x-reactions': {
@@ -116,14 +141,14 @@ const ArrayParam = () => {
               },
               },
             },
             },
           },
           },
-          'valueType.elementType.fileType': {
+          fileType: {
             title: '文件类型',
             title: '文件类型',
             'x-decorator': 'FormItem',
             'x-decorator': 'FormItem',
             'x-component': 'Select',
             'x-component': 'Select',
             'x-visible': false,
             'x-visible': false,
             enum: FileTypeList,
             enum: FileTypeList,
             'x-reactions': {
             'x-reactions': {
-              dependencies: ['...type'],
+              dependencies: ['.type'],
               fulfill: {
               fulfill: {
                 state: {
                 state: {
                   visible: "{{['file'].includes($deps[0])}}",
                   visible: "{{['file'].includes($deps[0])}}",
@@ -133,6 +158,7 @@ const ArrayParam = () => {
           },
           },
           jsonConfig: {
           jsonConfig: {
             title: 'JSON对象',
             title: 'JSON对象',
+            type: 'void',
             'x-decorator': 'FormItem',
             'x-decorator': 'FormItem',
             'x-component': 'JsonParam',
             'x-component': 'JsonParam',
             'x-reactions': {
             'x-reactions': {
@@ -144,37 +170,7 @@ const ArrayParam = () => {
               },
               },
             },
             },
           },
           },
-          'valueType.elementType.expands.maxLength': {
-            title: '密码长度',
-            'x-decorator': 'FormItem',
-            'x-component': 'NumberPicker',
-            'x-decorator-props': {
-              tooltip: '字节',
-            },
-            'x-visible': false,
-            'x-reactions': {
-              dependencies: ['....type'],
-              fulfill: {
-                state: {
-                  visible: "{{['password'].includes($deps[0])}}",
-                },
-              },
-            },
-          },
-          'valueType.elementType.format': {
-            title: '时间格式',
-            'x-decorator': 'FormItem',
-            'x-component': 'Select',
-            enum: DateTypeList,
-            'x-reactions': {
-              dependencies: ['...type'],
-              fulfill: {
-                state: {
-                  visible: "{{['date'].includes($deps[0])}}",
-                },
-              },
-            },
-          },
+
           description: {
           description: {
             title: '描述',
             title: '描述',
             'x-decorator': 'FormItem',
             'x-decorator': 'FormItem',

+ 7 - 13
src/components/Metadata/EnumParam/index.tsx

@@ -14,9 +14,9 @@ const EnumParam = () => {
   });
   });
 
 
   const schema: ISchema = {
   const schema: ISchema = {
-    type: 'void',
+    type: 'object',
     properties: {
     properties: {
-      config: {
+      elements: {
         type: 'array',
         type: 'array',
         'x-component': 'ArrayItems',
         'x-component': 'ArrayItems',
         items: {
         items: {
@@ -36,19 +36,12 @@ const EnumParam = () => {
               'x-component-props': {
               'x-component-props': {
                 layout: 'vertical',
                 layout: 'vertical',
               },
               },
-              'x-reactions': [
-                {
-                  fulfill: {
-                    schema: {
-                      title: '{{$self.query(".label").value()}}',
-                    },
-                  },
-                },
-              ],
+              'x-reactions':
+                '{{(field)=>field.title = field.value && (field.value.text) || field.title}}',
               properties: {
               properties: {
-                label: {
+                text: {
                   type: 'string',
                   type: 'string',
-                  title: 'Label',
+                  title: 'Text',
                   required: true,
                   required: true,
                   'x-decorator': 'FormItem',
                   'x-decorator': 'FormItem',
                   'x-component': 'Input',
                   'x-component': 'Input',
@@ -87,4 +80,5 @@ const EnumParam = () => {
   };
   };
   return <SchemaField schema={schema} />;
   return <SchemaField schema={schema} />;
 };
 };
+
 export default EnumParam;
 export default EnumParam;

+ 45 - 21
src/components/Metadata/JsonParam/index.tsx

@@ -29,7 +29,7 @@ const JsonParam = () => {
   const schema: ISchema = {
   const schema: ISchema = {
     type: 'object',
     type: 'object',
     properties: {
     properties: {
-      json2: {
+      properties: {
         type: 'array',
         type: 'array',
         'x-component': 'ArrayItems',
         'x-component': 'ArrayItems',
         'x-decorator': 'FormItem',
         'x-decorator': 'FormItem',
@@ -43,7 +43,7 @@ const JsonParam = () => {
               'x-component': 'ArrayItems.SortHandle',
               'x-component': 'ArrayItems.SortHandle',
             },
             },
             config: {
             config: {
-              type: 'object',
+              type: 'void',
               title: '配置参数',
               title: '配置参数',
               'x-decorator': 'Editable.Popover',
               'x-decorator': 'Editable.Popover',
               'x-component': 'FormLayout',
               'x-component': 'FormLayout',
@@ -54,7 +54,7 @@ const JsonParam = () => {
                 placement: 'left',
                 placement: 'left',
               },
               },
               'x-reactions':
               'x-reactions':
-                '{{(field)=>field.title = field.value && (field.value.name) || field.title}}',
+                '{{(field)=>field.title = field.query(".config.name").get("value") || field.title}}',
               properties: {
               properties: {
                 id: {
                 id: {
                   title: '标识',
                   title: '标识',
@@ -68,28 +68,52 @@ const JsonParam = () => {
                   'x-decorator': 'FormItem',
                   'x-decorator': 'FormItem',
                   'x-component': 'Input',
                   'x-component': 'Input',
                 },
                 },
-                'valueType.type': {
-                  title: '数据类型',
-                  required: true,
-                  'x-decorator': 'FormItem',
-                  'x-component': 'Select',
-                  enum: DataTypeList,
-                },
-                'valueType.unit': {
-                  title: '单位',
-                  'x-decorator': 'FormItem',
-                  'x-component': 'Select',
-                  'x-visible': false,
-                  enum: Store.get('units'), // 理论上首层已经就缓存了单位数据,此处可直接获取
-                  'x-reactions': {
-                    dependencies: ['..valueType.type'],
-                    fulfill: {
-                      state: {
-                        visible: "{{['int','float','long','double'].includes($deps[0])}}",
+                valueType: {
+                  type: 'object',
+                  properties: {
+                    type: {
+                      title: '数据类型',
+                      required: true,
+                      'x-decorator': 'FormItem',
+                      'x-component': 'Select',
+                      enum: DataTypeList,
+                    },
+                    unit: {
+                      title: '单位',
+                      'x-decorator': 'FormItem',
+                      'x-component': 'Select',
+                      'x-visible': false,
+                      enum: Store.get('units'), // 理论上首层已经就缓存了单位数据,此处可直接获取
+                      'x-reactions': {
+                        dependencies: ['..valueType.type'],
+                        fulfill: {
+                          state: {
+                            visible: "{{['int','float','long','double'].includes($deps[0])}}",
+                          },
+                        },
+                      },
+                    },
+                    expands: {
+                      type: 'object',
+                      properties: {
+                        maxLength: {
+                          title: '最大长度',
+                          'x-decorator': 'FormItem',
+                          'x-component': 'NumberPicker',
+                          'x-reactions': {
+                            dependencies: ['..type'],
+                            fulfill: {
+                              state: {
+                                visible: "{{['string'].includes($deps[0])}}",
+                              },
+                            },
+                          },
+                        },
                       },
                       },
                     },
                     },
                   },
                   },
                 },
                 },
+
                 'valueType.scale': {
                 'valueType.scale': {
                   title: '精度',
                   title: '精度',
                   'x-decorator': 'FormItem',
                   'x-decorator': 'FormItem',

+ 150 - 145
src/pages/device/Product/Detail/Metadata/Base/Edit/index.tsx

@@ -72,175 +72,180 @@ const Edit = () => {
         'x-decorator': 'FormItem',
         'x-decorator': 'FormItem',
         'x-component': 'Input',
         'x-component': 'Input',
       },
       },
-      'expands.source': {
-        title: '来源',
-        required: true,
-        'x-decorator': 'FormItem',
-        'x-component': 'Select',
-        enum: PropertySource,
-      },
-      'valueType.type': {
-        title: '数据类型',
-        required: true,
-        'x-decorator': 'FormItem',
-        'x-component': 'Select',
-        enum: DataTypeList,
-      },
-      'expands.maxLength': {
-        title: '最大长度',
-        'x-decorator': 'FormItem',
-        'x-component': 'NumberPicker',
-        'x-reactions': {
-          dependencies: ['valueType.type'],
-          fulfill: {
-            state: {
-              visible: "{{['string'].includes($deps[0])}}",
-            },
+      valueType: {
+        type: 'object',
+        properties: {
+          type: {
+            title: '数据类型',
+            required: true,
+            'x-decorator': 'FormItem',
+            'x-component': 'Select',
+            enum: DataTypeList,
           },
           },
-        },
-      },
-      jsonConfig: {
-        title: 'JSON对象',
-        'x-decorator': 'FormItem',
-        'x-component': 'JsonParam',
-        'x-reactions': {
-          dependencies: ['.valueType.type'],
-          fulfill: {
-            state: {
-              visible: "{{['object'].includes($deps[0])}}",
+          unit: {
+            title: '单位',
+            'x-decorator': 'FormItem',
+            'x-component': 'Select',
+            'x-visible': false,
+            enum: units,
+            'x-reactions': {
+              dependencies: ['.type'],
+              fulfill: {
+                state: {
+                  visible: "{{['int','float','long','double'].includes($deps[0])}}",
+                },
+              },
             },
             },
           },
           },
-        },
-      },
-      arrayConfig: {
-        title: '元素配置',
-        'x-decorator': 'FormItem',
-        'x-component': 'ArrayParam',
-        'x-reactions': {
-          dependencies: ['.valueType.type'],
-          fulfill: {
-            state: {
-              visible: "{{['array'].includes($deps[0])}}",
+          scale: {
+            title: '精度',
+            'x-decorator': 'FormItem',
+            'x-component': 'NumberPicker',
+            'x-reactions': {
+              dependencies: ['.type'],
+              fulfill: {
+                state: {
+                  visible: "{{['float','double'].includes($deps[0])}}",
+                },
+              },
             },
             },
           },
           },
-        },
-      },
-      enumConfig: {
-        title: '枚举项',
-        'x-decorator': 'FormItem',
-        'x-component': 'EnumParam',
-        'x-reactions': {
-          dependencies: ['.valueType.type'],
-          fulfill: {
-            state: {
-              visible: "{{['enum'].includes($deps[0])}}",
+          booleanConfig: {
+            title: '布尔值',
+            type: 'void',
+            'x-decorator': 'FormItem',
+            'x-component': 'BooleanEnum',
+            'x-reactions': {
+              dependencies: ['.type'],
+              fulfill: {
+                state: {
+                  visible: "{{['boolean'].includes($deps[0])}}",
+                },
+              },
             },
             },
           },
           },
-        },
-      },
-      booleanConfig: {
-        title: '布尔值',
-        'x-decorator': 'FormItem',
-        'x-component': 'BooleanEnum',
-        'x-reactions': {
-          dependencies: ['.valueType.type'],
-          fulfill: {
-            state: {
-              visible: "{{['boolean'].includes($deps[0])}}",
+          format: {
+            title: '时间格式',
+            'x-decorator': 'FormItem',
+            'x-component': 'Select',
+            enum: DateTypeList,
+            'x-reactions': {
+              dependencies: ['.type'],
+              fulfill: {
+                state: {
+                  visible: "{{['date'].includes($deps[0])}}",
+                },
+              },
             },
             },
           },
           },
-        },
-      },
-      'valueType.elementType.format': {
-        title: '时间格式',
-        'x-decorator': 'FormItem',
-        'x-component': 'Select',
-        enum: DateTypeList,
-        'x-reactions': {
-          dependencies: ['valueType.type'],
-          fulfill: {
-            state: {
-              visible: "{{['date'].includes($deps[0])}}",
+          enumConfig: {
+            title: '枚举项',
+            type: 'void',
+            'x-decorator': 'FormItem',
+            'x-component': 'EnumParam',
+            'x-reactions': {
+              dependencies: ['.type'],
+              fulfill: {
+                state: {
+                  visible: "{{['enum'].includes($deps[0])}}",
+                },
+              },
             },
             },
           },
           },
-        },
-      },
-      'valueType.scale': {
-        title: '精度',
-        'x-decorator': 'FormItem',
-        'x-component': 'NumberPicker',
-        'x-reactions': {
-          dependencies: ['valueType.type'],
-          fulfill: {
-            state: {
-              visible: "{{['float','double'].includes($deps[0])}}",
+          expands: {
+            type: 'object',
+            properties: {
+              maxLength: {
+                title: '最大长度',
+                'x-decorator': 'FormItem',
+                'x-component': 'NumberPicker',
+                'x-decorator-props': {
+                  tooltip: '字节',
+                },
+                'x-reactions': {
+                  dependencies: ['..type'],
+                  fulfill: {
+                    state: {
+                      visible: "{{['string','password'].includes($deps[0])}}",
+                    },
+                  },
+                },
+              },
             },
             },
           },
           },
-        },
-      },
-      'valueType.elementType.fileType': {
-        title: '文件类型',
-        'x-decorator': 'FormItem',
-        'x-component': 'Select',
-        'x-visible': false,
-        enum: FileTypeList,
-        'x-reactions': {
-          dependencies: ['valueType.type'],
-          fulfill: {
-            state: {
-              visible: "{{['file'].includes($deps[0])}}",
+          elementType: {
+            title: '元素配置',
+            'x-decorator': 'FormItem',
+            'x-component': 'ArrayParam',
+            'x-reactions': {
+              dependencies: ['.type'],
+              fulfill: {
+                state: {
+                  visible: "{{['array'].includes($deps[0])}}",
+                },
+              },
             },
             },
           },
           },
-        },
-      },
-      'valueType.elementType.expands.maxLength': {
-        title: '密码长度',
-        'x-decorator': 'FormItem',
-        'x-component': 'NumberPicker',
-        'x-decorator-props': {
-          tooltip: '字节',
-        },
-        'x-visible': false,
-        'x-reactions': {
-          dependencies: ['valueType.type'],
-          fulfill: {
-            state: {
-              visible: "{{['password'].includes($deps[0])}}",
+          jsonConfig: {
+            title: 'JSON对象',
+            type: 'void',
+            'x-decorator': 'FormItem',
+            'x-component': 'JsonParam',
+            'x-reactions': {
+              dependencies: ['.type'],
+              fulfill: {
+                state: {
+                  visible: "{{['object'].includes($deps[0])}}",
+                },
+              },
             },
             },
           },
           },
-        },
-      },
-      'valueType.unit': {
-        title: '单位',
-        'x-decorator': 'FormItem',
-        'x-component': 'Select',
-        'x-visible': false,
-        enum: units,
-        'x-reactions': {
-          dependencies: ['valueType.type'],
-          fulfill: {
-            state: {
-              visible: "{{['int','float','long','double'].includes($deps[0])}}",
+          fileType: {
+            title: '文件类型',
+            'x-decorator': 'FormItem',
+            'x-component': 'Select',
+            'x-visible': false,
+            enum: FileTypeList,
+            'x-reactions': {
+              dependencies: ['.type'],
+              fulfill: {
+                state: {
+                  visible: "{{['file'].includes($deps[0])}}",
+                },
+              },
             },
             },
           },
           },
         },
         },
       },
       },
-      'expands.readOnly': {
-        title: '是否只读',
-        required: true,
-        'x-decorator': 'FormItem',
-        'x-component': 'Radio.Group',
-        enum: [
-          {
-            label: '是',
-            value: true,
+      expands: {
+        type: 'object',
+        properties: {
+          source: {
+            title: '来源',
+            required: true,
+            'x-decorator': 'FormItem',
+            'x-component': 'Select',
+            enum: PropertySource,
           },
           },
-          {
-            label: '否',
-            value: false,
+          readOnly: {
+            title: '是否只读',
+            required: true,
+            'x-decorator': 'FormItem',
+            'x-component': 'Radio.Group',
+            enum: [
+              {
+                label: '是',
+                value: true,
+              },
+              {
+                label: '否',
+                value: false,
+              },
+            ],
           },
           },
-        ],
+        },
       },
       },
+
       description: {
       description: {
         title: '描述',
         title: '描述',
         'x-decorator': 'FormItem',
         'x-decorator': 'FormItem',