hejianhao
2026-04-13 49c63ef784c22302c22e1aa4fb4eea3691d3b297
fix(websocket): 处理 ORDER_UPDATE_LINE 时强制重新绘制完整路线

当收到 ORDER_UPDATE_LINE 类型的 WebSocket 消息时,需要强制重置路线状态并触发完整重绘,以解决路线更新时可能出现的显示不一致问题。在 use-web-socket-events 钩子中新增了 handleForceFullRouteRedraw 函数来清空所有相关状态并重新应用新路线点。
2个文件已修改
37 ■■■■■ 已修改文件
src/robotaxi/pages/begin-route/hooks/use-web-socket-events.ts 25 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/utils/websocket.ts 12 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/robotaxi/pages/begin-route/hooks/use-web-socket-events.ts
@@ -204,14 +204,39 @@
    });
};
const handleForceFullRouteRedraw = (points: any[], deps: UseWebSocketEventsDeps) => {
    deps.setRoutePoints([]);
    deps.setPolyline([]);
    deps.orderRouteInitializedRef.current = false;
    deps.currentFullRouteRef.current = [];
    deps.lastErasedIndexRef.current = 0;
    deps.polylineKeyRef.current = '';
    deps.lastPolylineUpdateAtRef.current = 0;
    deps.lastRoutePointRef.current = null;
    deps.lastRouteUpdateAtRef.current = 0;
    Taro.nextTick(() => {
        deps.orderRouteInitializedRef.current = true;
        deps.currentFullRouteRef.current = [...points];
        deps.lastErasedIndexRef.current = 0;
        deps.applyRoutePoints(points);
        syncVehiclePointWithRoute(points, deps);
    });
};
const handleOrderRoutePayload = (payload: any, deps: UseWebSocketEventsDeps) => {
    if (deps.tripStatusRef.current === 5) return;
    const points = payload?.points || [];
    const servedPoints = Array.isArray(payload?.servedPoints) ? payload.servedPoints : [];
    const forceFullRedraw = payload?.forceFullRedraw === true;
    updateRouteSummary(payload, deps);
    if ([4, 6].includes(deps.tripStatusRef.current)) {
        deps.setVehicleMoveAlongPoints(servedPoints);
    }
    if (forceFullRedraw) {
        handleForceFullRouteRedraw(points, deps);
        return;
    }
    const isEraseStatus = [4, 6].includes(deps.tripStatusRef.current);
    if (isEraseStatus) {
        handleEraseRouteStatus(points, deps);
src/utils/websocket.ts
@@ -426,7 +426,7 @@
        this.notifyListeners('order_status', { status, ...mapped, data, content });
      }
    }
    if (data?.type === 'ORDER_ROUTE') {
    if (data?.type === 'ORDER_ROUTE' || data?.type === 'ORDER_UPDATE_LINE') {
      const routeType = content?.routeType;
      const routeObj = safeParse(content?.route ?? '{}', {});
      const rawDirection = Number(content?.direction);
@@ -453,7 +453,15 @@
          cached.latest = points;
        }
        Taro.setStorageSync('orderRoutePoints', cached);
        this.notifyListeners('order_route', { routeType, direction, points, servedPoints, data, content });
        this.notifyListeners('order_route', {
          routeType,
          direction,
          points,
          servedPoints,
          data,
          content,
          forceFullRedraw: data?.type === 'ORDER_UPDATE_LINE'
        });
      }
    }
    if (data?.type === 'ORDER_UPDATE_PRICE') {