fix(order): 解决支付取消后加载状态未正确重置问题
- 在支付流程中添加 skipFinallyResetPayLoading 标志来控制加载状态 - 检测用户取消支付情况并跳转到待付款订单列表页面 - 优化支付取消后的页面导航逻辑,支持 redirectTo 和 navigateTo 两种方式 - 修改订单列表中的按钮文案"取消订单"为"取消" - 修改订单列表中的按钮文案"立即支付"为"继续支付"
This commit is contained in:
@@ -430,6 +430,7 @@ const OrderConfirm = () => {
|
||||
* 统一支付入口
|
||||
*/
|
||||
const onPay = async (goods: ShopGoods) => {
|
||||
let skipFinallyResetPayLoading = false
|
||||
try {
|
||||
setPayLoading(true)
|
||||
|
||||
@@ -603,6 +604,29 @@ const OrderConfirm = () => {
|
||||
// })
|
||||
} catch (error: any) {
|
||||
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 =
|
||||
message.includes('不在配送范围') ||
|
||||
message.includes('配送范围') ||
|
||||
@@ -632,7 +656,9 @@ const OrderConfirm = () => {
|
||||
Taro.showToast({ title: message || '支付失败,请重试', icon: 'none' })
|
||||
}
|
||||
} finally {
|
||||
setPayLoading(false)
|
||||
if (!skipFinallyResetPayLoading) {
|
||||
setPayLoading(false)
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user