fix: 修复编辑学校时所属区域不回显问题

原 getRegionIdPath 函数假设区域ID按层级编码,实际不是
改为递归遍历区域树查找目标节点,返回从根到目标的完整路径
This commit is contained in:
神码-方晓辉 2026-02-02 17:54:24 +08:00
parent 3cad9fa79a
commit 10469f6517
1 changed files with 16 additions and 15 deletions

View File

@ -179,23 +179,24 @@ const open = (row, defaultRegionId = null) => {
const getRegionIdPath = (regionId) => {
if (!regionId) return []
const id = regionId.toString()
const path = []
// ID1
if (id.length >= 1) {
path.push(parseInt(id.charAt(0)))
}
// ID2
if (id.length >= 2) {
path.push(parseInt(id.substring(0, 2)))
}
// ID3
if (id.length >= 3) {
path.push(parseInt(id))
//
const findPath = (nodes, targetId, path = []) => {
for (const node of nodes) {
const currentPath = [...path, node.regionId]
if (node.regionId === targetId) {
return currentPath
}
if (node.children && node.children.length > 0) {
const result = findPath(node.children, targetId, currentPath)
if (result.length > 0) {
return result
}
}
}
return []
}
return path
return findPath(props.regionTree, regionId)
}
//