From 10469f6517ca92c40e35ec76c2b1efab6f2cbc39 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A5=9E=E7=A0=81-=E6=96=B9=E6=99=93=E8=BE=89?= Date: Mon, 2 Feb 2026 17:54:24 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E7=BC=96=E8=BE=91?= =?UTF-8?q?=E5=AD=A6=E6=A0=A1=E6=97=B6=E6=89=80=E5=B1=9E=E5=8C=BA=E5=9F=9F?= =?UTF-8?q?=E4=B8=8D=E5=9B=9E=E6=98=BE=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 原 getRegionIdPath 函数假设区域ID按层级编码,实际不是 改为递归遍历区域树查找目标节点,返回从根到目标的完整路径 --- .../school/components/SchoolDialog.vue | 31 ++++++++++--------- 1 file changed, 16 insertions(+), 15 deletions(-) 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) } // 提交表单