add limit

This commit is contained in:
Mrx
2026-02-26 13:15:09 +08:00
parent fb8dea93a0
commit d6e460d7b6
8 changed files with 305 additions and 67 deletions

View File

@@ -35,7 +35,8 @@
<input v-model="formData.mobile" id="mobile" type="tel" placeholder="请输入手机号"
class="flex-1 border-none outline-none" @click="handleInputClick" />
</div>
<div class="flex items-center py-3 border-b border-gray-100">
<!-- 验证码输入框仅需要短信验证码的产品显示 -->
<div v-if="needSmsCode" class="flex items-center py-3 border-b border-gray-100">
<label for="verificationCode" class="w-20 font-medium text-gray-700">验证码</label>
<input v-model="formData.verificationCode" id="verificationCode" placeholder="请输入验证码"
maxlength="6" class="flex-1 border-none outline-none" @click="handleInputClick" />
@@ -133,6 +134,7 @@ import { useUserStore } from "@/stores/userStore";
import { useDialogStore } from "@/stores/dialogStore";
import { useEnv } from "@/composables/useEnv";
import { showConfirmDialog } from "vant";
import { useAliyunCaptcha } from "@/composables/useAliyunCaptcha";
import Payment from "@/components/Payment.vue";
import BindPhoneOnlyDialog from "@/components/BindPhoneOnlyDialog.vue";
@@ -200,6 +202,7 @@ const dialogStore = useDialogStore();
const userStore = useUserStore();
const { isWeChat } = useEnv();
const appStore = useAppStore();
const { runWithCaptcha } = useAliyunCaptcha();
// 响应式数据
const showPayment = ref(false);
@@ -210,6 +213,14 @@ const trapezoidBgImage = ref('');
const isCountingDown = ref(false);
const countdown = ref(60);
// 不需要短信验证码的产品列表(使用拼图验证)
const noSmsCodeRequiredProducts = ['marriage'];
// 判断当前产品是否需要短信验证码
const needSmsCode = computed(() => {
return !noSmsCodeRequiredProducts.includes(props.feature);
});
// 使用传入的featureData或创建响应式引用
const featureData = computed(() => props.featureData || {});
@@ -349,34 +360,75 @@ function handleSubmit() {
formData.idCard,
(v) => isIdCardValid.value,
"请输入有效的身份证号码"
) ||
!validateField(
"verificationCode",
formData.verificationCode,
(v) => v,
"请输入验证码"
)
) {
return;
}
// 需要短信验证码的产品,校验验证码
if (needSmsCode.value && !formData.verificationCode) {
showToast({ message: "请输入验证码" });
return;
}
// 不需要登录也能查询,直接提交请求
// 如果是已登录用户在微信环境且未绑定手机号,提示绑定(但不强制)
if (isLoggedIn.value && !userStore.mobile && props.type !== 'promotion' && isWeChat.value) {
pendingPayment.value = true;
dialogStore.openBindPhone();
} else {
submitRequest();
// 不需要短信验证码的产品,使用拼图验证
if (!needSmsCode.value) {
runWithCaptcha(
(captchaVerifyParam) => submitRequest(captchaVerifyParam),
(res) => {
if (res.code === 200) {
handleQuerySuccess(res);
}
}
);
} else {
// 需要短信验证码的产品,直接提交
submitRequest().then(({ data, error }) => {
if (data?.code === 200) {
handleQuerySuccess(data);
}
});
}
}
}
async function submitRequest() {
// 处理查询成功
function handleQuerySuccess(res) {
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);
const tokenVersion = import.meta.env.VITE_TOKEN_VERSION || "1.1";
localStorage.setItem("tokenVersion", tokenVersion);
}
showPayment.value = true;
emit('submit-success', res.data);
}
async function submitRequest(captchaVerifyParam = null) {
const req = {
name: formData.name,
id_card: formData.idCard,
mobile: formData.mobile,
code: formData.verificationCode
mobile: formData.mobile
};
// 需要短信验证码的产品,添加 code 字段
if (needSmsCode.value) {
req.code = formData.verificationCode;
}
// 不需要短信验证码的产品,添加拼图验证参数
if (captchaVerifyParam) {
req.captchaVerifyParam = captchaVerifyParam;
}
const reqStr = JSON.stringify(req);
const encodeData = aesEncrypt(
reqStr,
@@ -397,22 +449,7 @@ async function submitRequest() {
.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);
// ⚠️ 重要:保存 token 后立即设置 tokenVersion防止被 checkTokenVersion 清除
const tokenVersion = import.meta.env.VITE_TOKEN_VERSION || "1.1";
localStorage.setItem("tokenVersion", tokenVersion);
}
showPayment.value = true;
emit('submit-success', data.value.data);
}
return { data: data.value, error };
}
async function sendVerificationCode() {
@@ -422,22 +459,27 @@ async function sendVerificationCode() {
return;
}
const { data, error } = await useApiFetch("/auth/sendSms")
.post({ mobile: formData.mobile, actionType: "query" })
.json();
if (!error.value && data.value.code === 200) {
showToast({ message: "验证码发送成功", type: "success" });
startCountdown();
nextTick(() => {
const verificationCodeInput = document.getElementById('verificationCode');
if (verificationCodeInput) {
verificationCodeInput.focus();
// 使用阿里云滑块验证码
runWithCaptcha(
(captchaVerifyParam) =>
useApiFetch("/auth/sendSms")
.post({ mobile: formData.mobile, actionType: "query", captchaVerifyParam })
.json(),
(res) => {
if (res.code === 200) {
showToast({ message: "验证码发送成功", type: "success" });
startCountdown();
nextTick(() => {
const verificationCodeInput = document.getElementById('verificationCode');
if (verificationCodeInput) {
verificationCodeInput.focus();
}
});
} else {
showToast({ message: res.msg || "验证码发送失败,请重试" });
}
});
} else {
showToast({ message: "验证码发送失败,请重试" });
}
}
);
}
let timer = null;