From f636670bf69719d7d5bd3157e27eb84ab564d105 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E9=99=8C?= Date: Mon, 11 Sep 2023 21:37:28 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0xUpdate?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/xUpdate/index.vue | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/src/components/xUpdate/index.vue b/src/components/xUpdate/index.vue index 13df1de..8724a69 100644 --- a/src/components/xUpdate/index.vue +++ b/src/components/xUpdate/index.vue @@ -47,6 +47,7 @@ labelPosition : "right", labelWidth : "120px", size : "medium", + submitinfokey : "info", url:'', merge:false, // 远程数据时, 是否合并data submitname:'保存' @@ -83,6 +84,8 @@ }, // 表单提交方法 submit(){ + + this.$refs.formref.validate(async (valid) => { if (valid) { if (!this.config.url) { @@ -90,8 +93,22 @@ this.$alert('没有'+ ((this.config.name || this.titleMap[this.mode]) || '编辑') +'数据相关配置', "提示", {type: 'error'}); return; } + + + const data = { + [this.config.submitinfokey || 'info']: this.data, + }; + + if (this.key && typeof this.data[this.key] !== 'undefined') { + Object.assign(data,{[this.key]: this.data[this.key]}); + } + + if (this.token) { + Object.assign(data,{token: this.token}); + } + this.isSaveing = true; - this.$http.post(this.config.url, {token:this.token, info:this.data}).then((res) => { + this.$http.post(this.config.url, data).then((res) => { this.isSaveing = false; if (res.code == 200 ) { this.visible = false; @@ -150,11 +167,6 @@ // 表单注入数据 setData(data){ this.data = data; - - if (this.key == 'token' && typeof this.data[this.key] !== 'undefined') { - this.token = this.data[this.key]; - } - return this; }, }