xuw5
2026-05-07 7d5aafefa587270469e8895f8b9493d65b1592f8
feat: 调整轮训逻辑
1个文件已修改
31 ■■■■■ 已修改文件
src/pages/cashier/index.tsx 31 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/pages/cashier/index.tsx
@@ -92,6 +92,7 @@
  componentWillUnmount() {
    if (this.timer) {
      clearInterval(this.timer);
      clearTimeout(this.timer);
    }
    if (this.appShowListener) {
      Taro.offAppShow(this.appShowListener);
@@ -379,15 +380,16 @@
  }
  // 轮询查询信用订单状态
  pollCreditOrderStatus = async ({ businessOrderId, authOrderId, channelOrderId }) => {
  pollCreditOrderStatus = ({ businessOrderId, authOrderId, channelOrderId }): Promise<void> => {
    const maxRetries = 10;
    const interval = 2000;
    let retries = 0;
    Taro.showLoading({ title: '查询订单状态...' });
    const poll = () => {
      this.timer = setInterval(async () => {
    return new Promise((resolve) => {
      let retries = 0;
      const poll = async () => {
        retries++;
        try {
          const queryRes = await this.props.dispatchCreditOrderQuery({
@@ -401,40 +403,47 @@
          const status = queryRes?.creditOrderStatus;
          if (status === 'DOING' || status === 'DONE') {
            clearInterval(this.timer);
            Taro.hideLoading();
            this.resetLoading();
            this.creditOrderSuccess(queryRes);
            resolve();
            return;
          }
          if (status === 'REVOKED' || status === 'EXPIRED') {
            clearInterval(this.timer);
            Taro.hideLoading();
            this.resetLoading();
            Taro.showToast({ title: '订单已取消或失效', icon: 'none' });
            resolve();
            return;
          }
          if (retries >= maxRetries) {
            clearInterval(this.timer);
            Taro.hideLoading();
            this.resetLoading();
            Taro.showToast({ title: '查询超时,请稍后再试', icon: 'none' });
            resolve();
            return;
          }
          // 继续轮询
          this.timer = setTimeout(poll, interval);
        } catch (err) {
          console.error('pollCreditOrderStatus error:', err);
          if (retries >= maxRetries) {
            clearInterval(this.timer);
            Taro.hideLoading();
            this.resetLoading();
            Taro.showToast({ title: '查询订单状态失败', icon: 'none' });
            resolve();
            return;
          }
          // 出错也继续重试
          this.timer = setTimeout(poll, interval);
        }
      }, interval);
    };
      };
    poll();
      poll();
    });
  }
  // 统一重置 loading 状态