From 2895d59e2ac06f3c418a15049170c33dcfbaae0c Mon Sep 17 00:00:00 2001 From: xudan Date: Wed, 22 Oct 2025 15:07:33 +0800 Subject: [PATCH] =?UTF-8?q?feat(movement-supervision):=20=E4=BC=98?= =?UTF-8?q?=E5=8C=96=E6=A5=BC=E5=B1=82=E5=88=87=E6=8D=A2=E4=BD=93=E9=AA=8C?= =?UTF-8?q?=EF=BC=8C=E5=BC=82=E6=AD=A5=E5=A4=84=E7=90=86=E6=9C=BA=E5=99=A8?= =?UTF-8?q?=E4=BA=BA=E5=88=9D=E5=A7=8B=E5=8C=96=E4=B8=8EWebSocket=E8=BF=9E?= =?UTF-8?q?=E6=8E=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .env.development | 2 +- src/pages/movement-supervision.vue | 21 +++++++++++++-------- src/pages/scene-editor.vue | 9 ++++++++- 3 files changed, 22 insertions(+), 10 deletions(-) diff --git a/.env.development b/.env.development index 8a075a6..b9977a8 100644 --- a/.env.development +++ b/.env.development @@ -4,5 +4,5 @@ ENV_WEBSOCKET_BASE=/ws ENV_STORAGE_WEBSOCKET_BASE=/vwedWs # 开发环境token配置 - 可以手动设置或从另一个项目获取后填入 -ENV_DEV_TOKEN=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjE3NjEyMjQyMDUsInVzZXJuYW1lIjoiYWRtaW4ifQ.VJh59eh3inhKqqupFvxOnSGkJd0zUf_PmBmRMyiQKX0 +ENV_DEV_TOKEN=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjE3NjEyMzM2NzMsInVzZXJuYW1lIjoiYWRtaW4ifQ.KPflinK1a3dxwjkEuZTfyVnEe7oX1LwmzBYn0-hSogc ENV_DEV_TENANT_ID=1000 diff --git a/src/pages/movement-supervision.vue b/src/pages/movement-supervision.vue index b152c2d..4655128 100644 --- a/src/pages/movement-supervision.vue +++ b/src/pages/movement-supervision.vue @@ -649,20 +649,25 @@ const handleAutoSaveAndRestoreViewState = async () => { const handleFloorChange = async (value: any) => { const newFloorIndex = value as number; if (editor.value && floorScenes.value[newFloorIndex]) { + // 1) 先加载新楼层 await editor.value.load(floorScenes.value[newFloorIndex]); - // 切换楼层后,重新初始化机器人以确保状态正确 - await editor.value.initRobots(); - // 重新连接 WebSocket 以获取新楼层的实时数据 - if (mode.value === 'live') { - await monitorScene(); - } - // 楼层切换后定位到中心(参考 map-toolbar.vue) + + // 2) 立即定位到新楼层中心,提升交互反馈(不要等待后续WS/机器人初始化) try { const { centerX, centerY } = calculateCenterPoint(editor.value); - jumpToPosition(editor.value, centerX, centerY, false, 0.05); + await jumpToPosition(editor.value, centerX, centerY, false, 0.05); } catch { // ignore } + + // 3) 后续耗时操作异步进行,避免阻塞定位体验 + // 3.1 重新初始化机器人 + Promise.resolve(editor.value.initRobots()).catch(() => void 0); + + // 3.2 重新连接 WebSocket 以获取新楼层的实时数据(不等待握手完成) + if (mode.value === 'live') { + void monitorScene(); + } } }; //#endregion diff --git a/src/pages/scene-editor.vue b/src/pages/scene-editor.vue index 99998d7..79ff50b 100644 --- a/src/pages/scene-editor.vue +++ b/src/pages/scene-editor.vue @@ -656,7 +656,7 @@ const selectRobot = (id: string) => { editor.value?.inactive(); }; -const { saveViewState, autoSaveAndRestoreViewState, isSaving } = useViewState(); +const { saveViewState, autoSaveAndRestoreViewState, isSaving, jumpToPosition, calculateCenterPoint } = useViewState(); const handleSaveViewState = async () => { if (!editor.value) return; @@ -707,6 +707,13 @@ const handleFloorChange = async (value: any) => { undefined, floorImportFlags.value[newFloorIndex] ?? false, ); + // 加载完成后,立即定位到新楼层内容中心,提升体验 + try { + const { centerX, centerY } = calculateCenterPoint(editor.value); + await jumpToPosition(editor.value, centerX, centerY, false, 0.05); + } catch { + // ignore + } } else { currentFloorIndex.value = newFloorIndex; previousFloorIndex.value = newFloorIndex;