Procházet zdrojové kódy

refactor(equipemt): 调整组织树形选择器逻辑

Zimo před 5 dny
rodič
revize
f27ab9f66c

+ 8 - 16
src/components/DeptTreeSelect/index.vue

@@ -75,22 +75,17 @@ const loadDeptData = async () => {
 const loadTree = async () => {
   try {
     const { depts, currentId } = await loadDeptData()
-    if (
-      props.initSelect &&
-      props.modelValue &&
-      currentId !== undefined &&
-      !depts.some((item) => item.id === props.modelValue)
-    ) {
+    const targetKey = props.modelValue ?? (props.initSelect ? currentId : null)
+    if (props.initSelect && props.modelValue) {
       emits('update:modelValue', currentId)
     }
+    if (targetKey && !expandedKeys.value.includes(targetKey)) {
+      expandedKeys.value = [...expandedKeys.value, targetKey]
+    }
     deptList.value = sortTreeBySort(handleTree(depts))
     nextTick(() => {
-      const targetKey = props.modelValue ?? (props.initSelect ? currentId : null)
       if (targetKey && treeRef.value) {
         treeRef.value.setCurrentKey(targetKey)
-        if (!expandedKeys.value.includes(targetKey)) expandedKeys.value.push(targetKey)
-        else if (deptList.value.length > 0)
-          expandedKeys.value = deptList.value.map((item) => item.id)
       }
     })
   } catch (e) {
@@ -125,8 +120,7 @@ onMounted(loadTree)
 <template>
   <div
     class="dept-aside-container relative bg-white dark:bg-[#1d1e1f] shadow rounded-lg transition-all duration-300 ease-in-out overflow-visible"
-    :class="[isCollapsed ? 'is-collapsed' : 'p-4']"
-  >
+    :class="[isCollapsed ? 'is-collapsed' : 'p-4']">
     <div v-show="!isCollapsed" class="h-full flex flex-col gap-4 overflow-hidden w-full">
       <h1 v-if="showTitle" class="text-lg font-medium truncate shrink-0">{{ props.title }}</h1>
 
@@ -136,8 +130,7 @@ onMounted(loadTree)
           placeholder="请输入部门名称"
           clearable
           size="default"
-          :prefix-icon="Search"
-        />
+          :prefix-icon="Search" />
       </div>
 
       <div class="flex-1 relative overflow-hidden">
@@ -153,8 +146,7 @@ onMounted(loadTree)
                 node-key="id"
                 highlight-current
                 :default-expanded-keys="expandedKeys"
-                @node-click="handleNodeClick"
-              />
+                @node-click="handleNodeClick" />
             </el-scrollbar>
           </template>
         </el-auto-resizer>

+ 1 - 1
src/views/pms/iotrydailyreport/equipment.vue

@@ -35,7 +35,7 @@ const formVisible = ref(false)
 const total = ref(0)
 
 const query = ref<Query>({
-  deptId: deptId,
+  deptId: undefined,
   pageNo: 1,
   pageSize: 10,
   createTime: undefined