Procházet zdrojové kódy

新增通用文件上传功能

luoaoxuan před 1 rokem
rodič
revize
7c25fa09a8

+ 2 - 2
src/api/upload/zip.js

@@ -5,11 +5,11 @@ import { BUSINESS_BASE_URL } from '@/api/baseUrl'
  * 导入文件
  * 导入文件
  * @param {*} file
  * @param {*} file
  */
  */
-export function importZip (file) {
+export function upload (file, uploadUrl) {
     const data = new FormData() // 创建form对象
     const data = new FormData() // 创建form对象
     data.append('file', file)
     data.append('file', file)
     return request({
     return request({
-        url: BUSINESS_BASE_URL() + '/thirtyparty/humiture/importHumiture',
+        url: BUSINESS_BASE_URL() + uploadUrl,
         method: 'post',
         method: 'post',
         data: data,
         data: data,
         isLoading: true,
         isLoading: true,

+ 34 - 24
src/business/platform/data/templaterender/templates/list.vue

@@ -268,11 +268,13 @@
             @close="(visible) => (importTableDialogVisible = visible)"
             @close="(visible) => (importTableDialogVisible = visible)"
             @action-event="handleImportTableActionEvent"
             @action-event="handleImportTableActionEvent"
         />
         />
-        <import-zip
-            :visible="importZipDialogVisible"
+        <upload-file
+            :visible="uploadFileDialogVisible"
             title="导入"
             title="导入"
-            @close="(visible) => (importZipDialogVisible = visible)"
-            @action-event="handleImportZipActionEvent"
+            :accept="accept"
+            :upload-title="uploadTitle"
+            @close="(visible) => (uploadFileDialogVisible = visible)"
+            @action-event="handleUploadFileActionEvent"
         />
         />
 
 
         <xlsxFile
         <xlsxFile
@@ -328,7 +330,7 @@ import IbpsImportColumnsDialog from '../components/import-columns-dialog'
 import CustomDataDisplayMixin from '@/business/platform/system/mixins/customDataDisplay'
 import CustomDataDisplayMixin from '@/business/platform/system/mixins/customDataDisplay'
 import FormPrintTemplate from '@/business/platform/form/form-print/template'
 import FormPrintTemplate from '@/business/platform/form/form-print/template'
 import importTable from '@/business/platform/form/formrender/dynamic-form/components/import-table'
 import importTable from '@/business/platform/form/formrender/dynamic-form/components/import-table'
-import importZip from '@/business/platform/form/formrender/dynamic-form/components/import-zip.vue'
+import uploadFile from '@/business/platform/form/formrender/dynamic-form/components/import-zip.vue'
 import JTemplate from '../utils/JTemplate' // 自定义脚本
 import JTemplate from '../utils/JTemplate' // 自定义脚本
 import JDialogTemplate from '../utils/JDialogTemplate' // 对话框自定义脚本
 import JDialogTemplate from '../utils/JDialogTemplate' // 对话框自定义脚本
 
 
@@ -341,7 +343,7 @@ import Vue from 'vue'
 Vue.component('ibps-data-template-render-dialog', () => import('@/business/platform/data/templaterender/preview/dialog.vue'))
 Vue.component('ibps-data-template-render-dialog', () => import('@/business/platform/data/templaterender/preview/dialog.vue'))
 import xlsxFile from '@/business/platform/data/templaterender/templates/compenent/xlsxFile.vue'
 import xlsxFile from '@/business/platform/data/templaterender/templates/compenent/xlsxFile.vue'
 import generalModules from '@/views/system/jbdScan/generalModules.vue'
 import generalModules from '@/views/system/jbdScan/generalModules.vue'
-import { importZip as importzip } from '@/api/upload/zip'
+import { upload } from '@/api/upload/zip'
 export default {
 export default {
     name: 'list',
     name: 'list',
     components: {
     components: {
@@ -360,7 +362,7 @@ export default {
         DictionaryFormat,
         DictionaryFormat,
         Scan,
         Scan,
         importTable,
         importTable,
-        importZip,
+        uploadFile,
         Print: () => import('../components/print'),
         Print: () => import('../components/print'),
         LabelPrint: () => import('../components/labelPrint'),
         LabelPrint: () => import('../components/labelPrint'),
         xlsxFile,
         xlsxFile,
@@ -404,6 +406,9 @@ export default {
     data () {
     data () {
         const { first = '', second = '' } = this.$store.getters.level || {}
         const { first = '', second = '' } = this.$store.getters.level || {}
         return {
         return {
+            accept: '',
+            uploadUrl: '',
+            uploadTitle: '',
             first,
             first,
             second,
             second,
             npmDialogFormVisible: false, // 弹窗
             npmDialogFormVisible: false, // 弹窗
@@ -475,7 +480,7 @@ export default {
             printList: [],
             printList: [],
 
 
             importTableDialogVisible: false,
             importTableDialogVisible: false,
-            importZipDialogVisible: false,
+            uploadFileDialogVisible: false,
             position: null,
             position: null,
             importList: [],
             importList: [],
             importValue: null,
             importValue: null,
@@ -1819,19 +1824,24 @@ export default {
             return { [pidKey]: selection }
             return { [pidKey]: selection }
         },
         },
 
 
-        // 自定义导入  小林
-        handleImport (data = [], type = 'excel') {
-            switch (type) {
-                case 'excel':
-                    this.importList = data
-                    this.importValue = this.getKeys(this.importList)
-                    this.importTableDialogVisible = true
-                    break
-                case 'zip':
-                    this.importZipDialogVisible = true
-                    break
-                default:
-                    break
+        /**
+         * 自定义导入 accept文件类型  uploadUrl接口地址 uploadTitle描述文本
+         */
+        handleImport (data = [], option = {}) {
+            const { accept = '', uploadUrl = '', uploadTitle = '请选择导入文件' } = option
+            // 原逻辑
+            if (uploadUrl === '') {
+                this.importList = data
+                this.importValue = this.getKeys(this.importList)
+                this.importTableDialogVisible = true
+            } else {
+                this.uploadFileDialogVisible = true
+                this.accept = accept
+                this.uploadUrl = uploadUrl
+                if (this.uploadUrl[0] !== '/') {
+                    this.uploadUrl = '/' + this.uploadUrl
+                }
+                this.uploadTitle = uploadTitle
             }
             }
         },
         },
         handleImportTableActionEvent (file, options) {
         handleImportTableActionEvent (file, options) {
@@ -1854,10 +1864,10 @@ export default {
                 // ActionUtils.success('导入成功')
                 // ActionUtils.success('导入成功')
             })
             })
         },
         },
-        async handleImportZipActionEvent (file, options) {
+        async handleUploadFileActionEvent (file, options) {
             // 调用上传接口
             // 调用上传接口
-            await importzip(file)
-            this.importZipDialogVisible = false
+            await upload(file, this.uploadUrl)
+            this.uploadFileDialogVisible = false
             this.search()
             this.search()
             ActionUtils.success('导入成功')
             ActionUtils.success('导入成功')
         },
         },

+ 8 - 2
src/business/platform/form/formrender/dynamic-form/components/import-zip.vue

@@ -22,14 +22,14 @@
                 <el-upload
                 <el-upload
                     ref="upload"
                     ref="upload"
                     action="https://www.bpmhome.cn/post"
                     action="https://www.bpmhome.cn/post"
-                    accept=".zip"
+                    :accept="accept"
                     :file-list="fileList"
                     :file-list="fileList"
                     :on-change="handleChange"
                     :on-change="handleChange"
                     :before-upload="handleUpload"
                     :before-upload="handleUpload"
                     :auto-upload="false"
                     :auto-upload="false"
                 >
                 >
                     <el-button type="primary" icon="el-icon-upload">选择文件</el-button>
                     <el-button type="primary" icon="el-icon-upload">选择文件</el-button>
-                    <div slot="tip" class="el-upload__tip"> 请导入Zip文件</div>
+                    <div slot="tip" class="el-upload__tip"> {{ uploadTitle }}</div>
                 </el-upload>
                 </el-upload>
             </el-form-item>
             </el-form-item>
             <!-- <el-form-item label="格式数据:">
             <!-- <el-form-item label="格式数据:">
@@ -54,6 +54,12 @@ import ActionUtils from '@/utils/action'
 
 
 export default {
 export default {
     props: {
     props: {
+        uploadTitle: {
+            type: String
+        },
+        accept: {
+            type: String
+        },
         visible: {
         visible: {
             type: Boolean,
             type: Boolean,
             default: false
             default: false