fix(maps): MapCanvas onMounted 忽略路由 :id 恒取第一张地图 — 修复 /maps/canvas/53 打开显示54空图、新增节点落错地图

This commit is contained in:
Hermes CI Fix
2026-09-08 20:35:51 +08:00
parent 265714341c
commit aa81cee009
+8 -2
View File
@@ -176,6 +176,7 @@
<script setup lang="ts">
import { ref, reactive, computed, watch, onMounted, nextTick, onUnmounted } from "vue"
import { useRoute } from "vue-router"
import { ElMessage, ElMessageBox } from "element-plus"
import { mapApi, kpiApi, okrTemplateApi, okrApi } from "../api/index"
import KnowledgePanel from '../components/KnowledgePanel.vue'
@@ -192,6 +193,7 @@ import html2canvas from "html2canvas"
// ── 四层泳道配置 ──
const layerKeysOrdered = [...LAYER_KEYS]
const orderedLayerConfigs = getLayerList()
const route = useRoute()
// ── 状态 ──
const maps = ref<any[]>([])
@@ -1249,8 +1251,12 @@ function onWindowResize() {
onMounted(async () => {
const r: any = await mapApi.list()
maps.value = r.data || []
if (maps.value.length > 0) {
selectedMap.value = maps.value[0].id
// 路由带 id 优先加载对应地图(2026-09-08 修复:原忽略 :id 恒取第一张,
// 致 /maps/canvas/53 打开却显示最新图54、新增节点落错地图)
const routeId = Number(route.params.id)
const target = maps.value.find((m: any) => m.id === routeId) || maps.value[0]
if (target) {
selectedMap.value = target.id
loadCanvas()
} else {
ensureFourLayers()