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