fix(components): 修复部门选择组件非树结构,默认展开失败问题

This commit is contained in:
AN 2025-06-10 20:33:11 +08:00
parent aeb736ebf1
commit da1c16e023
2 changed files with 12 additions and 8 deletions

View File

@ -2,7 +2,7 @@
import { useAttrs } from 'vue';
import type { TreeSelectProps } from 'naive-ui';
import { useLoading } from '@sa/hooks';
import { fetchGetDeptSelect } from '@/service/api/system';
import { fetchGetDeptTree } from '@/service/api/system';
defineOptions({ name: 'DeptTreeSelect' });
@ -13,16 +13,21 @@ interface Props {
defineProps<Props>();
const value = defineModel<CommonType.IdType | null>('value', { required: false });
const options = defineModel<Api.System.Dept[]>('options', { required: false, default: [] });
const options = defineModel<Api.Common.CommonTreeRecord>('options', { required: false, default: [] });
const expandedKeys = defineModel<CommonType.IdType[]>('expandedKeys', { required: false, default: [] });
const attrs: TreeSelectProps = useAttrs();
const { loading, startLoading, endLoading } = useLoading();
async function getDeptList() {
startLoading();
const { error, data } = await fetchGetDeptSelect();
const { error, data } = await fetchGetDeptTree();
if (error) return;
options.value = data;
//
if (data?.length && !expandedKeys.value.length) {
expandedKeys.value = [data[0].id];
}
endLoading();
}
@ -32,13 +37,13 @@ getDeptList();
<template>
<NTreeSelect
v-model:value="value"
v-model:expanded-keys="expandedKeys"
filterable
class="h-full"
:loading="loading"
key-field="deptId"
label-field="deptName"
:options="options"
:default-expanded-keys="[0]"
key-field="id"
label-field="label"
:options="options as []"
v-bind="attrs"
/>
</template>

View File

@ -149,7 +149,6 @@ defineExpose({
<NCheckbox v-model:checked="cascade" :checked-value="true" :unchecked-value="false">父子联动</NCheckbox>
</div>
<NSpin class="resource h-full w-full py-6px pl-3px" content-class="h-full" :show="loading">
{{ checkedKeys }}
<NTree
ref="menuTreeRef"
v-model:checked-keys="checkedKeys"