| | |
| | | componentWillUnmount() { |
| | | if (this.timer) { |
| | | clearInterval(this.timer); |
| | | clearTimeout(this.timer); |
| | | } |
| | | if (this.appShowListener) { |
| | | Taro.offAppShow(this.appShowListener); |
| | |
| | | } |
| | | |
| | | // 轮询查询信用订单状态 |
| | | 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({ |
| | |
| | | |
| | | 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 状态 |