From 2f91380a79d21e351ae4096b5b5835f6e71f3ad0 Mon Sep 17 00:00:00 2001 From: lyh <925863403@qq.com> Date: 星期五, 17 一月 2025 17:20:39 +0800 Subject: [PATCH] DNC工作台 已办 --- src/views/dnc/common/ImportFileModal.vue | 134 +++++++++++++++++++++++++++++++++----------- 1 files changed, 99 insertions(+), 35 deletions(-) diff --git a/src/views/dnc/common/ImportFileModal.vue b/src/views/dnc/common/ImportFileModal.vue index 3ed0cb5..6dd4ce0 100644 --- a/src/views/dnc/common/ImportFileModal.vue +++ b/src/views/dnc/common/ImportFileModal.vue @@ -1,7 +1,7 @@ <template> <a-modal :title="title" :visible="visible" @cancel="handleModalClose" :maskClosable="false"> <a-upload :multiple="true" :file-list="fileList" :remove="handleRemove" :before-upload="beforeUpload"> - <a-button type="primary"> + <a-button type="primary" :disabled="uploading"> <a-icon type="import"/> 閫夊彇鏂囦欢 </a-button> @@ -26,6 +26,8 @@ </template> <script> + import dncApi from '@/api/dnc' + export default { name: 'ImportFileModal', components: {}, @@ -34,15 +36,48 @@ visible: false, title: '', fileList: [], - uploading: false + uploadParams: {}, + uploading: false, + isUploadMultiple: true } }, created() { this.$bus.$on('treeMenuItemMethodTrigger', this.triggerCorrespondingMethod) + this.$bus.$on('tableMenuItemMethodTrigger', this.triggerCorrespondingMethod) }, methods: { - handleImport(modalTitle) { - this.handleModalOpen(modalTitle) + /** + * 鐐瑰嚮瀵煎叆鏂囨。鎴朜C绋嬪簭鏃惰Е鍙� + * @param treeNodeInfo 鐐瑰嚮鏍戣妭鐐瑰彸閿彍鍗曞鍏ョ▼搴忔椂浼犲叆鏍戣妭鐐逛俊鎭� + * @param tableRowInfo 鐐瑰嚮琛ㄦ牸琛屽彸閿彍鍗曞鍏ョ▼搴忔椂浼犲叆琛屼俊鎭� + */ + handleImport(treeNodeInfo, tableRowInfo) { + this.isUploadMultiple = true + let attributionId // 鏂囨。鎵�灞炲眰绾d + let attributionType // 鏂囨。鎵�灞炲眰绾х被鍨� + let docClassCode // 鏂囨。绫诲瀷 + if (treeNodeInfo) { + attributionId = treeNodeInfo.treeKey + attributionType = treeNodeInfo.type + } else { + attributionId = tableRowInfo.attributionId + attributionType = tableRowInfo.attributionType + } + if (attributionType === 5 || attributionType === 6) docClassCode = 'NC' + else docClassCode = 'OTHER' + this.uploadParams = Object.assign({}, { attributionId, attributionType, docClassCode }) + this.visible = true + }, + + handlePush(_, tableRowInfo) { + this.isUploadMultiple = false + console.log('tableRowInfo', tableRowInfo) + this.uploadParams = Object.assign({}, { + id: tableRowInfo.docId, + attributionId: tableRowInfo.attributionId, + docClassCode: tableRowInfo.param + }) + this.visible = true }, handleRemove(file) { @@ -53,43 +88,69 @@ }, beforeUpload(file) { - this.fileList = [...this.fileList, file] + if (this.isUploadMultiple) { + if (!this.fileList.find(item => item.name === file.name)) this.fileList = [...this.fileList, file] + } else { + this.fileList.splice(0, 1, file) + } return false }, handleUpload() { - const { fileList } = this - const formData = new FormData() - fileList.forEach(file => { - formData.append('files[]', file) - }) + const { fileList, $notification, isUploadMultiple, uploadParams, $bus } = this this.uploading = true + let uploadedFileCount = 0 + let uploadSuccessFileCount = 0 + let apiMethod + let params - // You can use any AJAX library you like - request({ - url: 'https://www.mocky.io/v2/5cc8019d300000980a055e76', - method: 'post', - processData: false, - data: formData, - success: () => { - this.fileList = [] - this.uploading = false - this.$message.success('upload successfully.') - }, - error: () => { - this.uploading = false - this.$message.error('upload failed.') + fileList.forEach((file, index) => { + const formData = new FormData() + formData.append('file', file) + file.status = 'uploading' + // 鐩墠鏍规嵁鏄惁涓婁紶澶氫釜鏂囦欢鍒ゆ柇涓や釜鍔熻兘锛岃嫢鍚庣画澧炲姞鍔熻兘鎴栬皟鏁撮渶姹傚垯璋冩暣鍒ゆ柇鏉′欢 + if (isUploadMultiple) { + apiMethod = dncApi.importDocumentFromLocalApi + params = Object.assign({}, { params: uploadParams, formData }) + } else { + apiMethod = dncApi.documentVersionUpdateApi + params = Object.assign({}, { id: uploadParams.id, formData }) } + apiMethod(params) + .then(res => { + if (res.success) { + file.status = 'done' + uploadSuccessFileCount++ + console.log('uploadSuccessFileCount++', uploadSuccessFileCount) + $notification.success({ + message: '娑堟伅', + description: res.message + }) + } else { + file.status = 'error' + $notification.error({ + message: '娑堟伅', + description: res.message + }) + } + }) + .catch(err => { + file.status = 'error' + }) + .finally(() => { + uploadedFileCount++ + fileList.splice(index, 1, file) + // 褰撴枃浠跺叏閮ㄤ笂浼犲畬鎴愬悗 + if (uploadedFileCount === fileList.length) { + // 鑷冲皯鏈変竴涓枃浠朵笂浼犳垚鍔熷悗灏遍渶瑕侀噸鏂板姞杞芥枃妗e垪琛� + if (uploadSuccessFileCount > 0) { + $bus.$emit('importFileSuccess', uploadParams) + if (!isUploadMultiple) this.visible = false //鏃犳硶杩炵画鍏ュ簱澶氫釜鐗堟湰鍥犳鍏ュ簱鎴愬姛鍚庡嵆鍙��鍑虹獥鍙� + } + this.uploading = false + } + }) }) - }, - - /** - * 鎺у埗鏂囦欢涓婁紶绐楀彛寮�鍚苟璁剧疆绐楀彛鏍囬 - * @param modalTitle 绐楀彛鏍囬 - */ - handleModalOpen(modalTitle) { - this.title = modalTitle - this.visible = true }, /** @@ -100,8 +161,11 @@ this.fileList = [] }, - triggerCorrespondingMethod({ methodName, modalTitle }) { - if (this[methodName]) this[methodName](modalTitle) + triggerCorrespondingMethod({ methodName, modalTitle, treeNodeInfo, tableRowInfo }) { + if (this[methodName]) { + this[methodName](treeNodeInfo, tableRowInfo) + this.title = modalTitle + } } } } -- Gitblit v1.9.3