From d49f735e0ef0c32b737077f4990d0679044abbc1 Mon Sep 17 00:00:00 2001 From: sangchengzhi <2305486879@qq.com> Date: Wed, 14 Jan 2026 18:05:43 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9info=E9=A1=B5id=E6=95=B0?= =?UTF-8?q?=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/views/system/info/index.vue | 51 +++++++++++++++++++++++---------- 1 file changed, 36 insertions(+), 15 deletions(-) diff --git a/src/views/system/info/index.vue b/src/views/system/info/index.vue index 039d27f..95f1c47 100644 --- a/src/views/system/info/index.vue +++ b/src/views/system/info/index.vue @@ -76,6 +76,10 @@ + + + + @@ -121,6 +125,8 @@ export default { title: "", // 是否显示弹出层 open: false, + // 用于修改操作的id + currentId: null, // 查询参数 queryParams: { pageNo: 1, @@ -159,11 +165,11 @@ export default { cancel() { this.open = false; this.reset(); + this.currentId = null; // 重置currentId }, /** 表单重置 */ reset() { this.form = { - id: undefined, remark: undefined, role: undefined, }; @@ -188,32 +194,47 @@ export default { /** 修改按钮操作 */ handleUpdate(row) { this.reset(); - const id = row.id; - getInfo(id).then(response => { - this.form = response.data; + this.currentId = row.id; + console.log('点击修改时的row.id:', this.currentId); + getInfo(this.currentId).then(response => { + console.log('API返回的数据:', response.data); + // 确保form对象包含所有必要字段 + this.form = { + remark: '', + role: undefined, + ...response.data + }; this.open = true; this.title = "修改用户信息"; }); }, /** 提交按钮 */ submitForm() { + // 先进行表单验证 this.$refs["form"].validate(valid => { if (!valid) { return; } - // 修改的提交 - if (this.form.id != null) { - updateInfo(this.form).then(response => { - this.$modal.msgSuccess("修改成功"); - this.open = false; - this.getList(); - }); - return; + + // 判断是新增还是修改操作 + const isUpdate = !!this.currentId; + + // 准备提交数据 + const submitData = { ...this.form }; + + // 如果是修改操作,确保id存在且是数字类型 + if (isUpdate) { + // 使用currentId而不是form.id,并确保是数字类型 + submitData.id = parseInt(this.currentId); } - // 添加的提交 - createInfo(this.form).then(response => { - this.$modal.msgSuccess("新增成功"); + + // 执行请求 + const requestPromise = isUpdate ? updateInfo(submitData) : createInfo(submitData); + + requestPromise.then(response => { + this.$modal.msgSuccess(isUpdate ? "修改成功" : "新增成功"); this.open = false; + this.currentId = null; // 重置currentId this.getList(); }); });