This commit is contained in:
Mrx
2026-03-01 18:05:18 +08:00
parent b8defa47ab
commit 75cda811e2
2 changed files with 94 additions and 39 deletions

View File

@@ -35,7 +35,7 @@
<input v-model="formData.mobile" id="mobile" type="tel" placeholder="请输入手机号" <input v-model="formData.mobile" id="mobile" type="tel" placeholder="请输入手机号"
class="flex-1 border-none outline-none" @click="handleInputClick" /> class="flex-1 border-none outline-none" @click="handleInputClick" />
</div> </div>
<div class="flex items-center py-3 border-b border-gray-100"> <div v-if="needVerificationCode" class="flex items-center py-3 border-b border-gray-100">
<label for="verificationCode" class="w-20 font-medium text-gray-700">验证码</label> <label for="verificationCode" class="w-20 font-medium text-gray-700">验证码</label>
<input v-model="formData.verificationCode" id="verificationCode" placeholder="请输入验证码" <input v-model="formData.verificationCode" id="verificationCode" placeholder="请输入验证码"
maxlength="6" class="flex-1 border-none outline-none" @click="handleInputClick" /> maxlength="6" class="flex-1 border-none outline-none" @click="handleInputClick" />
@@ -385,6 +385,11 @@ const isIdCardValid = computed(() => /^\d{17}[\dX]$/i.test(formData.idCard));
const isLoggedIn = computed(() => userStore.isLoggedIn); const isLoggedIn = computed(() => userStore.isLoggedIn);
// 是否需要短信验证码marriage 产品使用拼图验证,不需要短信验证码)
const needVerificationCode = computed(() => {
return props.feature !== 'marriage';
});
const buttonText = computed(() => { const buttonText = computed(() => {
return isLoggedIn.value ? '立即查询' : '前往登录'; return isLoggedIn.value ? '立即查询' : '前往登录';
}); });
@@ -505,17 +510,25 @@ const isHasInput = (input) => {
function handleBindSuccess() { function handleBindSuccess() {
if (pendingPayment.value) { if (pendingPayment.value) {
pendingPayment.value = false; pendingPayment.value = false;
if (!needVerificationCode.value) {
submitRequestWithCaptcha();
} else {
submitRequest(); submitRequest();
} }
} }
}
// 处理登录成功的回调 // 处理登录成功的回调
function handleLoginSuccess() { function handleLoginSuccess() {
if (pendingPayment.value) { if (pendingPayment.value) {
pendingPayment.value = false; pendingPayment.value = false;
if (!needVerificationCode.value) {
submitRequestWithCaptcha();
} else {
submitRequest(); submitRequest();
} }
} }
}
// 处理输入框点击事件 // 处理输入框点击事件
const handleInputClick = async () => { const handleInputClick = async () => {
@@ -555,6 +568,7 @@ function handleSubmit() {
return; return;
} }
// 基本字段验证
if ( if (
!validateField("name", formData.name, (v) => v, "请输入姓名") || !validateField("name", formData.name, (v) => v, "请输入姓名") ||
!validateField( !validateField(
@@ -568,25 +582,85 @@ function handleSubmit() {
formData.idCard, formData.idCard,
(v) => isIdCardValid.value, (v) => isIdCardValid.value,
"请输入有效的身份证号码" "请输入有效的身份证号码"
) || )
!validateField( ) {
return;
}
// 短信验证码验证(仅非 marriage 产品需要)
if (needVerificationCode.value) {
if (!validateField(
"verificationCode", "verificationCode",
formData.verificationCode, formData.verificationCode,
(v) => v, (v) => v,
"请输入验证码" "请输入验证码"
) )) {
) {
return; return;
} }
}
// 检查是否需要绑定手机号 // 检查是否需要绑定手机号
if (!userStore.mobile) { if (!userStore.mobile) {
pendingPayment.value = true; pendingPayment.value = true;
dialogStore.openBindPhone(); dialogStore.openBindPhone();
} else {
// marriage 产品使用拼图验证
if (!needVerificationCode.value) {
submitRequestWithCaptcha();
} else { } else {
submitRequest(); 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() { async function submitRequest() {
const req = { const req = {
@@ -595,37 +669,18 @@ async function submitRequest() {
mobile: formData.mobile, mobile: formData.mobile,
code: formData.verificationCode code: formData.verificationCode
}; };
const reqStr = JSON.stringify(req); const requestData = buildQueryRequestData(req);
const encodeData = aesEncrypt(reqStr, "ff83609b2b24fc73196aac3d3dfb874f"); const apiUrl = getQueryApiUrl();
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 { data, error } = await useApiFetch(apiUrl) const { data, error } = await useApiFetch(apiUrl)
.post(requestData) .post(requestData)
.json(); .json();
if (data.value.code === 200) { if (data.value?.code === 200) {
queryId.value = data.value.data.id; onQuerySuccess(data.value);
}
// 推广查询需要保存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);
}
}
async function sendVerificationCode() { async function sendVerificationCode() {
if (isCountingDown.value || !isPhoneNumberValid.value) return; if (isCountingDown.value || !isPhoneNumberValid.value) return;

View File

@@ -149,12 +149,12 @@ const router = createRouter({
component: () => import('@/views/AgentServiceAgreement.vue'), component: () => import('@/views/AgentServiceAgreement.vue'),
meta: { title: '信息技术服务合同' }, meta: { title: '信息技术服务合同' },
}, },
{ // {
path: '/inquire/marriage', // path: '/inquire/marriage',
name: 'inquire-marriage', // name: 'inquire-marriage',
component: () => import('@/views/Maintenance.vue'), // component: () => import('@/views/Maintenance.vue'),
meta: { title: '维护通知' }, // meta: { title: '维护通知' },
}, // },
{ {
path: '/inquire/:feature', path: '/inquire/:feature',
name: 'inquire', name: 'inquire',