fix: 多个同级部门时显示父部门名称

This commit is contained in:
Your Name 2026-01-06 20:58:12 +08:00
parent 2084dfe1fc
commit 412114271e

View File

@ -1133,21 +1133,34 @@ const getDeptNameFromIds = (deptIds: string): string => {
const ids = deptIds.split(',').map(id => parseInt(id.trim())).filter(id => !isNaN(id))
if (ids.length === 0) return '所有部门'
// 从部门列表中查找名称
const deptNames = ids.map(id => {
const dept = departmentList.value.find(d => d.id === id)
return dept ? dept.deptName : `部门${id}`
})
// 从部门列表中查找部门信息
const depts = ids.map(id => departmentList.value.find(d => d.id === id)).filter(d => d)
if (depts.length === 0) return '所有部门'
// 如果只有一个部门,显示部门名称
if (deptNames.length === 1) {
return deptNames[0]
if (depts.length === 1) {
return depts[0]!.deptName
}
// 如果有多个部门,显示全部名称(用逗号分隔)
// 检查是否所有部门属于同一个父部门
const parentIds = depts.map(d => d!.parentId).filter(id => id !== undefined && id !== null)
if (parentIds.length === depts.length) {
// 所有部门都有父部门
const uniqueParentIds = [...new Set(parentIds)]
if (uniqueParentIds.length === 1) {
// 所有部门属于同一个父部门,显示父部门名称
const parentDept = departmentList.value.find(d => d.id === uniqueParentIds[0])
if (parentDept) {
return parentDept.deptName
}
}
}
// 部门属于不同父部门,显示具体名称
const deptNames = depts.map(d => d!.deptName)
if (deptNames.length <= 3) {
return deptNames.join('、')
}
// 如果部门太多,显示前2个加省略
return `${deptNames.slice(0, 2).join('、')}等${deptNames.length}个部门`
}