fix: 修复编辑学校时所属区域不回显问题
原 getRegionIdPath 函数假设区域ID按层级编码,实际不是 改为递归遍历区域树查找目标节点,返回从根到目标的完整路径
This commit is contained in:
parent
3cad9fa79a
commit
10469f6517
|
|
@ -179,23 +179,24 @@ const open = (row, defaultRegionId = null) => {
|
||||||
const getRegionIdPath = (regionId) => {
|
const getRegionIdPath = (regionId) => {
|
||||||
if (!regionId) return []
|
if (!regionId) return []
|
||||||
|
|
||||||
const id = regionId.toString()
|
// 递归遍历树查找目标节点,返回从根到目标的完整路径
|
||||||
const path = []
|
const findPath = (nodes, targetId, path = []) => {
|
||||||
|
for (const node of nodes) {
|
||||||
// 省级ID(1位)
|
const currentPath = [...path, node.regionId]
|
||||||
if (id.length >= 1) {
|
if (node.regionId === targetId) {
|
||||||
path.push(parseInt(id.charAt(0)))
|
return currentPath
|
||||||
}
|
}
|
||||||
// 市级ID(2位)
|
if (node.children && node.children.length > 0) {
|
||||||
if (id.length >= 2) {
|
const result = findPath(node.children, targetId, currentPath)
|
||||||
path.push(parseInt(id.substring(0, 2)))
|
if (result.length > 0) {
|
||||||
}
|
return result
|
||||||
// 区级ID(3位)
|
}
|
||||||
if (id.length >= 3) {
|
}
|
||||||
path.push(parseInt(id))
|
}
|
||||||
|
return []
|
||||||
}
|
}
|
||||||
|
|
||||||
return path
|
return findPath(props.regionTree, regionId)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 提交表单
|
// 提交表单
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue