♻️ 重构gt返回逻辑

This commit is contained in:
BTMuli
2025-10-08 10:36:17 +08:00
parent 43c85afd1e
commit 3f219ebb82
2 changed files with 8 additions and 16 deletions

View File

@@ -48,7 +48,7 @@ declare function initGeetest(
async function displayBox( async function displayBox(
props: TGApp.BBS.Geetest.CreateRes, props: TGApp.BBS.Geetest.CreateRes,
): Promise<TGApp.BBS.Geetest.GeetestVerifyRes | false> { ): Promise<TGApp.BBS.Geetest.GeetestVerifyRes | false> {
return await new Promise<TGApp.BBS.Geetest.GeetestVerifyRes>((resolve) => { return await new Promise<TGApp.BBS.Geetest.GeetestVerifyRes | false>((resolve) => {
initGeetest( initGeetest(
{ {
gt: props.gt, gt: props.gt,
@@ -64,11 +64,12 @@ async function displayBox(
geetestEl.value.innerHTML = ""; geetestEl.value.innerHTML = "";
captchaObj.appendTo("#geetest"); captchaObj.appendTo("#geetest");
captchaObj.onReady(() => (show.value = true)); captchaObj.onReady(() => (show.value = true));
captchaObj.onSuccess(() => { captchaObj.onClose(() => {
const validate = captchaObj.getValidate(); const validate = captchaObj.getValidate();
show.value = false;
if (!validate) resolve(false);
resolve(validate); resolve(validate);
}); });
captchaObj.onClose(() => (show.value = false));
}, },
); );
}); });

View File

@@ -1,7 +1,7 @@
/** /**
* @file types/BBS/Geetest.d.ts * @file types/BBS/Geetest.d.ts
* @description 米游社Geetest 类型定义文件 * @description 米游社Geetest 类型定义文件
* @since Beta v0.7.2 * @since Beta v0.8.3
*/ */
declare namespace TGApp.BBS.Geetest { declare namespace TGApp.BBS.Geetest {
@@ -11,7 +11,6 @@ declare namespace TGApp.BBS.Geetest {
* @interface CreateResp * @interface CreateResp
* @extends TGApp.BBS.Response.BaseWithData * @extends TGApp.BBS.Response.BaseWithData
* @property {CreateRes} data - 极验验证数据 * @property {CreateRes} data - 极验验证数据
* @return CreateResp
*/ */
type CreateResp = TGApp.BBS.Response.BaseWithData<CreateRes>; type CreateResp = TGApp.BBS.Response.BaseWithData<CreateRes>;
@@ -23,7 +22,6 @@ declare namespace TGApp.BBS.Geetest {
* @property {string} challenge - 极验验证 challenge * @property {string} challenge - 极验验证 challenge
* @property {number} new_captcha - 极验验证 new_captcha * @property {number} new_captcha - 极验验证 new_captcha
* @property {number} success - 极验验证 success * @property {number} success - 极验验证 success
* @return CreateRes
*/ */
type CreateRes = { gt: string; challenge: string; new_captcha: number; success: number }; type CreateRes = { gt: string; challenge: string; new_captcha: number; success: number };
@@ -33,7 +31,6 @@ declare namespace TGApp.BBS.Geetest {
* @interface VerifyResp * @interface VerifyResp
* @extends TGApp.BBS.Response.Base * @extends TGApp.BBS.Response.Base
* @property {VerifyRes} data - 极验验证数据 * @property {VerifyRes} data - 极验验证数据
* @return VerifyResp
*/ */
type VerifyResp = TGApp.BBS.Response.BaseWithData<VerifyRes>; type VerifyResp = TGApp.BBS.Response.BaseWithData<VerifyRes>;
@@ -43,7 +40,6 @@ declare namespace TGApp.BBS.Geetest {
* @interface VerifyRes * @interface VerifyRes
* @property {string} challenge - 极验验证 challenge * @property {string} challenge - 极验验证 challenge
* @property {string} validate - 极验验证 validate * @property {string} validate - 极验验证 validate
* @return VerifyRes
*/ */
type VerifyRes = { challenge: string }; type VerifyRes = { challenge: string };
@@ -58,7 +54,6 @@ declare namespace TGApp.BBS.Geetest {
* @property {string} product - 极验验证 product * @property {string} product - 极验验证 product
* @property {string} width - 极验验证 width * @property {string} width - 极验验证 width
* @property {string} area - 极验验证 area * @property {string} area - 极验验证 area
* @return InitGeetestParams
*/ */
type InitGeetestParams = { type InitGeetestParams = {
gt: string; gt: string;
@@ -72,20 +67,17 @@ declare namespace TGApp.BBS.Geetest {
/** /**
* @description Geetest 插件 captchaObj * @description Geetest 插件 captchaObj
* @since Beta v0.7.2 * @since Beta v0.8.3
* @interface GeetestCaptcha * @interface GeetestCaptcha
* @property {Function} appendTo * @property {Function} appendTo
* @property {Function} getValidate * @property {Function} getValidate
* @property {Function} onSuccess
* @property {Function} onClose * @property {Function} onClose
* @property {Function} onReady * @property {Function} onReady
* @return GeetestCaptcha
*/ */
type GeetestCaptcha = { type GeetestCaptcha = {
appendTo: (selector: string) => void; appendTo: (selector: string) => void;
getValidate: () => GeetestVerifyRes; getValidate: () => Promise<GeetestVerifyRes>;
onSuccess: (callback: () => void) => void; onClose: (callback: () => void) => boolean;
onClose: (callback: () => void) => void;
onReady: (callback: () => void) => void; onReady: (callback: () => void) => void;
}; };
@@ -96,7 +88,6 @@ declare namespace TGApp.BBS.Geetest {
* @property {string} geetest_challenge * @property {string} geetest_challenge
* @property {string} geetest_validate * @property {string} geetest_validate
* @property {string} geetest_seccode * @property {string} geetest_seccode
* @return GeetestVerifyRes
*/ */
type GeetestVerifyRes = { type GeetestVerifyRes = {
geetest_challenge: string; geetest_challenge: string;