f
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
import { showToast } from "vant";
|
import { showToast, showLoadingToast, closeToast } from "vant";
|
||||||
import useApiFetch from "@/composables/useApiFetch";
|
import useApiFetch from "@/composables/useApiFetch";
|
||||||
|
|
||||||
// 阿里云验证码场景 ID
|
// 阿里云验证码场景 ID
|
||||||
@@ -117,42 +117,53 @@ export function useAliyunCaptcha() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
window.__captchaVerifyCallback = async (captchaVerifyParam) => {
|
const loading = showLoadingToast({
|
||||||
window.__lastBizResponse = null;
|
message: "安全验证加载中...",
|
||||||
const { data, error } = await bizVerify(captchaVerifyParam);
|
forbidClick: true,
|
||||||
const result = data?.value ?? data;
|
duration: 0,
|
||||||
if (error?.value || !result) {
|
loadingType: "spinner",
|
||||||
return { captchaResult: false, bizResult: false };
|
});
|
||||||
|
|
||||||
|
try {
|
||||||
|
window.__captchaVerifyCallback = async (captchaVerifyParam) => {
|
||||||
|
window.__lastBizResponse = null;
|
||||||
|
const { data, error } = await bizVerify(captchaVerifyParam);
|
||||||
|
const result = data?.value ?? data;
|
||||||
|
if (error?.value || !result) {
|
||||||
|
return { captchaResult: false, bizResult: false };
|
||||||
|
}
|
||||||
|
window.__lastBizResponse = result;
|
||||||
|
const captchaOk = result.captchaVerifyResult !== false;
|
||||||
|
const bizOk = result.code === 200;
|
||||||
|
return { captchaResult: captchaOk, bizResult: bizOk };
|
||||||
|
};
|
||||||
|
|
||||||
|
window.__onBizResultCallback = (bizResult) => {
|
||||||
|
if (
|
||||||
|
bizResult === true &&
|
||||||
|
window.__lastBizResponse &&
|
||||||
|
typeof window.__onCaptchaBizSuccess === "function"
|
||||||
|
) {
|
||||||
|
window.__onCaptchaBizSuccess(window.__lastBizResponse);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
await ensureCaptchaInit();
|
||||||
|
|
||||||
|
// 首次初始化时 SDK 会异步调用 getInstance,需等待实例就绪后再 show
|
||||||
|
if (captchaReadyPromise) {
|
||||||
|
await captchaReadyPromise;
|
||||||
|
captchaReadyPromise = null;
|
||||||
}
|
}
|
||||||
window.__lastBizResponse = result;
|
if (!window.captcha) {
|
||||||
const captchaOk = result.captchaVerifyResult !== false;
|
showToast({ message: "验证码未加载,请刷新页面重试" });
|
||||||
const bizOk = result.code === 200;
|
return;
|
||||||
return { captchaResult: captchaOk, bizResult: bizOk };
|
|
||||||
};
|
|
||||||
|
|
||||||
window.__onBizResultCallback = (bizResult) => {
|
|
||||||
if (
|
|
||||||
bizResult === true &&
|
|
||||||
window.__lastBizResponse &&
|
|
||||||
typeof window.__onCaptchaBizSuccess === "function"
|
|
||||||
) {
|
|
||||||
window.__onCaptchaBizSuccess(window.__lastBizResponse);
|
|
||||||
}
|
}
|
||||||
};
|
window.__onCaptchaBizSuccess = onSuccess;
|
||||||
|
window.captcha.show();
|
||||||
await ensureCaptchaInit();
|
} finally {
|
||||||
|
closeToast();
|
||||||
// 首次初始化时 SDK 会异步调用 getInstance,需等待实例就绪后再 show
|
|
||||||
if (captchaReadyPromise) {
|
|
||||||
await captchaReadyPromise;
|
|
||||||
captchaReadyPromise = null;
|
|
||||||
}
|
}
|
||||||
if (!window.captcha) {
|
|
||||||
showToast({ message: "验证码未加载,请刷新页面重试" });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
window.__onCaptchaBizSuccess = onSuccess;
|
|
||||||
window.captcha.show();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return { runWithCaptcha };
|
return { runWithCaptcha };
|
||||||
|
|||||||
Reference in New Issue
Block a user