feat(movement-supervision): 优化楼层切换体验,异步处理机器人初始化与WebSocket连接
This commit is contained in:
parent
d2eb594099
commit
2895d59e2a
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user