ソースを参照

解决设备账台导入失败

hezhanp 8 ヶ月 前
コミット
afd21ef9b0

+ 12 - 4
src/api/system/file/index.js

@@ -18,13 +18,21 @@ export async function uploadFile(data) {
  * 导入文件 批量
  * @param file 文件
  */
-export async function importBatch(data,api,onUploadProgressCb,fileKeyName='file') {
+export async function importBatch(data, api, onUploadProgressCb, fileKeyName = 'file') {
   const formData = new FormData();
-  data.multiPartFiles.forEach((item, index) => {
+  
+  data.multiPartFiles.forEach((item) => {
     formData.append(fileKeyName, item);
   });
-  const res = await request.post(api, formData,{
-    onUploadProgress:onUploadProgressCb?onUploadProgressCb:()=>{}
+  
+  Object.keys(data).forEach(key => {
+    if (key !== 'multiPartFiles') {
+      formData.append(key, data[key]);
+    }
+  });
+  
+  const res = await request.post(api, formData, {
+    onUploadProgress: onUploadProgressCb ? onUploadProgressCb : () => {}
   });
   if (res.data.code === '0') {
     return res.data;

+ 45 - 38
src/components/upload/import-dialog.vue

@@ -64,7 +64,11 @@
         type: Boolean,
         default: true
       } ,
-      fileKeyName:'file'
+      fileKeyName:'file',
+       rootCategoryLevelId: {
+    type: [Number, String], // 类型与主组件rootId一致
+    default: '' // 默认值为空,避免无值时报错
+  }
     },
     //注册组件
     data() {
@@ -80,7 +84,8 @@
       };
     },
 
-    created() {},
+    created() {
+    },
     methods: {
       open() {
         this.attaments = [];
@@ -105,44 +110,46 @@
         this.attaments.push(param.file);
       },
       // 文件上传
-      async upload() {
-        if (this.attaments.length == 0) {
-          return this.$message.warning('文件不能为空!');
-        }
-        this.module = this.$props.defModule;
-        this.isProgress = true;
-        this.percentage = 0;
-        await importBatch(
-          {
-            module: this.module,
-            multiPartFiles: this.attaments
-          },
-          this.apiUrl,
-          (data) => {
-            console.log(data, 'data');
-            this.percentage = parseFloat(
-              ((data.loaded * 100) / data.total).toFixed(2)
-            );
-            if (this.percentage >= 100) {
-              setTimeout(() => {
-                this.isProgress = false;
-              }, 500);
-            }
-          },
-          this.fileKeyName
-        )
-          .then((res) => {
-            this.$message.success('操作成功!');
-            this.dialogVisible = false;
-            this.isProgress = false;
-            this.$emit('success');
-          })
-          .catch(() => {
-            this.isProgress = false;
-          });
-      },
+async upload() {
+  if (this.attaments.length == 0) {
+    return this.$message.warning('文件不能为空!');
+  }
+  this.module = this.$props.defModule;
+  this.isProgress = true;
+  this.percentage = 0;
+  await importBatch(
+    {
+      module: this.module,
+      multiPartFiles: this.attaments,
+      rootCategoryLevelId: this.rootCategoryLevelId
+    },
+    this.apiUrl,
+    (data) => {
+      console.log(data, 'data');
+      this.percentage = parseFloat(
+        ((data.loaded * 100) / data.total).toFixed(2)
+      );
+      if (this.percentage >= 100) {
+        setTimeout(() => {
+          this.isProgress = false;
+        }, 500);
+      }
+    },
+    this.fileKeyName,
+  )
+    .then((res) => {
+      this.$message.success('操作成功!');
+      this.dialogVisible = false;
+      this.isProgress = false;
+      this.$emit('success');
+    })
+    .catch(() => {
+      this.isProgress = false;
+    });
+},
       //下载模板
       downLoadTemplate() {
+        
         if(this.isWeb){
           download1(window.location.origin + this.fileUrl, this.fileName);
         }else{

+ 1 - 0
src/views/ledgerAssets/equipment/components/equipment-list.vue

@@ -149,6 +149,7 @@
       :isWeb="false"
       fileName="设备台账导入模板"
       apiUrl="/main/asset/importFile"
+  :rootCategoryLevelId="rootId" 
     />
   </div>
 </template>