From ac3ad638949e4d560ddf69320a5f9bb28ca5aaca Mon Sep 17 00:00:00 2001
From: ahaos <8406649+lhailgl@user.noreply.gitee.com>
Date: 星期三, 19 七月 2023 22:48:30 +0800
Subject: [PATCH] !29 修改列表打开对话框和接口请求顺序 Merge pull request !29 from ahaos/tspr

---
 src/views/system/user/index.vue |   46 +++++++++++++++++++++-------------------------
 1 files changed, 21 insertions(+), 25 deletions(-)

diff --git a/src/views/system/user/index.vue b/src/views/system/user/index.vue
index 8e3bcfa..f8aa2e8 100644
--- a/src/views/system/user/index.vue
+++ b/src/views/system/user/index.vue
@@ -154,7 +154,7 @@
     </el-row>
 
     <!-- 娣诲姞鎴栦慨鏀圭敤鎴烽厤缃璇濇 -->
-    <el-dialog :title="dialog.title" v-model="dialog.visible" width="600px" append-to-body @close="closeDialog">
+    <el-dialog ref="formDialogRef" :title="dialog.title" v-model="dialog.visible" width="600px" append-to-body @close="closeDialog">
       <el-form :model="form" :rules="rules" ref="userFormRef" label-width="80px">
         <el-row>
           <el-col :span="12">
@@ -354,6 +354,7 @@
 const queryFormRef = ref<ElFormInstance>();
 const userFormRef = ref<ElFormInstance>();
 const uploadRef = ref<ElUploadInstance>();
+const formDialogRef = ref<ElDialogInstance>();
 
 const dialog = reactive<DialogOption>({
   visible: false,
@@ -547,40 +548,35 @@
 }
 /** 鍙栨秷鎸夐挳 */
 const cancel = () => {
-  reset();
   dialog.visible = false;
+  reset();
 }
 
 /** 鏂板鎸夐挳鎿嶄綔 */
-const handleAdd = () => {
+const handleAdd = async () => {
+  reset();
+  const { data } = await api.getUser();
   dialog.visible = true;
   dialog.title = "鏂板鐢ㄦ埛";
-  nextTick(async () => {
-    reset();
-    await initTreeData();
-    const { data } = await api.getUser();
-    postOptions.value = data.posts;
-    roleOptions.value = data.roles;
-    form.value.password = initPassword.value;
-  })
+  await initTreeData();
+  postOptions.value = data.posts;
+  roleOptions.value = data.roles;
+  form.value.password = initPassword.value;
 }
 /** 淇敼鎸夐挳鎿嶄綔 */
-const handleUpdate = (row?: UserForm) => {
+const handleUpdate = async (row?: UserForm) => {
+  reset();
+  const userId = row?.userId || ids.value[0]
+  const { data } = await api.getUser(userId)
   dialog.visible = true;
   dialog.title = "淇敼鐢ㄦ埛";
-  nextTick(async () => {
-    reset();
-    await initTreeData();
-    const userId = row?.userId || ids.value[0]
-    const { data } = await api.getUser(userId)
-    Object.assign(form.value, data.user);
-    postOptions.value = data.posts;
-    roleOptions.value = data.roles;
-    form.value.postIds = data.postIds;
-    form.value.roleIds = data.roleIds;
-    form.value.password = "";
-  })
-
+  await initTreeData();
+  Object.assign(form.value, data.user);
+  postOptions.value = data.posts;
+  roleOptions.value = data.roles;
+  form.value.postIds = data.postIds;
+  form.value.roleIds = data.roleIds;
+  form.value.password = "";
 }
 
 /** 鎻愪氦鎸夐挳 */

--
Gitblit v1.9.3