From 8ad162aab62e6b94a79f5bb3b5783a17226ef33f Mon Sep 17 00:00:00 2001 From: g7hoo Date: Tue, 16 Aug 2022 15:49:51 +0800 Subject: [PATCH] =?UTF-8?q?update=20dialog:=20=E5=A4=9A=E4=B8=8A=E4=BC=A0?= =?UTF-8?q?=E7=BB=84=E4=BB=B6=E4=B8=8A=E4=BC=A0=E3=80=81=E4=B8=8B=E8=BD=BD?= =?UTF-8?q?=E5=92=8C=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../base-dialog/addOrUpdate/index.vue | 35 +++++++++++++++++-- src/views/modules/monitoring/equipment.vue | 18 +++++----- 2 files changed, 41 insertions(+), 12 deletions(-) diff --git a/src/components/base-dialog/addOrUpdate/index.vue b/src/components/base-dialog/addOrUpdate/index.vue index 9e7cbde..40069b3 100644 --- a/src/components/base-dialog/addOrUpdate/index.vue +++ b/src/components/base-dialog/addOrUpdate/index.vue @@ -53,7 +53,7 @@ :is="ec.component" v-bind="ec.props" @uploader-update-filelist="handleUploadListUpdate($event, ec.props.extraParams.typeCode)" - :uploader-inject-file-list="dataForm.files" + :uploader-inject-file-list="/*用于设备分流的*/ fileList[ec.props.extraParams.typeCode]" /> @@ -174,7 +174,8 @@ export default { dataFormRules: {}, tempForm: [], // 临时保存自动生成的code,或其他数据 shouldWait: null, - fileForm: {} // 文件上传分流用、合并用的表单,根据 typeCode 进行分流,在请求时合并 + fileForm: {}, // 文件上传分流用、合并用的表单,根据 typeCode 进行分流,在请求时合并 + fileList: {} // 文件加载时分流,依据 typeCode } }, computed: { @@ -342,6 +343,33 @@ export default { const dataFormKeys = Object.keys(this.dataForm) console.log('data form keys: ', dataFormKeys, pick(res.data, dataFormKeys)) this.dataForm = pick(res.data, dataFormKeys) + + // LABEL: FILE_RELATED + /** 对文件下载进行分流 */ + this.fileList = {} + if (this.dataForm.files) { + console.log('files: ', this.dataForm.files) + this.dataForm.files.forEach(file => { + // const fileName = file.fileUrl.split('/').pop() + /** [1] 处理 fileList */ + if (Object.hasOwn(this.fileList, file.typeCode)) { + /** 已存在 */ + // this.fileList[file.typeCode].push({ id: file.id, name: fileName, typeCode: file.typeCode }) + this.fileList[file.typeCode].push(file) + } else { + // this.fileList[file.typeCode] = [{ id: file.id, name: fileName, typeCode: file.typeCode }] + this.fileList[file.typeCode] = [file] + } + + /** [2] 处理 fileForm */ + if (Object.hasOwn(this.fileForm, file.typeCode)) { + this.fileForm[file.typeCode].push(file.id) + } else { + this.fileForm[file.typeCode] = [file.id] + } + }) + console.log('after分流:', this.fileList) + } } }) } else { @@ -446,6 +474,7 @@ export default { // LABEL: FILE_RELATED handleUploadListUpdate(filelist, typeCode = 'DefaultTypeCode') { + console.log('before handleUploadListUpdate(): ', JSON.parse(JSON.stringify(this.fileForm))) // 设备类型 typeCode: EquipmentTypeFile // 设备信息 typeCode: EquipmentInfoFile | EquipmentInfoImage @@ -462,7 +491,7 @@ export default { typeCode, filelist.map(item => item.id) ) - console.log('handleUploadListUpdate(): ', this.fileForm) + console.log('after handleUploadListUpdate(): ', this.fileForm) }, handleClose() { diff --git a/src/views/modules/monitoring/equipment.vue b/src/views/modules/monitoring/equipment.vue index 58db293..3920699 100644 --- a/src/views/modules/monitoring/equipment.vue +++ b/src/views/modules/monitoring/equipment.vue @@ -266,16 +266,16 @@ export default { }, // 新增 / 修改 addOrUpdateHandle(id) { - // this.addOrUpdateVisible = true - // this.$nextTick(() => { - // this.$refs.addOrUpdate.init(id) - // }) - this.$router.push({ - name: 'monitoring-equipmentAdd', - params: { - equipmentId: id - } + this.addOrUpdateVisible = true + this.$nextTick(() => { + this.$refs.addOrUpdate.init(id) }) + // this.$router.push({ + // name: 'monitoring-equipmentAdd', + // params: { + // equipmentId: id + // } + // }) }, // 删除 deleteHandle(id) {