|
|
@@ -24,25 +24,21 @@
|
|
|
|
|
|
<script setup lang="ts">
|
|
|
import StepProgress from '@/components/StepProgress.vue'
|
|
|
-import { getFaceAuthInfoApi, getFaceAuthResultApi } from '@/services/modules/faceRecognition'
|
|
|
-import { ref, reactive, onBeforeMount, onMounted, onUnmounted } from 'vue'
|
|
|
-import { showToast } from 'vant'
|
|
|
-import { useInvoice } from '@/hooks/useInvoice'
|
|
|
+import { getFaceAuthInfoApi } from '@/services/modules/faceRecognition'
|
|
|
+import { ref, onBeforeMount } from 'vue'
|
|
|
import { useUserStore } from '@/stores/modules/user'
|
|
|
-import type { PushRecordIdRequest } from '@/services/modules/invoiceInformation/type.d.ts'
|
|
|
|
|
|
const userStore = useUserStore()
|
|
|
const etsUrl = ref('')
|
|
|
|
|
|
-const params = reactive<PushRecordIdRequest>({
|
|
|
- pushRecordId: userStore.pushRecordId,
|
|
|
-})
|
|
|
-
|
|
|
-// --- 初始化 Hooks ---
|
|
|
-const { submitInvoiceApply } = useInvoice()
|
|
|
// 获取认证链接
|
|
|
const getConfirmInvoiceInfo = async () => {
|
|
|
- const res = await getFaceAuthInfoApi(params)
|
|
|
+ const callbackUrl = window.location.origin + '/h5/pedding-face-recognition'
|
|
|
+ const obj = {
|
|
|
+ pushRecordId: userStore.pushRecordId,
|
|
|
+ callbackUrl: callbackUrl,
|
|
|
+ }
|
|
|
+ const res = await getFaceAuthInfoApi(obj)
|
|
|
if (res.code === 0 && res.data?.faceAuthUrl) {
|
|
|
etsUrl.value = res.data.faceAuthUrl
|
|
|
} else {
|
|
|
@@ -50,51 +46,8 @@ const getConfirmInvoiceInfo = async () => {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-// 获取认证结果
|
|
|
-const getFaceAuthResult = async () => {
|
|
|
- try {
|
|
|
- const res = await getFaceAuthResultApi(params)
|
|
|
- if (res.code === 0 && res.data?.success) {
|
|
|
- submitInvoiceApply()
|
|
|
- } else {
|
|
|
- showToast('认证失败,请刷新页面后重试')
|
|
|
- }
|
|
|
- } catch (err) {
|
|
|
- console.error('获取认证结果失败', err)
|
|
|
- showToast('网络错误,请稍后重试')
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-// 🧠 监听 iframe 发来的消息
|
|
|
-const handleMessage = (event: MessageEvent) => {
|
|
|
- // 忽略 React DevTools 的心跳消息
|
|
|
- if (event.data?.source === 'react-devtools-content-script') return
|
|
|
-
|
|
|
- console.log('📩 收到 iframe 消息:', event.data)
|
|
|
-
|
|
|
- if (event.data?.type === 'AUTH_DONE') {
|
|
|
- showToast('认证完成,跳转下一步')
|
|
|
- // 比如继续执行下一步逻辑
|
|
|
- } else if (event.data?.type === 'AUTH_ERROR') {
|
|
|
- showToast('认证失败:' + event.data.message)
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-onMounted(() => {
|
|
|
- window.addEventListener('message', handleMessage)
|
|
|
-})
|
|
|
-
|
|
|
-onUnmounted(() => {
|
|
|
- window.removeEventListener('message', handleMessage)
|
|
|
-})
|
|
|
-
|
|
|
onBeforeMount(() => {
|
|
|
getConfirmInvoiceInfo()
|
|
|
-
|
|
|
- // 模拟获取认证结果
|
|
|
- setTimeout(() => {
|
|
|
- getFaceAuthResult()
|
|
|
- }, 5000)
|
|
|
})
|
|
|
</script>
|
|
|
|