xieyonghong 3 سال پیش
والد
کامیت
597a948545

+ 1 - 0
config/config.ts

@@ -93,4 +93,5 @@ export default defineConfig({
     );
     memo.module.rule('mjs-rule').test(/.m?js/).resolve.set('fullySpecified', false);
   },
+  devtool: 'source-map',
 });

+ 2 - 0
src/components/FSelectDevices/index.tsx

@@ -13,6 +13,7 @@ import { model } from '@formily/reactive';
 import moment from 'moment';
 
 interface Props {
+  id?: string;
   value?: Partial<DeviceInstance>[];
   onChange?: (data: Partial<DeviceInstance>[]) => void;
   productId?: string;
@@ -112,6 +113,7 @@ const FSelectDevices = observer((props: Props) => {
       <Input
         disabled
         value={props.value?.map((item) => item.name).join(',')}
+        id={props?.id}
         addonAfter={
           <EditOutlined
             onClick={() => {

+ 2 - 0
src/components/Upload/index.tsx

@@ -16,6 +16,7 @@ interface Props {
   placeholder: string;
   display?: string;
   beforeUpload: any;
+  accept?: string;
 }
 
 type FileProperty = {
@@ -92,6 +93,7 @@ const FUpload = connect((props: Props) => {
   });
   return (
     <Upload
+      accept={props?.accept}
       beforeUpload={props.beforeUpload}
       listType={map.get(props.type || 'image')?.type}
       action={`/${SystemConst.API_BASE}/file/static`}

+ 89 - 29
src/pages/device/components/Metadata/Import/index.tsx

@@ -15,7 +15,7 @@ import { onlyMessage } from '@/utils/util';
 import { ExclamationCircleOutlined } from '@ant-design/icons';
 import { InstanceModel } from '@/pages/device/Instance';
 import _ from 'lodash';
-import { DeviceMetadata } from '@/pages/device/Product/typings';
+import type { DeviceMetadata } from '@/pages/device/Product/typings';
 
 interface Props {
   visible: boolean;
@@ -44,6 +44,7 @@ const Import = (props: Props) => {
     field.loading = true;
     const product = (await service.queryNoPagingPost({
       paging: false,
+      sorts: [{ name: 'createTime', order: 'desc' }],
       terms: [{ column: 'id$not', value: param.id }],
     })) as any;
     field.dataSource = product.result
@@ -67,6 +68,12 @@ const Import = (props: Props) => {
           { label: '拷贝产品', value: 'copy' },
           { label: '导入物模型', value: 'import' },
         ],
+        'x-validator': [
+          {
+            required: true,
+            message: '请选择导入方式',
+          },
+        ],
       },
       copy: {
         title: '选择产品',
@@ -91,6 +98,12 @@ const Import = (props: Props) => {
             },
           },
         ],
+        'x-validator': [
+          {
+            required: true,
+            message: '请选择产品',
+          },
+        ],
       },
       metadata: {
         title: '物模型类型',
@@ -102,6 +115,12 @@ const Import = (props: Props) => {
         'x-component-props': {
           width: '800px',
         },
+        'x-validator': [
+          {
+            required: true,
+            message: '请选择物模型类型',
+          },
+        ],
         default: 'jetlinks',
         'x-reactions': {
           dependencies: ['.type'],
@@ -122,10 +141,17 @@ const Import = (props: Props) => {
           },
         ],
       },
-      layout: {
-        type: 'void',
-        'x-component': 'Space',
-        'x-visible': false,
+      metadataType: {
+        title: '导入类型',
+        'x-decorator': 'FormItem',
+        'x-component': 'Select',
+        'x-decorator-props': {
+          width: '800px',
+        },
+        'x-component-props': {
+          width: '800px',
+        },
+        default: 'script',
         'x-reactions': {
           dependencies: ['.type'],
           fulfill: {
@@ -134,31 +160,59 @@ const Import = (props: Props) => {
             },
           },
         },
-
-        properties: {
-          upload: {
-            'x-decorator': 'FormItem',
-            'x-component': 'FUpload',
-            'x-component-props': {
-              title: '快速导入',
-              showUploadList: false,
-              accept: '.json',
-              formatOnType: true,
-              formatOnPaste: true,
-              type: 'file',
-              beforeUpload: (file: any) => {
-                console.log(file, 'fff');
-                const reader = new FileReader();
-                reader.readAsText(file);
-                reader.onload = (json) => {
-                  form.setValues({
-                    import: json.target?.result,
-                  });
-                };
-              },
+        'x-validator': [
+          {
+            required: true,
+            message: '请选择导入类型',
+          },
+        ],
+        enum: [
+          {
+            label: '文件上传',
+            value: 'file',
+          },
+          {
+            label: '脚本',
+            value: 'script',
+          },
+        ],
+      },
+      upload: {
+        title: '文件上传',
+        'x-decorator': 'FormItem',
+        'x-component': 'FUpload',
+        'x-visible': false,
+        'x-reactions': {
+          dependencies: ['.metadataType'],
+          fulfill: {
+            state: {
+              visible: "{{$deps[0]==='file'}}",
             },
           },
         },
+        'x-validator': [
+          {
+            required: true,
+            message: '请上传文件',
+          },
+        ],
+        'x-component-props': {
+          title: '快速导入',
+          showUploadList: false,
+          accept: '.json',
+          formatOnType: true,
+          formatOnPaste: true,
+          type: 'file',
+          beforeUpload: (file: any) => {
+            const reader = new FileReader();
+            reader.readAsText(file);
+            reader.onload = (json) => {
+              form.setValues({
+                import: json.target?.result,
+              });
+            };
+          },
+        },
       },
       import: {
         title: '物模型',
@@ -175,11 +229,17 @@ const Import = (props: Props) => {
           },
         },
         'x-visible': false,
+        'x-validator': [
+          {
+            required: true,
+            message: '请输入物模型',
+          },
+        ],
         'x-reactions': {
-          dependencies: ['.type'],
+          dependencies: ['.metadataType'],
           fulfill: {
             state: {
-              visible: "{{$deps[0]==='import'}}",
+              visible: "{{$deps[0]==='script'}}",
             },
           },
         },

+ 7 - 6
src/pages/media/Cascade/Publish/index.tsx

@@ -17,15 +17,15 @@ const Publish = (props: Props) => {
   const [count, setCount] = useState<number>(0);
   const [countErr, setCountErr] = useState<number>(0);
   const [flag, setFlag] = useState<boolean>(true);
-  const [errMessage, setErrMessage] = useState<string>('');
+  const [errMessage, setErrMessage] = useState<any[]>([]);
 
   const getData = () => {
     let dt = 0;
     let et = 0;
+    const errMessages: any[] = [];
     const source = new EventSourcePolyfill(activeAPI);
     source.onmessage = (e: any) => {
       const res = JSON.parse(e.data);
-      // console.log(res);
       if (res.successful) {
         dt += 1;
         setCount(dt);
@@ -33,7 +33,8 @@ const Publish = (props: Props) => {
         et += 1;
         setCountErr(et);
         setFlag(false);
-        setErrMessage(res.message);
+        errMessages.push({ ...res });
+        setErrMessage([...errMessages]);
       }
     };
     source.onerror = () => {
@@ -60,11 +61,11 @@ const Publish = (props: Props) => {
           <div>成功: {count}</div>
           <div>
             失败: {countErr}
-            {!!errMessage && (
+            {errMessage.length > 0 && (
               <a
                 style={{ marginLeft: 20 }}
                 onClick={() => {
-                  downloadObject(JSON.parse(errMessage || '{}'), props.data.name + '-推送失败');
+                  downloadObject(errMessage, props.data.name + '-推送失败');
                 }}
               >
                 下载
@@ -77,7 +78,7 @@ const Publish = (props: Props) => {
       </Row>
       {!flag && (
         <div>
-          <Input.TextArea rows={10} value={errMessage} />
+          <Input.TextArea rows={10} value={JSON.stringify(errMessage)} />
         </div>
       )}
     </Modal>