From b4e00bbca03786c28879900f4d1bbe98f82cc795 Mon Sep 17 00:00:00 2001 From: g7hoo Date: Mon, 15 Aug 2022 10:23:39 +0800 Subject: [PATCH] =?UTF-8?q?update=20=E5=9F=BA=E6=9C=AC=E5=AE=8C=E6=88=90?= =?UTF-8?q?=E4=B8=8A=E4=BC=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../base-dialog/addOrUpdate/index.vue | 30 +++++++++- src/components/base-upload/index.vue | 60 ++++++++++++++++--- .../modules/monitoring/equipmentType.vue | 5 +- 3 files changed, 83 insertions(+), 12 deletions(-) diff --git a/src/components/base-dialog/addOrUpdate/index.vue b/src/components/base-dialog/addOrUpdate/index.vue index 5251e1f..7b4b44e 100644 --- a/src/components/base-dialog/addOrUpdate/index.vue +++ b/src/components/base-dialog/addOrUpdate/index.vue @@ -46,7 +46,7 @@ @@ -137,6 +137,11 @@ export default { return defaultNames[name] } }, + // provide() { + // return { + // _df: this.dataForm + // } + // }, data() { return { COLUMN_PER_ROW, @@ -236,15 +241,26 @@ export default { } // end if (item.rules) }) + /** 计算默认值 */ + function calDefault(type) { + switch (type) { + case 'array': + return [] + // more case... + default: + return '' + } + } /** 检查是否需要额外的组件 */ this.configs.extraComponents && this.configs.extraComponents.forEach(item => { - this.$set(this.dataForm, [item.name], '') + this.$set(this.dataForm, [item.name], calDefault(item.fieldType)) }) /** 单独设置 id */ this.$set(this.dataForm, 'id', null) }) + console.log("mounted: this.dataForm", JSON.stringify(this.dataForm)) }, methods: { @@ -302,6 +318,7 @@ export default { }).then(({ data: res }) => { if (res && res.code === 0) { const dataFormKeys = Object.keys(this.dataForm) + console.log('data form keys: ', dataFormKeys, pick(res.data, dataFormKeys)) this.dataForm = pick(res.data, dataFormKeys) } }) @@ -310,9 +327,12 @@ export default { if (this.shouldWait) this.shouldWait.then(() => { if (this.tempForm.length) { + console.log("create new, tempform", JSON.stringify(this.tempForm.length)) this.tempForm.forEach(item => { + console.log('item data', item.data) this.dataForm[item.name] = item.data }) + console.log("create new, dataform", JSON.stringify(this.dataForm)) } }) } @@ -381,6 +401,12 @@ export default { } }, + handleUploadListUpdate(filelist) { + // 此处需要参照‘设备类型’新增的接口,灵活地设置 dataForm + this.$set(this.dataForm, 'fileIds', filelist.map(item => item.id)) + console.log('handleUploadListUpdate(): ', this.dataForm) + }, + handleClose() { this.$emit('destory-dialog') this.visible = false diff --git a/src/components/base-upload/index.vue b/src/components/base-upload/index.vue index 427f0f5..1a20e51 100644 --- a/src/components/base-upload/index.vue +++ b/src/components/base-upload/index.vue @@ -9,6 +9,8 @@ diff --git a/src/views/modules/monitoring/equipmentType.vue b/src/views/modules/monitoring/equipmentType.vue index a35045c..d24c968 100644 --- a/src/views/modules/monitoring/equipmentType.vue +++ b/src/views/modules/monitoring/equipmentType.vue @@ -81,12 +81,13 @@ const addOrUpdateConfigs = { ], extraComponents: [ { - name: 'file-upload-key', + name: 'files', + fieldType: 'array', label: '上传资料', component: () => import('@/components/base-upload'), props: { // 上传组件需要的 props url: "/monitoring/attachment/uploadFileFormData", - extraParams: { typeCode: 123 }, + extraParams: { typeCode: "EquipmentTypeFile" }, buttonContent: '点击上传', tip: '上传文件大小不要超过 2mb (2048kb)' }