diff --git a/frontend/src/views/CreateTask.vue b/frontend/src/views/CreateTask.vue index 0e74993..511044b 100644 --- a/frontend/src/views/CreateTask.vue +++ b/frontend/src/views/CreateTask.vue @@ -154,7 +154,7 @@ @@ -163,7 +163,7 @@ :key="dept.id" :value="dept.id" > - {{ dept.deptName }} + {{ dept.displayName }} @@ -1007,6 +1007,28 @@ const loadDepartmentList = async () => { } } +const getDepartmentById = (deptId?: number | null) => { + if (!deptId) return undefined + return departmentList.value.find(d => d.id === deptId) +} + +const getDepartmentDisplayName = ( + dept?: departmentApi.DepartmentOverview | null, + duplicateNames?: Set +) => { + if (!dept) return '未知部门' + + const parentDept = getDepartmentById(dept.parentId) + const shouldShowParent = duplicateNames?.has(dept.deptName) ?? false + const isThirdLevelOrDeeper = !!parentDept && parentDept.parentId !== undefined && parentDept.parentId !== null && parentDept.parentId !== 0 + + if (!parentDept || (!shouldShowParent && !isThirdLevelOrDeeper)) { + return dept.deptName + } + + return `${parentDept.deptName} / ${dept.deptName}` +} + // 构建级联选择器选项(三级结构) const taskTypeCascaderOptions = computed(() => { const buildOptions = (items: any[]): CascaderOption[] => { @@ -1400,8 +1422,8 @@ const pipelineGroups = computed(() => { // 如果用户选择了具体部门,使用用户选择的部门 if (taskType.selectedDeptId) { deptIds = String(taskType.selectedDeptId) - const selectedDept = departmentList.value.find(d => d.id === taskType.selectedDeptId) - deptName = selectedDept?.deptName || '未知部门' + const selectedDept = getDepartmentById(taskType.selectedDeptId) + deptName = getDepartmentDisplayName(selectedDept) } else { deptName = getDeptNameFromIds(deptIds) } @@ -1448,7 +1470,7 @@ const pipelineGroups = computed(() => { }) // 获取任务类型可选的部门列表 -const getTaskTypeDeptOptions = (item: TaskTypeItem): Array<{ id: number, deptName: string }> => { +const getTaskTypeDeptOptions = (item: TaskTypeItem): Array<{ id: number, deptName: string, displayName: string }> => { if (!item.taskTypeId) return [] const typeInfo = getTaskTypeInfo(item.taskTypeId) @@ -1459,12 +1481,23 @@ const getTaskTypeDeptOptions = (item: TaskTypeItem): Array<{ id: number, deptNam const ids = deptIds.split(',').map(id => parseInt(id.trim())).filter(id => !isNaN(id)) if (ids.length <= 1) return [] // 只有一个部门时不需要选择 + + const depts = ids + .map(id => getDepartmentById(id)) + .filter((dept): dept is departmentApi.DepartmentOverview => !!dept) + + const duplicateNames = new Set( + depts + .map(dept => dept.deptName) + .filter((name, index, names) => names.indexOf(name) !== index) + ) - // 返回部门列表 - return ids.map(id => { - const dept = departmentList.value.find(d => d.id === id) - return dept ? { id: dept.id!, deptName: dept.deptName } : null - }).filter(d => d !== null) as Array<{ id: number, deptName: string }> + // 同名三级部门展示为“二级部门 / 三级部门”,避免用户无法区分 + return depts.map(dept => ({ + id: dept.id!, + deptName: dept.deptName, + displayName: getDepartmentDisplayName(dept, duplicateNames) + })) } // 根据部门ID获取部门名称 @@ -1475,12 +1508,12 @@ const getDeptNameFromIds = (deptIds: string): string => { if (ids.length === 0) return '所有部门' // 从部门列表中查找部门信息 - const depts = ids.map(id => departmentList.value.find(d => d.id === id)).filter(d => d) + const depts = ids.map(id => getDepartmentById(id)).filter((dept): dept is departmentApi.DepartmentOverview => !!dept) if (depts.length === 0) return '所有部门' // 如果只有一个部门,显示部门名称 if (depts.length === 1) { - return depts[0]!.deptName + return getDepartmentDisplayName(depts[0]) } // 检查是否所有部门属于同一个父部门 @@ -1490,7 +1523,7 @@ const getDeptNameFromIds = (deptIds: string): string => { const uniqueParentIds = [...new Set(parentIds)] if (uniqueParentIds.length === 1) { // 所有部门属于同一个父部门,显示父部门名称 - const parentDept = departmentList.value.find(d => d.id === uniqueParentIds[0]) + const parentDept = getDepartmentById(uniqueParentIds[0]) if (parentDept) { return parentDept.deptName } @@ -1498,7 +1531,12 @@ const getDeptNameFromIds = (deptIds: string): string => { } // 部门属于不同父部门,显示具体名称 - const deptNames = depts.map(d => d!.deptName) + const duplicateNames = new Set( + depts + .map(dept => dept.deptName) + .filter((name, index, names) => names.indexOf(name) !== index) + ) + const deptNames = depts.map(dept => getDepartmentDisplayName(dept, duplicateNames)) if (deptNames.length <= 3) { return deptNames.join('、') } @@ -3166,8 +3204,8 @@ onUnmounted(() => { .task-type-dept { flex-shrink: 0; - min-width: 160px; // 固定最小宽度 - width: 160px; // 固定宽度 + min-width: 220px; // 给“二级部门 / 三级部门”留出足够空间 + width: 220px; } .task-type-actions {