Ver Fonte

修改弹窗打开与数据获取加载顺序

lichunyang há 4 semanas atrás
pai
commit
a4292b0905
1 ficheiros alterados com 30 adições e 16 exclusões
  1. 30 16
      src/components/PersonUnitDialog.vue

+ 30 - 16
src/components/PersonUnitDialog.vue

@@ -5,6 +5,7 @@
     @update:model-value="$emit('update:visible', $event)"
     class="dialog_class"
     draggable
+    @open="handleDialogOpen"
   >
     <template #header="{ titleId, titleClass }">
       <div class="my-header">
@@ -465,24 +466,37 @@ const handleConfirm = () => {
   emit("update:visible", false)
 }
 
+const handleDialogOpen = async () => {
+  loading.value = true
+  try {
+    const groups = await fetchUnitGroups()
+    unitGroups.value = groups
+    if (groups.length > 0) {
+      await fetchUnitTableData(selectedGroupId.value)
+    }
+  } finally {
+    loading.value = false
+  }
+}
+
 // 初始化数据
-watch(
-  () => props.visible,
-  async (newVisible) => {
-    if (newVisible) {
-      loading.value = true
-      const groups = await fetchUnitGroups()
-      unitGroups.value = groups
-      if (groups.length > 0) {
+// watch(
+//   () => props.visible,
+//   async (newVisible) => {
+//     if (newVisible) {
+//       loading.value = true
+//       const groups = await fetchUnitGroups()
+//       unitGroups.value = groups
+//       if (groups.length > 0) {
         
-        await fetchUnitTableData(selectedGroupId.value)
-      } else {
-        loading.value = false
-      }
-    }
-  },
-  { immediate: true }
-)
+//         await fetchUnitTableData(selectedGroupId.value)
+//       } else {
+//         loading.value = false
+//       }
+//     }
+//   },
+//   // { immediate: true }
+// )
 
 // 监听选中的单位系统变化
 watch(