Просмотр исходного кода

feat(import): 新增批量导入动态参数并移除文件大小限制

- importBatchNew 支持动态追加 params 到 FormData
- import-dialogNew 移除 10MB 上传限制,新增 param 属性透传
- 分类详情页新增导入入口,导入时传递当前节点 id
yusheng 2 недель назад
Родитель
Сommit
c560210def

+ 3 - 0
src/api/system/file/index.js

@@ -191,6 +191,9 @@ export async function importBatchNew(data) {
   data.multiPartFiles.forEach((item, index) => {
   data.multiPartFiles.forEach((item, index) => {
     formData.append(`multiPartFiles`, item);
     formData.append(`multiPartFiles`, item);
   });
   });
+  for (let key in data.params) {
+    formData.append(`${key}`, data.params[key]);
+  }
   const res = await request.post(data.apiUrl, formData);
   const res = await request.post(data.apiUrl, formData);
   if (res.data.code === '0') {
   if (res.data.code === '0') {
     return res.data;
     return res.data;

+ 11 - 14
src/components/upload/import-dialogNew.vue

@@ -8,7 +8,6 @@
           action="#"
           action="#"
           :show-file-list="false"
           :show-file-list="false"
           :http-request="handlSuccess"
           :http-request="handlSuccess"
-          :before-upload="beforeUpload"
           :multiple="true"
           :multiple="true"
         >
         >
           <el-button icon="el-icon-plus" size="small" type="primary"
           <el-button icon="el-icon-plus" size="small" type="primary"
@@ -49,7 +48,7 @@
 </template>
 </template>
 
 
 <script>
 <script>
-  import { importBatch,importBatchNew } from '@/api/system/file/index.js';
+  import { importBatch, importBatchNew } from '@/api/system/file/index.js';
   // import { download1 } from '@/utils/file';
   // import { download1 } from '@/utils/file';
   import { downLoadTemplateNew } from '@/api/system/file/index.js';
   import { downLoadTemplateNew } from '@/api/system/file/index.js';
   export default {
   export default {
@@ -58,7 +57,11 @@
       defModule: '',
       defModule: '',
       fileUrl: '',
       fileUrl: '',
       fileName: '',
       fileName: '',
-      apiUrl: ''
+      apiUrl: '',
+      param: {
+        type: Object,
+        default: () => ({})
+      }
     },
     },
     //注册组件
     //注册组件
     data() {
     data() {
@@ -84,14 +87,7 @@
       delFileList(index) {
       delFileList(index) {
         this.attaments.splice(index, 1);
         this.attaments.splice(index, 1);
       },
       },
-      //上传限制
-      beforeUpload(file) {
-        const isLt10M = file.size / 1024 / 1024 < 10;
-        if (!isLt10M) {
-          this.$message.error('导入单文件大小不能超过 10MB!');
-        }
-        return isLt10M;
-      },
+
       //图片上传
       //图片上传
       handlSuccess(param) {
       handlSuccess(param) {
         this.file = param.file;
         this.file = param.file;
@@ -102,13 +98,14 @@
         if (this.attaments.length == 0) {
         if (this.attaments.length == 0) {
           return this.$message.warning('文件不能为空!');
           return this.$message.warning('文件不能为空!');
         }
         }
-        this.module = this.$props.defModule;
+        this.module = this.defModule;
         this.uploading = true;
         this.uploading = true;
-        let api=this.apiUrl?importBatchNew: importBatch
+        let api = this.apiUrl ? importBatchNew : importBatch;
         await api({
         await api({
           module: this.module,
           module: this.module,
           multiPartFiles: this.attaments,
           multiPartFiles: this.attaments,
-          apiUrl:this.apiUrl
+          apiUrl: this.apiUrl,
+          ...this.param
         }).finally(() => {
         }).finally(() => {
           this.uploading = false;
           this.uploading = false;
         });
         });

+ 61 - 32
src/views/classifyManage/treeClassify/details.vue

@@ -10,38 +10,53 @@
           <!-- 操作按钮 -->
           <!-- 操作按钮 -->
           <ele-toolbar class="ele-toolbar-actions">
           <ele-toolbar class="ele-toolbar-actions">
             <div style="margin: 5px 0">
             <div style="margin: 5px 0">
-              <el-button
-                size="small"
-                type="primary"
-                icon="el-icon-plus"
-                class="ele-btn-icon"
-                @click="openEdit(true)"
-                v-if="$hasPermission('main:categorylevel:save')"
-              >
-                新建下级节点
-              </el-button>
-              <el-button
-                size="small"
-                type="warning"
-                icon="el-icon-edit"
-                class="ele-btn-icon"
-                :disabled="!current.id || current.id == rootId"
-                @click="openEdit(false)"
-                v-if="$hasPermission('main:categorylevel:update')"
+              <div>
+                <el-button
+                  size="small"
+                  type="primary"
+                  icon="el-icon-plus"
+                  class="ele-btn-icon"
+                  @click="openEdit(true)"
+                  v-if="$hasPermission('main:categorylevel:save')"
+                >
+                  新建下级节点
+                </el-button>
+                <el-button
+                  size="small"
+                  type="warning"
+                  icon="el-icon-edit"
+                  class="ele-btn-icon"
+                  :disabled="!current.id || current.id == rootId"
+                  @click="openEdit(false)"
+                  v-if="$hasPermission('main:categorylevel:update')"
+                >
+                  编辑节点
+                </el-button>
+                <el-button
+                  size="small"
+                  type="danger"
+                  icon="el-icon-delete"
+                  class="ele-btn-icon"
+                  :disabled="!current.id || current.id == rootId"
+                  @click="deleteCategory"
+                  v-if="$hasPermission('main:categorylevel:delete')"
+                >
+                  删除
+                </el-button></div
               >
               >
-                编辑节点
-              </el-button>
-              <el-button
-                size="small"
-                type="danger"
-                icon="el-icon-delete"
-                class="ele-btn-icon"
-                :disabled="!current.id || current.id == rootId"
-                @click="deleteCategory"
-                v-if="$hasPermission('main:categorylevel:delete')"
+              <div>
+                <el-button
+                  size="small"
+                  type="primary"
+                  icon="el-icon-download"
+                  class="ele-btn-icon"
+                  @click="importProfession"
+                  style="margin-top: 5px"
+                  v-if="$hasPermission('main:categorylevel:update')"
+                >
+                  导入
+                </el-button></div
               >
               >
-                删除
-              </el-button>
             </div>
             </div>
           </ele-toolbar>
           </ele-toolbar>
           <div class="ele-border-lighter sys-organization-list">
           <div class="ele-border-lighter sys-organization-list">
@@ -169,7 +184,16 @@
       :rootId="rootId"
       :rootId="rootId"
       :curNode="curNode"
       :curNode="curNode"
     />
     />
-    <!-- <classify-manage-edit ref="editRef" @done="reload" /> -->
+    <importDialog
+      ref="importDialogRef"
+      :apiUrl="'/main/factoryworkstation/importBatch'"
+      :fileUrl="'/main/factoryworkstation/downLoadTemplate'"
+      fileName="分类导入模板"
+      @success="reload"
+      :param="{
+        id: current.id
+      }"
+    />
   </div>
   </div>
 </template>
 </template>
 <script>
 <script>
@@ -182,11 +206,13 @@
     deleteCategory
     deleteCategory
   } from '@/api/classifyManage';
   } from '@/api/classifyManage';
   import { parameterGetByCode } from '@/api/system/dictionary/index.js';
   import { parameterGetByCode } from '@/api/system/dictionary/index.js';
+  import importDialog from '@/components/upload/import-dialogNew.vue';
 
 
   export default {
   export default {
     components: {
     components: {
       classifyManageEdit,
       classifyManageEdit,
-      ListEdit
+      ListEdit,
+      importDialog
     },
     },
     mixins: [dictMixins],
     mixins: [dictMixins],
     data() {
     data() {
@@ -246,6 +272,9 @@
       });
       });
     },
     },
     methods: {
     methods: {
+      importProfession() {
+        this.$refs.importDialogRef.open();
+      },
       async reload(isEdit) {
       async reload(isEdit) {
         if (isEdit) {
         if (isEdit) {
           this.getTree().then(() => {
           this.getTree().then(() => {