From 04f119a53a7fea8dfe5c809bf2681cc02fc8c4a7 Mon Sep 17 00:00:00 2001 From: freedakgmail Date: Tue, 18 Aug 2026 22:08:29 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E7=BB=84=E7=BB=87=E6=9E=B6=E6=9E=84?= =?UTF-8?q?=E9=83=A8=E9=97=A8=E4=B8=8B=E6=8B=89=E6=98=BE=E7=A4=BA=E5=B1=82?= =?UTF-8?q?=E7=BA=A7=E8=B7=AF=E5=BE=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 部门编辑弹窗上级部门下拉显示完整路径如 总公司 / 技术部 / 前端组 - 岗位编辑弹窗所属部门下拉同样显示层级路径 - 下拉选项按路径名排序 --- frontend/src/pages/OrgChart.tsx | 50 +++++++++++++++++++++++++++++++-- 1 file changed, 47 insertions(+), 3 deletions(-) diff --git a/frontend/src/pages/OrgChart.tsx b/frontend/src/pages/OrgChart.tsx index e67a6eb..d432f83 100644 --- a/frontend/src/pages/OrgChart.tsx +++ b/frontend/src/pages/OrgChart.tsx @@ -51,6 +51,28 @@ export default function OrgChart() { onError: (err: any) => toast.error(err?.response?.data?.error?.message || '删除失败'), }) + // 构建部门层级路径映射,如 "总公司 / 技术部 / 前端组" + const buildDeptPath = (departments: any[]): Record => { + const map: Record = {} + const byId: Record = {} + departments.forEach(d => { byId[d.id] = d }) + const getPath = (d: any): string => { + if (map[d.id]) return map[d.id] + const parts: string[] = [d.name] + let cur = d + while (cur.parentId && byId[cur.parentId]) { + cur = byId[cur.parentId] + parts.unshift(cur.name) + } + const path = parts.join(' / ') + map[d.id] = path + return path + } + departments.forEach(d => getPath(d)) + return map + } + const deptPathMap = buildDeptPath(departments) + const toggleExpand = (id: string) => { setExpanded(prev => { const next = new Set(prev) @@ -180,9 +202,9 @@ export default function OrgChart() {
@@ -215,6 +237,28 @@ function PositionTab({ positions, departments }: { positions: any[]; departments const [editing, setEditing] = useState(null) const [form, setForm] = useState({ name: '', departmentId: '', headcount: 0, level: '', description: '' }) + // 构建部门层级路径 + const buildDeptPath = (depts: any[]): Record => { + const map: Record = {} + const byId: Record = {} + depts.forEach(d => { byId[d.id] = d }) + const getPath = (d: any): string => { + if (map[d.id]) return map[d.id] + const parts: string[] = [d.name] + let cur = d + while (cur.parentId && byId[cur.parentId]) { + cur = byId[cur.parentId] + parts.unshift(cur.name) + } + const path = parts.join(' / ') + map[d.id] = path + return path + } + depts.forEach(d => getPath(d)) + return map + } + const deptPathMap = buildDeptPath(departments) + const createMutation = useMutation({ mutationFn: (data: any) => editing ? api.put(`/positions/${editing.id}`, data) : api.post('/positions', data), onSuccess: () => { @@ -288,7 +332,7 @@ function PositionTab({ positions, departments }: { positions: any[]; departments