From 866b57fb42d62659876621da6b63c076c842f318 Mon Sep 17 00:00:00 2001 From: maochaoying <925670706@qq.com> Date: Fri, 25 Aug 2023 18:06:36 +0800 Subject: [PATCH] =?UTF-8?q?=E7=94=A8=E6=88=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/User.vue | 75 +++++++++++++++++++++++++++++++++++++------------ 1 file changed, 57 insertions(+), 18 deletions(-) diff --git a/src/components/User.vue b/src/components/User.vue index 7c63e39..abd7cec 100644 --- a/src/components/User.vue +++ b/src/components/User.vue @@ -10,7 +10,7 @@ @@ -55,7 +56,11 @@ 提交 - 重置 @@ -87,6 +92,7 @@ const INITIAL_DATA = { export default { data() { return { + operType: 1, formData: { ...INITIAL_DATA }, rules: { username: [ @@ -147,13 +153,23 @@ export default { cell: (h, { row }) => { if (row.username != 'admin') { return ( -
- this.delUser(row.username)} - > - 删除 - +
+
+ this.delUser(row.username)} + > + 删除 + +
+
+ this.updateUser(row)} + > + 修改 + +
) } @@ -162,8 +178,26 @@ export default { ], } }, - methods: { + addUser() { + this.operType = 1 + this.formData = { + username: '', + role: '', + password: '', + } + this.visible = true + }, + updateUser(row) { + console.log(row) + this.formData = { + username: row.username, + role: row.role, + password: '', + } + this.operType = 2 + this.visible = true + }, handleClose() { this.formData = { ...INITIAL_DATA } this.visible = false @@ -197,14 +231,19 @@ export default { async onSubmit({ validateResult, firstError }) { if (validateResult === true) { // 新增用户 - const res = await addUserApi(this.formData) - if (res?.code == 200) { - this.formData = { ...INITIAL_DATA } - this.visible = false - this.$message.success('提交成功') - this.getUserList() + if (this.operType == 1) { + const res = await addUserApi(this.formData) + if (res?.code == 200) { + this.formData = { ...INITIAL_DATA } + this.visible = false + this.$message.success('提交成功') + this.getUserList() + } else { + this.$message.error(res.msg) + } } else { - this.$message.error(res.msg) + // 更新用户 + console.log(123) } } else { this.$message.warning(firstError)