forked from gxwebsoft/mp-10550
fix(order): 解决支付取消后加载状态未正确重置问题
- 在支付流程中添加 skipFinallyResetPayLoading 标志来控制加载状态 - 检测用户取消支付情况并跳转到待付款订单列表页面 - 优化支付取消后的页面导航逻辑,支持 redirectTo 和 navigateTo 两种方式 - 修改订单列表中的按钮文案"取消订单"为"取消" - 修改订单列表中的按钮文案"立即支付"为"继续支付"
This commit is contained in:
@@ -430,6 +430,7 @@ const OrderConfirm = () => {
|
|||||||
* 统一支付入口
|
* 统一支付入口
|
||||||
*/
|
*/
|
||||||
const onPay = async (goods: ShopGoods) => {
|
const onPay = async (goods: ShopGoods) => {
|
||||||
|
let skipFinallyResetPayLoading = false
|
||||||
try {
|
try {
|
||||||
setPayLoading(true)
|
setPayLoading(true)
|
||||||
|
|
||||||
@@ -603,6 +604,29 @@ const OrderConfirm = () => {
|
|||||||
// })
|
// })
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
const message = String(error?.message || '')
|
const message = String(error?.message || '')
|
||||||
|
const isUserCancelPay =
|
||||||
|
message.includes('用户取消支付') ||
|
||||||
|
message.includes('取消支付') ||
|
||||||
|
message.toLowerCase().includes('requestpayment:fail cancel') ||
|
||||||
|
message.toLowerCase().includes('cancel')
|
||||||
|
|
||||||
|
// 用户取消支付:跳转到待付款列表,方便继续支付
|
||||||
|
if (isUserCancelPay) {
|
||||||
|
skipFinallyResetPayLoading = true
|
||||||
|
setPayLoading(false)
|
||||||
|
const url = '/user/order/order?statusFilter=0'
|
||||||
|
try {
|
||||||
|
await Taro.redirectTo({ url })
|
||||||
|
} catch (_e) {
|
||||||
|
try {
|
||||||
|
await Taro.navigateTo({ url })
|
||||||
|
} catch (_e2) {
|
||||||
|
// ignore
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
const isOutOfDeliveryRange =
|
const isOutOfDeliveryRange =
|
||||||
message.includes('不在配送范围') ||
|
message.includes('不在配送范围') ||
|
||||||
message.includes('配送范围') ||
|
message.includes('配送范围') ||
|
||||||
@@ -632,7 +656,9 @@ const OrderConfirm = () => {
|
|||||||
Taro.showToast({ title: message || '支付失败,请重试', icon: 'none' })
|
Taro.showToast({ title: message || '支付失败,请重试', icon: 'none' })
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
setPayLoading(false)
|
if (!skipFinallyResetPayLoading) {
|
||||||
|
setPayLoading(false)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -820,12 +820,12 @@ function OrderList(props: OrderListProps) {
|
|||||||
<Button size={'small'} onClick={(e) => {
|
<Button size={'small'} onClick={(e) => {
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
void cancelOrder(item);
|
void cancelOrder(item);
|
||||||
}}>取消订单</Button>
|
}}>取消</Button>
|
||||||
{(!item.createTime || !isPaymentExpired(item.createTime, 24)) && (
|
{(!item.createTime || !isPaymentExpired(item.createTime, 24)) && (
|
||||||
<Button size={'small'} type="primary" onClick={(e) => {
|
<Button size={'small'} type="primary" onClick={(e) => {
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
void payOrder(item);
|
void payOrder(item);
|
||||||
}}>立即支付</Button>
|
}}>继续支付</Button>
|
||||||
)}
|
)}
|
||||||
</Space>
|
</Space>
|
||||||
)}
|
)}
|
||||||
|
|||||||
Reference in New Issue
Block a user