fix(websocket): 处理 ORDER_UPDATE_LINE 时强制重新绘制完整路线
当收到 ORDER_UPDATE_LINE 类型的 WebSocket 消息时,需要强制重置路线状态并触发完整重绘,以解决路线更新时可能出现的显示不一致问题。在 use-web-socket-events 钩子中新增了 handleForceFullRouteRedraw 函数来清空所有相关状态并重新应用新路线点。
| | |
| | | }); |
| | | }; |
| | | |
| | | 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); |
| | |
| | | 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); |
| | |
| | | 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') { |