hejianhao
2026-04-03 a5a21c42f70a7bb61aade6fe7eaf3d2da7624f31
fix(后备箱控制): 优化后备箱状态轮询逻辑

- 提取轮询失败处理逻辑为独立函数,减少代码重复
- 增加后备箱状态数据有效性检查,避免因空数据导致轮询中断
- 统一后备箱状态值类型转换,确保比较逻辑一致性
1个文件已修改
55 ■■■■■ 已修改文件
src/robotaxi/pages/begin-route/components/calling-car.tsx 55 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/robotaxi/pages/begin-route/components/calling-car.tsx
@@ -474,14 +474,6 @@
            doorType,
            ...locationPayload
        }).then((res: any) => {
            const isFailure = res?.success === false || (typeof res?.code === 'number' && res.code !== 0);
            if (isFailure) {
                Taro.showToast({
                    title: res?.msg || '解锁失败,请重试或联系客服',
                    icon: 'none'
                });
                return;
            }
            if (doorType === 'trunk') {
                const loadingText = trunkStatus ? '正在关闭后备箱' : '正在开启后备箱';
                Taro.showLoading({ title: loadingText, mask: true });
@@ -490,10 +482,31 @@
                const maxPolls = 3;
                const pollInterval = 2000; // 2秒
                const handlePollFail = () => {
                    pollCount++;
                    if (pollCount < maxPolls) {
                        trunkPollTimerRef.current = setTimeout(doPoll, pollInterval);
                    } else {
                        Taro.hideLoading();
                        Taro.showToast({
                            title: trunkStatus ? '关闭后备箱失败' : '开启后备箱失败',
                            icon: 'none'
                        });
                    }
                };
                const doPoll = () => {
                    queryVehicleTrunkOpenStatus({ orderId: targetOrderId }).then((pollRes: any) => {
                        const data = pollRes?.data ?? pollRes?.result ?? pollRes;
                        const value = data?.stateMap?.trunkAjarCloseSt?.value;
                        const data = pollRes;
                        const rawValue = data?.stateMap?.trunkAjarCloseSt?.value;
                        // 如果 data 或 value 为空,继续轮询
                        if (!data || rawValue === undefined || rawValue === null || rawValue === '') {
                            handlePollFail();
                            return;
                        }
                        const value = String(rawValue);
                        
                        if (value === '0' || value === '1') {
                            // 0: 关闭, 1: 开启
@@ -507,28 +520,10 @@
                            onSuccess?.();
                        } else {
                            // 继续轮询
                            pollCount++;
                            if (pollCount < maxPolls) {
                                trunkPollTimerRef.current = setTimeout(doPoll, pollInterval);
                            } else {
                                Taro.hideLoading();
                                Taro.showToast({
                                    title: trunkStatus ? '关闭后备箱失败' : '开启后备箱失败',
                                    icon: 'none'
                                });
                            }
                            handlePollFail();
                        }
                    }).catch(() => {
                        pollCount++;
                        if (pollCount < maxPolls) {
                            trunkPollTimerRef.current = setTimeout(doPoll, pollInterval);
                        } else {
                            Taro.hideLoading();
                            Taro.showToast({
                                title: trunkStatus ? '关闭后备箱失败' : '开启后备箱失败',
                                icon: 'none'
                            });
                        }
                        handlePollFail();
                    });
                };