소스 검색

对未支付订单进行刷新操作

lex 2 년 전
부모
커밋
74d979be05
1개의 변경된 파일39개의 추가작업 그리고 21개의 파일을 삭제
  1. 39 21
      src/student/payment-result/index.tsx

+ 39 - 21
src/student/payment-result/index.tsx

@@ -36,7 +36,9 @@ export default defineComponent({
       goodsInfos: [] as any,
       background: 'transparent',
       color: '#fff',
-      backIconColor: 'white' as any
+      backIconColor: 'white' as any,
+      timer: null as any,
+      timerCount: 0 // 执行次数
     })
     const form = reactive({
       resionList: [] as any,
@@ -65,6 +67,20 @@ export default defineComponent({
       }
     }
 
+    // 定时任务
+    const onTimeout = async () => {
+      // 判断订单状态,如果未支付则刷新
+      if (['WAIT_PAY', 'PAYING'].includes(state.orders.status) && state.timerCount <= 10) {
+        state.timer = setTimeout(async () => {
+          state.timerCount += 1
+          await getDetails()
+          onTimeout()
+        }, 3000)
+      } else {
+        clearTimeout(state.timer)
+      }
+    }
+
     const onRefund = async () => {
       showConfirmDialog({
         message: '您是否确定撤销退费?'
@@ -162,29 +178,31 @@ export default defineComponent({
       }
     }
 
-    const popStateEvent = () => {
-      const ua = window.navigator.userAgent.toLowerCase()
-      if (browser().weixin) {
-        // 关闭微信
-        ;(window as any).WeixinJSBridge.call('closeWindow')
-      } else if (ua.indexOf('alipay') != -1) {
-        // 关闭支付宝
-        ;(window as any).AlipayJSBridge.call('closeWebview') // 支付宝浏览器
-      } else {
-        router.back()
-      }
-    }
+    // const popStateEvent = () => {
+    //   const ua = window.navigator.userAgent.toLowerCase()
+    //   if (browser().weixin) {
+    //     // 关闭微信
+    //     ;(window as any).WeixinJSBridge.call('closeWindow')
+    //   } else if (ua.indexOf('alipay') != -1) {
+    //     // 关闭支付宝
+    //     ;(window as any).AlipayJSBridge.call('closeWebview') // 支付宝浏览器
+    //   } else {
+    //     router.back()
+    //   }
+    // }
 
-    onBeforeRouteLeave((leaveGuard: any) => {
-      // 判断是否是微信
-      if (browser().weixin && !['/payResult', '/payDefine'].includes(leaveGuard.path)) {
-        popStateEvent()
-      }
-    })
+    // onBeforeRouteLeave((leaveGuard: any) => {
+    //   // 判断是否是微信
+    //   alert(leaveGuard.path)
+    //   if (browser().weixin && !['/preApply'].includes(leaveGuard.path)) {
+    //     popStateEvent()
+    //   }
+    // })
 
-    onMounted(() => {
-      getDetails()
+    onMounted(async () => {
+      await getDetails()
       getDefaultParams()
+      await onTimeout()
       useEventListener(document, 'scroll', () => {
         const { y } = useWindowScroll()
         if (y.value > 52) {