diff --git a/frontend/ruoyi-ui/src/views/business/school/components/SchoolDialog.vue b/frontend/ruoyi-ui/src/views/business/school/components/SchoolDialog.vue index 16de0f3..a59c058 100644 --- a/frontend/ruoyi-ui/src/views/business/school/components/SchoolDialog.vue +++ b/frontend/ruoyi-ui/src/views/business/school/components/SchoolDialog.vue @@ -179,23 +179,24 @@ const open = (row, defaultRegionId = null) => { const getRegionIdPath = (regionId) => { if (!regionId) return [] - const id = regionId.toString() - const path = [] - - // 省级ID(1位) - if (id.length >= 1) { - path.push(parseInt(id.charAt(0))) - } - // 市级ID(2位) - if (id.length >= 2) { - path.push(parseInt(id.substring(0, 2))) - } - // 区级ID(3位) - 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) } // 提交表单