| | |
| | | cancelOrder, |
| | | queryOrderRoute, |
| | | } from '../../../robotaxi/api/begin-route'; |
| | | import { getOrderDetail } from '../../../robotaxi/api/order'; |
| | | |
| | | export default function SelectMapSite() { |
| | | const WAITING_TIMER_START_KEY = 'waitingTimerStartAt'; |
| | |
| | | const [waitingRadarVisible, setWaitingRadarVisible] = useState(true); |
| | | |
| | | const tripStatusRef = useRef(tripStatus); // 行程状态引用 |
| | | const lastTripStatusRef = useRef(tripStatus); |
| | | const routeRequestKeyRef = useRef<string>(''); // 路线请求键 |
| | | const allowIncludePointsRef = useRef(true); |
| | | const orderRouteInitializedRef = useRef(false); |
| | | // 在发布行程状态也允许展示路线 |
| | | const shouldShowRoute = [1, 4, 6, 8, 9].includes(tripStatus); |
| | | const authSuccessBound = useRef(false); // 认证成功是否绑定 |
| | |
| | | } |
| | | }, []); |
| | | const shouldShowWaitingRadar = isAndroid && [2, 3].includes(tripStatus); |
| | | |
| | | useEffect(() => { |
| | | const wasHold = [6].includes(lastTripStatusRef.current); |
| | | const isHold = [6].includes(tripStatus); |
| | | if (!wasHold && isHold) { |
| | | allowIncludePointsRef.current = true; |
| | | orderRouteInitializedRef.current = false; |
| | | } |
| | | lastTripStatusRef.current = tripStatus; |
| | | }, [tripStatus]); |
| | | |
| | | // 加载等待弹窗图片 |
| | | useEffect(() => { |
| | |
| | | setRoutePoints([]); |
| | | setPolyline([]); |
| | | } |
| | | if (payload?.showCancelPopup) { |
| | | if (payload?.status === 0 && tripStatus == 5) { |
| | | setCancelType(2); |
| | | } |
| | | if (payload?.status === 0 && [2, 3].includes(tripStatus)) { |
| | | setCancelType(3); |
| | | } |
| | | setShowCancelPopup(true); |
| | | } |
| | | // if (payload?.showCancelPopup) { |
| | | // if (payload?.status === 0 && tripStatus == 5) { |
| | | // setCancelType(2); |
| | | // } |
| | | // if (payload?.status === 0 && [2, 3].includes(tripStatus)) { |
| | | // setCancelType(3); |
| | | // } |
| | | // setShowCancelPopup(true); |
| | | // } |
| | | if (payload?.showPassengerNotice) { |
| | | if (Taro.getStorageSync('passengerNoticeShowed') !== 'true') { |
| | | setShowPassengerNotice(true); |
| | |
| | | |
| | | orderRouteHandlerRef.current = (payload) => { |
| | | const points = payload?.points || []; |
| | | // if (tripStatusRef.current !== 5) { |
| | | setTimeout(() => { |
| | | applyRoutePoints(points); |
| | | if ([4, 5, 6].includes(tripStatusRef.current)) { |
| | | const firstPoint = points?.[0]; |
| | | if (firstPoint && typeof firstPoint.latitude === 'number' && typeof firstPoint.longitude === 'number') { |
| | | setVehicleLocation({ latitude: firstPoint.latitude, longitude: firstPoint.longitude }); |
| | | } |
| | | } |
| | | }, 500); |
| | | // } else { |
| | | // setRoutePoints([]); |
| | | // setPolyline([]); |
| | | // } |
| | | const direction = payload?.direction; |
| | | if (typeof direction === 'number' && Number.isFinite(direction)) { |
| | | setVehicleDirection(direction); |
| | |
| | | const distanceKm = normalizeDistanceKm(distance); |
| | | if (distanceKm !== null) { |
| | | setRouteDistance(distanceKm); |
| | | Taro.setStorageSync('orderRouteDistance', distanceKm); |
| | | Taro.setStorageSync('orderRouteDistanceUnit', 'km'); |
| | | Taro.setStorageSync('orderRouteDistance', distanceKm.value); |
| | | Taro.setStorageSync('orderRouteDistanceUnit', distanceKm.unit); |
| | | } |
| | | const durationSeconds = normalizeDurationSeconds(duration); |
| | | if (durationSeconds !== null) { |
| | |
| | | Taro.setStorageSync('orderRouteDuration', durationSeconds); |
| | | Taro.setStorageSync('orderRouteDurationUnit', 's'); |
| | | } |
| | | const isHoldMapStatus = [5, 6].includes(tripStatusRef.current); |
| | | // 仅在呼叫及后续阶段允许展示路线 |
| | | if (isHoldMapStatus && orderRouteInitializedRef.current) { |
| | | setTimeout(() => { |
| | | applyRoutePoints(points); |
| | | const firstPoint = points?.[0]; |
| | | if (firstPoint && typeof firstPoint.latitude === 'number' && typeof firstPoint.longitude === 'number') { |
| | | setVehicleLocation({ latitude: firstPoint.latitude, longitude: firstPoint.longitude }); |
| | | } |
| | | }, 500); |
| | | return; |
| | | } |
| | | if (isHoldMapStatus) { |
| | | orderRouteInitializedRef.current = true; |
| | | } |
| | | |
| | | // 发布行程状态也允许展示路线 |
| | | setTimeout(() => { |
| | | applyRoutePoints(points); |
| | | if ([4, 5, 6].includes(tripStatusRef.current)) { |
| | | const firstPoint = points?.[0]; |
| | | if (firstPoint && typeof firstPoint.latitude === 'number' && typeof firstPoint.longitude === 'number') { |
| | | setVehicleLocation({ latitude: firstPoint.latitude, longitude: firstPoint.longitude }); |
| | | } |
| | | } |
| | | }, 500); |
| | | |
| | | }; |
| | | // 仅在呼叫及后续阶段允许更新车辆位置 |
| | | vehicleLocationHandlerRef.current = (payload) => { |
| | | const latitude = payload?.latitude; |
| | | const longitude = payload?.longitude; |
| | |
| | | latitude: e.latitude, |
| | | longitude: e.longitude, |
| | | }], |
| | | padding: [50, 50, 500, 50] |
| | | padding: [50, 50, 600, 50] |
| | | }); |
| | | } |
| | | setElapsedSeconds(0); |
| | | Taro.removeStorageSync(WAITING_TIMER_START_KEY); |
| | | Taro.removeStorageSync(WAITING_TIMER_ELAPSED_KEY); |
| | | } else if ([8, 9].includes(tripStatus)) { |
| | | getOrderDetail(Taro.getStorageSync('orderId')).then((res: any) => { |
| | | if (res.trajectories) { |
| | | const points = res.trajectories.map((item: any) => ({ |
| | | latitude: item.location.split(',')[1], |
| | | longitude: item.location.split(',')[0], |
| | | })); |
| | | applyRoutePoints(points); |
| | | const mapCtx = Taro.createMapContext('map'); |
| | | mapCtx.includePoints({ |
| | | points: points, |
| | | padding: [40, 40, 500, 40] |
| | | }) |
| | | } |
| | | }); |
| | | setElapsedSeconds(0); |
| | | Taro.removeStorageSync(WAITING_TIMER_START_KEY); |
| | | Taro.removeStorageSync(WAITING_TIMER_ELAPSED_KEY); |
| | |
| | | useEffect(() => { |
| | | const s = Taro.getStorageSync('startSite'); |
| | | const pickupMarker = s?.latitude && s?.longitude ? { |
| | | id: Date.now() + 1, |
| | | id: 1, |
| | | latitude: s.latitude, |
| | | longitude: s.longitude, |
| | | iconPath: 'https://huishou-1323682843.cos.ap-nanjing.myqcloud.com/images/51e7cb75-72af-4994-9d6e-d999efb2fbc7.png', |
| | |
| | | } |
| | | } : null; |
| | | const dropoffMarker = endSite?.latitude && endSite?.longitude ? { |
| | | id: Date.now() + 2, |
| | | id: 2, |
| | | latitude: endSite.latitude, |
| | | longitude: endSite.longitude, |
| | | iconPath: 'https://huishou-1323682843.cos.ap-nanjing.myqcloud.com/images/6a56b1eb-ec37-4839-8733-262942af070d.png', |
| | |
| | | } |
| | | } : null; |
| | | const carMarker = vehicleLocation ? { |
| | | id: Date.now() + 3, |
| | | id: 3, |
| | | latitude: vehicleLocation.latitude, |
| | | longitude: vehicleLocation.longitude, |
| | | iconPath: 'https://huishou-1323682843.cos.ap-nanjing.myqcloud.com/images/e51e92e6-700d-4e83-b3e0-14e6f18e0b9a.png', |
| | |
| | | }); |
| | | } |
| | | setPolyline(lines); |
| | | const mapCtx = Taro.createMapContext('map'); |
| | | if ([8, 9].includes(tripStatus) && routePoints.length > 0) { |
| | | mapCtx.includePoints({ |
| | | points: routePoints, |
| | | padding: [50, 50, 500, 50] |
| | | }); |
| | | } else { |
| | | const allPoints = [ |
| | | ...routePoints, |
| | | ...walkingPoints, |
| | | ]; |
| | | mapCtx.includePoints({ |
| | | points: allPoints, |
| | | padding: [50, 50, ![1, 6].includes(tripStatus) ? 500 : 100, 50] |
| | | }); |
| | | if (![6].includes(tripStatus) || allowIncludePointsRef.current) { |
| | | const mapCtx = Taro.createMapContext('map'); |
| | | if ([8, 9].includes(tripStatus) && routePoints.length > 0) { |
| | | mapCtx.includePoints({ |
| | | points: routePoints, |
| | | padding: [50, 50, 500, 50] |
| | | }); |
| | | } else { |
| | | const allPoints = [ |
| | | ...routePoints, |
| | | ...walkingPoints, |
| | | ]; |
| | | mapCtx.includePoints({ |
| | | points: allPoints, |
| | | padding: [50, 50, ![1, 6].includes(tripStatus) ? 500 : 100, 50] |
| | | }); |
| | | } |
| | | if ([6].includes(tripStatus)) { |
| | | allowIncludePointsRef.current = false; |
| | | } |
| | | } |
| | | } else { |
| | | setPolyline([]); |