Quellcode durchsuchen

修改认证结果,提交失败跳转回信息页面

yuanmingze vor 2 Monaten
Ursprung
Commit
99ab99f412
2 geänderte Dateien mit 21 neuen und 9 gelöschten Zeilen
  1. 16 3
      src/hooks/useInvoice.ts
  2. 5 6
      src/views/pedding-face-recognition/index.vue

+ 16 - 3
src/hooks/useInvoice.ts

@@ -1,5 +1,5 @@
 import { ref, reactive } from 'vue'
-import { useRouter } from 'vue-router'
+import { useRouter, useRoute } from 'vue-router'
 import { showToast, showSuccessToast } from 'vant'
 import { getStatusApi, submitInvoiceApplyApi } from '@/services/modules/invoiceInformation'
 import type { PushRecordIdRequest } from '@/services/modules/invoiceInformation/type.d.ts'
@@ -23,6 +23,8 @@ export function useInvoice() {
   const userStore = useUserStore()
   const router = useRouter()
 
+  const route = useRoute()
+
   // state
   const btnDisabled = ref(false)
   const statusMap = ref<ToStatus>({})
@@ -73,20 +75,31 @@ export function useInvoice() {
    */
   const submitInvoiceApply = async () => {
     try {
+      // 1. 提交流程
       const res = await submitInvoiceApplyApi(params)
+      // 2. 成功逻辑
       if (res.code === 0 && res.data) {
         showSuccessToast('提交成功')
         setTimeout(() => {
           userStore.LogOut()
           router.replace({ path: '/success' })
         }, 800)
-      } else {
-        showToast(res.msg)
+        return
       }
+      // 3. 失败逻辑(接口返回的错误)
+      showToast(res.msg)
     } catch (err: any) {
+      // 4. 异常逻辑
       console.error('提交失败', err)
       showToast(err.message)
     }
+
+    // 5. 失败后统一处理 —— 判断当前页面是否需要跳转
+    if (route.path !== '/h5/invoice-information/index') {
+      setTimeout(() => {
+        router.replace('/h5/invoice-information/index')
+      }, 1800)
+    }
   }
 
   return {

+ 5 - 6
src/views/pedding-face-recognition/index.vue

@@ -45,19 +45,18 @@ const getFaceAuthResult = async () => {
       // 已认证或无需认证提交跳转
       if (rzzt === 'NO_REQUIRED_AUTHENTICATION') {
         submitInvoiceApply()
-      } else {
-        // 认证失败重定向到发票信息页面
-        router.replace({
-          path: '/invoice-information',
-        })
       }
     } else {
-      showToast('认证失败,请刷新页面后重试')
+      showToast('扫脸认证失败,请重试')
     }
   } catch (err) {
     console.error('获取认证结果失败', err)
     showToast('网络错误,请稍后重试')
   }
+
+  setTimeout(() => {
+    router.replace('/h5/invoice-information/index')
+  }, 1800)
 }
 
 onMounted(() => {