47 lines
933 B
TypeScript
47 lines
933 B
TypeScript
import type { TicketInfoType, TokenInfoType } from "react-rotate-captcha";
|
|
import { getCaptcha, VerfiyCaptcha } from "@/api/captcha/api.ts";
|
|
|
|
export type ActionType = {
|
|
code: 0 | 1;
|
|
msg: string;
|
|
};
|
|
let image: string = "";
|
|
|
|
export async function get(): Promise<TokenInfoType> {
|
|
const res: any = await getCaptcha();
|
|
image = res.data.str;
|
|
return res;
|
|
}
|
|
|
|
export function isSupportWebp() {
|
|
try {
|
|
return (
|
|
document
|
|
.createElement("canvas")
|
|
.toDataURL("image/webp", 0.5)
|
|
.indexOf("data:image/webp") === 0
|
|
);
|
|
} catch (err) {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
export async function load() {
|
|
return image;
|
|
}
|
|
|
|
export function sleep(time: number) {
|
|
return new Promise((resolve) => {
|
|
setTimeout(() => resolve(true), time);
|
|
});
|
|
}
|
|
|
|
export async function verify(token: string, deg: number): Promise<TicketInfoType> {
|
|
const data: any = {
|
|
token: token,
|
|
deg: deg,
|
|
};
|
|
const res: any = await VerfiyCaptcha(data);
|
|
return res;
|
|
}
|