From cfec6ff3f524bee1e0e3b85a7b6be07d3c3a2fbc Mon Sep 17 00:00:00 2001 From: g7hoo Date: Tue, 9 Aug 2022 16:45:16 +0800 Subject: [PATCH] =?UTF-8?q?finish=20=E5=9F=BA=E6=9C=AC=E5=AE=8C=E6=88=90di?= =?UTF-8?q?alog=E2=80=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../base-dialog/addOrUpdate/index.vue | 82 ++++++++++++++----- src/views/modules/monitoring/product.vue | 2 +- 2 files changed, 64 insertions(+), 20 deletions(-) diff --git a/src/components/base-dialog/addOrUpdate/index.vue b/src/components/base-dialog/addOrUpdate/index.vue index 289d6d4..ff1df4b 100644 --- a/src/components/base-dialog/addOrUpdate/index.vue +++ b/src/components/base-dialog/addOrUpdate/index.vue @@ -15,14 +15,22 @@ v-if="getType(n, c) === 'input'" :placeholder="configs.fields[(n - 1) * COLUMN_PER_ROW + (c - 1)].placeholder || '...'" v-model="dataForm[configs.fields[(n - 1) * COLUMN_PER_ROW + (c - 1)].name]" + clearable /> - - - - - - - + + + + + + + + + @@ -145,10 +153,10 @@ export default { /** 自动请求并填充 */ this.$http({ url: this.$http.adornUrl(item.api), - methods: 'get' + method: 'POST' // 也可以改成动态决定 }).then(({ data: res }) => { - if (data & (data.code === 0)) { - this.dataFrom[item.name] = res.data // <=== 此处需要对接口 + if (res && res.code === 0) { + this.dataForm[item.name] = res.data // <=== 此处需要对接口 } }) } // end if (item.api) @@ -241,15 +249,51 @@ export default { this.visible = true }, handleClick(btn) { - switch (btn.name) { - case 'save': - break - case 'update': - break - case 'reset': - break - // add more.. - } + this.$refs['dataForm'].validate(valid => { + if (valid) { + /** 提取url */ + const urls = {} + this.configs.operations.map(item => { + urls[item.name] = item.url + }) + /** 操作 */ + switch (btn.name) { + case 'save': + case 'update': + this.$http({ + url: this.$http.adornUrl(urls[btn.name]), + method: btn.name === 'save' ? 'POST' : 'PUT', + data: this.dataForm + }).then(({ data: res }) => { + if (data && data.code === 0) { + this.$message({ + message: btn.name === 'save' ? '添加成功!' : '更新成功!', + type: 'success', + duration: 1500, + onClose() { + this.$emit('refreshDataList') + this.visible = false + } + }) + } + }) + return + case 'reset': + for (const key of Object.keys(this.dataForm)) { + if (typeof this.dataForm[key] === 'string') { + this.dataForm[key] = '' + } else if (this.dataForm[key] instanceof Array) { + this.dataForm[key].splice(0) + } else { + this.dataForm[key] = null + } + } + console.log('after reset: ', JSON.stringify(this.dataForm)) + break + // add more.. + } + } + }) }, handleClose() { if (this.isAdd || this.isUpdated) this.$emit('refreshDataList') diff --git a/src/views/modules/monitoring/product.vue b/src/views/modules/monitoring/product.vue index 2ede590..5e7fb39 100644 --- a/src/views/modules/monitoring/product.vue +++ b/src/views/modules/monitoring/product.vue @@ -100,7 +100,7 @@ const addOrUpdateConfigs = { 'name', { name: 'code', - api: 'xx/code' + api: '/monitoring/product/getCode' }, { name: 'processTime',