From 75cda811e2273fcbdc955c4571a801499c214f3c Mon Sep 17 00:00:00 2001 From: Mrx <18278715334@163.com> Date: Sun, 1 Mar 2026 18:05:18 +0800 Subject: [PATCH] f --- src/components/InquireForm.vue | 121 ++++++++++++++++++++++++--------- src/router/index.js | 12 ++-- 2 files changed, 94 insertions(+), 39 deletions(-) diff --git a/src/components/InquireForm.vue b/src/components/InquireForm.vue index c4a2bd4..5e02317 100644 --- a/src/components/InquireForm.vue +++ b/src/components/InquireForm.vue @@ -35,7 +35,7 @@ -
+
@@ -385,6 +385,11 @@ const isIdCardValid = computed(() => /^\d{17}[\dX]$/i.test(formData.idCard)); const isLoggedIn = computed(() => userStore.isLoggedIn); +// 是否需要短信验证码(marriage 产品使用拼图验证,不需要短信验证码) +const needVerificationCode = computed(() => { + return props.feature !== 'marriage'; +}); + const buttonText = computed(() => { return isLoggedIn.value ? '立即查询' : '前往登录'; }); @@ -505,7 +510,11 @@ const isHasInput = (input) => { function handleBindSuccess() { if (pendingPayment.value) { pendingPayment.value = false; - submitRequest(); + if (!needVerificationCode.value) { + submitRequestWithCaptcha(); + } else { + submitRequest(); + } } } @@ -513,7 +522,11 @@ function handleBindSuccess() { function handleLoginSuccess() { if (pendingPayment.value) { pendingPayment.value = false; - submitRequest(); + if (!needVerificationCode.value) { + submitRequestWithCaptcha(); + } else { + submitRequest(); + } } } @@ -555,6 +568,7 @@ function handleSubmit() { return; } + // 基本字段验证 if ( !validateField("name", formData.name, (v) => v, "请输入姓名") || !validateField( @@ -568,15 +582,21 @@ function handleSubmit() { formData.idCard, (v) => isIdCardValid.value, "请输入有效的身份证号码" - ) || - !validateField( + ) + ) { + return; + } + + // 短信验证码验证(仅非 marriage 产品需要) + if (needVerificationCode.value) { + if (!validateField( "verificationCode", formData.verificationCode, (v) => v, "请输入验证码" - ) - ) { - return; + )) { + return; + } } // 检查是否需要绑定手机号 @@ -584,10 +604,64 @@ function handleSubmit() { pendingPayment.value = true; dialogStore.openBindPhone(); } else { - submitRequest(); + // marriage 产品使用拼图验证 + if (!needVerificationCode.value) { + submitRequestWithCaptcha(); + } else { + submitRequest(); + } } } +function getQueryApiUrl() { + if (props.type === 'promotion') { + return `/query/service_agent/${props.feature}`; + } + return `/query/service/${props.feature}`; +} + +function buildQueryRequestData(payload) { + const reqStr = JSON.stringify(payload); + const encodeData = aesEncrypt(reqStr, "ff83609b2b24fc73196aac3d3dfb874f"); + const requestData = { data: encodeData }; + if (props.type === 'promotion') { + requestData.agent_identifier = props.linkIdentifier; + } + return requestData; +} + +function onQuerySuccess(res) { + if (res?.code === 200 && res?.data) { + queryId.value = res.data.id; + if (props.type === 'promotion') { + localStorage.setItem("token", res.data.accessToken); + localStorage.setItem("refreshAfter", res.data.refreshAfter); + localStorage.setItem("accessExpire", res.data.accessExpire); + } + showPayment.value = true; + emit('submit-success', res.data); + } +} + +// 不需要短信验证码的产品:点击查询时先弹出拼图验证,通过后携带 captcha_verify_param 请求 +function submitRequestWithCaptcha() { + const apiUrl = getQueryApiUrl(); + runWithCaptcha( + (captchaVerifyParam) => { + const payload = { + name: formData.name, + id_card: formData.idCard, + mobile: formData.mobile, + captcha_verify_param: captchaVerifyParam + }; + return useApiFetch(apiUrl).post(buildQueryRequestData(payload)).json(); + }, + (res) => { + onQuerySuccess(res); + } + ); +} + async function submitRequest() { const req = { name: formData.name, @@ -595,38 +669,19 @@ async function submitRequest() { mobile: formData.mobile, code: formData.verificationCode }; - const reqStr = JSON.stringify(req); - const encodeData = aesEncrypt(reqStr, "ff83609b2b24fc73196aac3d3dfb874f"); - - let apiUrl = ''; - let requestData = { data: encodeData }; - - if (props.type === 'promotion') { - apiUrl = `/query/service_agent/${props.feature}`; - requestData.agent_identifier = props.linkIdentifier; - } else { - apiUrl = `/query/service/${props.feature}`; - } + const requestData = buildQueryRequestData(req); + const apiUrl = getQueryApiUrl(); const { data, error } = await useApiFetch(apiUrl) .post(requestData) .json(); - if (data.value.code === 200) { - queryId.value = data.value.data.id; - - // 推广查询需要保存token - if (props.type === 'promotion') { - localStorage.setItem("token", data.value.data.accessToken); - localStorage.setItem("refreshAfter", data.value.data.refreshAfter); - localStorage.setItem("accessExpire", data.value.data.accessExpire); - } - - showPayment.value = true; - emit('submit-success', data.value.data); + if (data.value?.code === 200) { + onQuerySuccess(data.value); } } + async function sendVerificationCode() { if (isCountingDown.value || !isPhoneNumberValid.value) return; if (!isPhoneNumberValid.value) { diff --git a/src/router/index.js b/src/router/index.js index 2ebc21e..788a4e9 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -149,12 +149,12 @@ const router = createRouter({ component: () => import('@/views/AgentServiceAgreement.vue'), meta: { title: '信息技术服务合同' }, }, - { - path: '/inquire/marriage', - name: 'inquire-marriage', - component: () => import('@/views/Maintenance.vue'), - meta: { title: '维护通知' }, - }, + // { + // path: '/inquire/marriage', + // name: 'inquire-marriage', + // component: () => import('@/views/Maintenance.vue'), + // meta: { title: '维护通知' }, + // }, { path: '/inquire/:feature', name: 'inquire',