feat: 用户管理调整部门使用树形选择器

This commit is contained in:
Your Name 2026-01-07 10:50:37 +08:00
parent eab4b6ba2a
commit 1c4e042c4b

View File

@ -1695,20 +1695,18 @@
</p> </p>
<a-form layout="vertical"> <a-form layout="vertical">
<a-form-item label="选择部门"> <a-form-item label="选择部门">
<a-select <a-tree-select
v-model:value="transferDeptId" v-model:value="transferDeptId"
placeholder="请选择部门" placeholder="请选择部门"
style="width: 100%" style="width: 100%"
> :tree-data="departmentTreeSelectData"
<a-select-option :value="0">未分配部门</a-select-option> :field-names="{ children: 'children', label: 'title', value: 'value' }"
<a-select-option tree-default-expand-all
v-for="dept in departments" allow-clear
:key="dept.id" show-search
:value="dept.id" :filter-tree-node="filterDeptTreeNode"
> tree-node-filter-prop="title"
{{ dept.deptName }} />
</a-select-option>
</a-select>
</a-form-item> </a-form-item>
</a-form> </a-form>
</div> </div>
@ -2499,6 +2497,38 @@ const getDepartmentLevel = (record: DepartmentOverview): number => {
return 3 return 3
} }
// 部门树形选择器数据 - 用于调整用户部门
const departmentTreeSelectData = computed(() => {
// 构建树形结构
const buildTree = (parentId: number | null): any[] => {
return departments.value
.filter(d => (d.parentId || null) === parentId)
.map(d => {
const children = buildTree(d.id!)
const node: any = {
title: `${d.deptName} (${d.deptType === 'demand' ? '需求' : '接单'})`,
value: d.id,
key: d.id
}
if (children.length > 0) {
node.children = children
}
return node
})
}
// 添加"未分配部门"选项
return [
{ title: '未分配部门', value: 0, key: 0 },
...buildTree(null)
]
})
// 过滤部门树节点
const filterDeptTreeNode = (inputValue: string, treeNode: any) => {
return treeNode.title.toLowerCase().includes(inputValue.toLowerCase())
}
// 上级部门选项(分层级)- 用于部门编辑弹窗 // 上级部门选项(分层级)- 用于部门编辑弹窗
const parentDepartmentOptions = computed(() => { const parentDepartmentOptions = computed(() => {
// 排除当前正在编辑的部门及其子部门 // 排除当前正在编辑的部门及其子部门