hejianhao
2026-07-01 dd369cf1a6d50f97167e2174ee9b9e29f3eedb32
重构(行程开始页面): 提取并复用车门解锁状态管理逻辑
1个文件已修改
48 ■■■■■ 已修改文件
src/robotaxi/pages/begin-route/index.tsx 48 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/robotaxi/pages/begin-route/index.tsx
@@ -294,7 +294,9 @@
  const requoteTriggeredRef = useRef(false); // 重新报价触发标记,防止重复触发
  const [callSubmitting, setCallSubmitting] = useState(false); // 呼叫车辆提交中状态
  const [orderId, setOrderId] = useState<string>(''); // 订单ID
  const [doorUnlockedInCurrentPage, setDoorUnlockedInCurrentPage] = useState(false); // 当前页面内是否已解锁过车门
  const [doorUnlockedInCurrentPage, setDoorUnlockedInCurrentPage] = useState(() => {
    return getDoorUnlockCache(getOrderId(String(Taro.getStorageSync('orderId') || '')));
  }); // 当前页面内是否已解锁过车门
  const [finishCountdownEnabled, setFinishCountdownEnabled] = useState(false); // 完成倒计时是否启用
  const customCalloutIconUrl = 'https://s.xiaopeng.com/xp-fe/robot-taxi/imgs/maker-tooltip-right.png'; // 自定义气泡图标URL
  const waitingCalloutBgUrl = 'https://s.xiaopeng.com/xp-fe/robot-taxi/imgs/maker-tooltip-bg.png'; // 等待气泡背景图URL
@@ -646,6 +648,21 @@
    lastVehiclePointRef,
    lastVehicleUpdateAtRef
  } = vehicleState; // 车辆状态解构
  const resolveDoorUnlockTargetOrderId = useCallback((explicitOrderId?: string) => {
    return getOrderId(explicitOrderId || orderId || Taro.getStorageSync('orderId') || '');
  }, [orderId]);
  const restoreDoorUnlockUiState = useCallback((explicitOrderId?: string) => {
    const targetOrderId = resolveDoorUnlockTargetOrderId(explicitOrderId);
    setDoorUnlockedInCurrentPage(getDoorUnlockCache(targetOrderId));
  }, [resolveDoorUnlockTargetOrderId]);
  const markDoorUnlockedForCurrentOrder = useCallback((explicitOrderId?: string) => {
    const targetOrderId = resolveDoorUnlockTargetOrderId(explicitOrderId);
    if (!targetOrderId) {
      return;
    }
    setDoorUnlockedInCurrentPage(true);
    setDoorUnlockCache(targetOrderId);
  }, [resolveDoorUnlockTargetOrderId]);
  const routeState = useRouteManager({
    isAndroid,
    tripStatus,
@@ -668,12 +685,7 @@
      if (!isOpenDoor) {
        return;
      }
      const targetOrderId = getOrderId(orderId || Taro.getStorageSync('orderId') || '');
      if (!targetOrderId) {
        return;
      }
      setDoorUnlockedInCurrentPage(true);
      setDoorUnlockCache(targetOrderId);
      markDoorUnlockedForCurrentOrder();
    },
    setCurrentUserLocation,
    handleOpenNoRoutePopup
@@ -1462,20 +1474,22 @@
   * 手动解锁成功后,同步页面级开门态并写入订单级缓存,供重新进页恢复 UI。
   */
  const handleDoorUnlockSuccess = useCallback(() => {
    const targetOrderId = getOrderId(orderId || Taro.getStorageSync('orderId') || '');
    if (!targetOrderId) {
      return;
    }
    setDoorUnlockedInCurrentPage(true);
    setDoorUnlockCache(targetOrderId);
  }, [orderId]);
    markDoorUnlockedForCurrentOrder();
  }, [markDoorUnlockedForCurrentOrder]);
  /**
   * 订单切换后重置当前页面内的车门打开态,避免串单。
   */
  useEffect(() => {
    setDoorUnlockedInCurrentPage(getDoorUnlockCache(getOrderId(orderId)));
  }, [orderId]);
    restoreDoorUnlockUiState(orderId);
  }, [orderId, restoreDoorUnlockUiState]);
  /**
   * 页面重新展示后按当前订单缓存恢复开门 UI,避免退出再进入时丢态。
   */
  useEffect(() => {
    restoreDoorUnlockUiState(orderId);
  }, [pageDidShowVersion, orderId, restoreDoorUnlockUiState]);
  const { queryPaymentResult: queryOrderPaymentResult } = useOrderPaymentResultQuery({
    orderId,
@@ -1613,8 +1627,6 @@
  useDidShow(() => {
    setPageDidShowVersion((v) => v + 1);
    const targetOrderId = getOrderId(orderId || Taro.getStorageSync('orderId') || '');
    setDoorUnlockedInCurrentPage(getDoorUnlockCache(targetOrderId));
    handleDidShow(router.params?.skipPageFlag, router.params?.fromModifyDestination);
    updateMapViewportPadding();
    // 完成态下隐藏小程序再恢复时,受控中心点可能与原生地图实际中心脱钩,主动触发一次