Bladeren bron

fix(metadata): fix getUnits

Lind 4 jaren geleden
bovenliggende
commit
40cf852550

+ 7 - 1
src/components/Metadata/ArrayParam/index.tsx

@@ -1,5 +1,5 @@
 import { createSchemaField } from '@formily/react';
-import { FormLayout, Editable, Select, FormItem, Input, NumberPicker } from '@formily/antd';
+import { Editable, FormItem, FormLayout, Input, NumberPicker, Select } from '@formily/antd';
 import type { ISchema } from '@formily/json-schema';
 import './index.less';
 import { DataTypeList, DateTypeList, FileTypeList } from '@/pages/device/data';
@@ -67,6 +67,12 @@ const ArrayParam = () => {
             'x-decorator': 'FormItem',
             'x-component': 'Select',
             'x-visible': false,
+            'x-component-props': {
+              showSearch: true,
+              showArrow: true,
+              filterOption: (input: string, option: any) =>
+                option.label.toLowerCase().indexOf(input.toLowerCase()) >= 0,
+            },
             enum: Store.get('units'),
             'x-reactions': {
               dependencies: ['.type'],

+ 30 - 8
src/components/Metadata/JsonParam/index.tsx

@@ -11,6 +11,8 @@ import { createSchemaField } from '@formily/react';
 import type { ISchema } from '@formily/json-schema';
 import { DataTypeList, DateTypeList } from '@/pages/device/data';
 import { Store } from 'jetlinks-store';
+import { useAsyncDataSource } from '@/utils/util';
+import { service } from '@/pages/device/components/Metadata';
 
 // 不算是自定义组件。只是抽离了JSONSchema
 interface Props {
@@ -30,6 +32,17 @@ const JsonParam = (props: Props) => {
       NumberPicker,
     },
   });
+  const getUnit = () =>
+    service.getUnit().then((resp) => {
+      const _data = resp.result.map((item: any) => ({
+        label: item.description,
+        value: item.id,
+      }));
+      // 缓存单位数据
+      Store.set('units', _data);
+      return _data;
+    });
+
   const schema: ISchema = {
     type: 'object',
     properties: {
@@ -101,15 +114,24 @@ const JsonParam = (props: Props) => {
                       '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])}}",
+                      'x-component-props': {
+                        showSearch: true,
+                        showArrow: true,
+                        filterOption: (input: string, option: any) =>
+                          option.label.toLowerCase().indexOf(input.toLowerCase()) >= 0,
+                      },
+                      enum: Store.get('units'),
+                      'x-reactions': [
+                        {
+                          dependencies: ['..valueType.type'],
+                          fulfill: {
+                            state: {
+                              visible: "{{['int','float','long','double'].includes($deps[0])}}",
+                            },
                           },
                         },
-                      },
+                        '{{useAsyncDataSource(getUnit)}}',
+                      ],
                     },
                     format: {
                       title: '时间格式',
@@ -196,6 +218,6 @@ const JsonParam = (props: Props) => {
       },
     },
   };
-  return <SchemaField schema={schema} />;
+  return <SchemaField schema={schema} scope={{ useAsyncDataSource, getUnit }} />;
 };
 export default JsonParam;

+ 23 - 0
src/global.less

@@ -65,3 +65,26 @@ ol {
   display: flex;
   justify-content: center;
 }
+
+.ant-form-item-required {
+  &::before {
+    position: absolute;
+    right: -12px;
+  }
+}
+
+.ant-formily-item-label-content {
+  position: relative;
+  overflow: unset;
+
+  .ant-formily-item-asterisk {
+    float: right;
+    margin-right: 0;
+    //position: absolute;
+    //right: -8px;
+  }
+}
+
+.ant-formily-item-colon {
+  display: none;
+}

+ 0 - 1
src/pages/device/components/Metadata/Base/Edit/index.tsx

@@ -777,7 +777,6 @@ const Edit = observer((props: Props) => {
       }
     };
 
-    console.log(typeMap.get(props.type), 'log');
     const _data = updateMetadata(type, [params], typeMap.get(props.type), updateDB);
     // console.log(params, JSON.parse(_data.metadata));
     // if (props.type === 'product') {

+ 2 - 2
src/pages/user/Login/index.tsx

@@ -10,7 +10,7 @@ import { Form, FormItem, Input, Password, Submit } from '@formily/antd';
 import { catchError, filter, mergeMap } from 'rxjs/operators';
 import * as ICONS from '@ant-design/icons';
 import { useModel } from '@@/plugin-model/useModel';
-import SystemConst from '@/utils/const';
+// import SystemConst from '@/utils/const';
 import { useIntl } from '@@/plugin-locale/localeExports';
 import { SelectLang } from '@@/plugin-locale/SelectLang';
 import Footer from '@/components/Footer';
@@ -166,7 +166,7 @@ const Login: React.FC = () => {
               <div className={styles.header}>
                 <Link to="/">
                   <img alt="logo" className={styles.logo} src="/logo.svg" />
-                  <span className={styles.title}>{SystemConst.SYSTEM_NAME}</span>
+                  {/*<span className={styles.title}>{SystemConst.SYSTEM_NAME}</span>*/}
                 </Link>
               </div>
               <div className={styles.desc}>