diff --git a/frontend/ruoyi-ui/src/views/business/school/index.vue b/frontend/ruoyi-ui/src/views/business/school/index.vue index 8f7d7a2..1647c55 100644 --- a/frontend/ruoyi-ui/src/views/business/school/index.vue +++ b/frontend/ruoyi-ui/src/views/business/school/index.vue @@ -61,6 +61,7 @@ :tree-props="{ children: 'children', hasChildren: 'hasChildren' }" :header-cell-style="{ background: '#f5f7fa', color: '#606266' }" style="width: 100%" + @expand-change="handleExpandChange" > @@ -193,6 +194,27 @@ const handleNodeClick = (data) => { getSchoolTree() } +// 表格行展开/折叠时,自动选中左侧对应区域 +const handleExpandChange = (row, expanded) => { + if (!expanded) return // 折叠时不处理 + + // 获取区域ID:学校直接取 regionId,年级/班级需要从父级学校获取 + let regionId = null + if (row.type === 'school') { + regionId = row.regionId + } else if (row.type === 'grade' || row.type === 'class') { + // 从 treeData 中查找所属学校的 regionId + const school = treeData.value.find(s => s.id === row.schoolId) + regionId = school?.regionId + } + + if (regionId) { + // 设置左侧区域树的选中状态(高亮) + treeRef.value?.setCurrentKey(regionId) + selectedRegionId.value = regionId + } +} + // 搜索 const handleQuery = () => { getSchoolTree()