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',