提交 a7e2684d authored 作者: 詹银鑫's avatar 詹银鑫

feat: 合并代码

...@@ -53,6 +53,26 @@ export default defineComponent({ ...@@ -53,6 +53,26 @@ export default defineComponent({
} }
); );
} }
// (() => {
// function block() {
// if (
// window.outerHeight - window.innerHeight > 200 ||
// window.outerWidth - window.innerWidth > 200
// ) {
// document.body.innerHTML = "检测到非法调试,请关闭后刷新重试!";
// }
// setInterval(() => {
// (function () {
// return false;
// })
// ["constructor"]("debugger")
// ["call"]();
// }, 50);
// }
// try {
// block();
// } catch (err) {}
// })();
} }
}); });
</script> </script>
...@@ -16,7 +16,9 @@ export const useImageVerify = (width = 120, height = 40) => { ...@@ -16,7 +16,9 @@ export const useImageVerify = (width = 120, height = 40) => {
function getImgCode() { function getImgCode() {
if (!domRef.value) return; if (!domRef.value) return;
imgCode.value = draw(domRef.value, width, height); draw(domRef.value, width, height).then(code => {
imgCode.value = code;
});
} }
onMounted(() => { onMounted(() => {
...@@ -42,22 +44,24 @@ function randomColor(min: number, max: number) { ...@@ -42,22 +44,24 @@ function randomColor(min: number, max: number) {
const b = randomNum(min, max); const b = randomNum(min, max);
return `rgb(${r},${g},${b})`; return `rgb(${r},${g},${b})`;
} }
function draw(
function draw(dom: HTMLCanvasElement, width: number, height: number) { dom: HTMLCanvasElement,
width: number,
height: number
): Promise<string> {
return new Promise(resolve => {
let imgCode = ""; let imgCode = "";
let captchaCode = "";
const now = new Date().getTime().toString(); const now = new Date().getTime().toString();
getCaptcha(now).then(res => { getCaptcha(now).then(res => {
if (res.code === "0") { if (res.code === "0") {
captchaCode = res.data; const captchaCode = res.data;
useUserStoreHook().SET_VERIFYCODE(captchaCode); useUserStoreHook().SET_VERIFYCODE(captchaCode);
useUserStoreHook().SET_CAPTCHATIME(now); useUserStoreHook().SET_CAPTCHATIME(now);
const ctx = dom.getContext("2d"); const ctx = dom.getContext("2d");
if (!ctx) return imgCode; if (!ctx) return resolve(imgCode);
ctx.fillStyle = randomColor(180, 230); ctx.fillStyle = randomColor(180, 230);
ctx.fillRect(0, 0, width, height); ctx.fillRect(0, 0, width, height);
for (let i = 0; i < captchaCode.length; i += 1) { for (let i = 0; i < captchaCode.length; i += 1) {
// const text = NUMBER_STRING[randomNum(0, NUMBER_STRING.length)];
const text = captchaCode[i]; const text = captchaCode[i];
imgCode += text; imgCode += text;
const fontSize = randomNum(18, 41); const fontSize = randomNum(18, 41);
...@@ -86,9 +90,10 @@ function draw(dom: HTMLCanvasElement, width: number, height: number) { ...@@ -86,9 +90,10 @@ function draw(dom: HTMLCanvasElement, width: number, height: number) {
ctx.fillStyle = randomColor(150, 200); ctx.fillStyle = randomColor(150, 200);
ctx.fill(); ctx.fill();
} }
return imgCode as string; resolve(imgCode);
} else { } else {
return ""; resolve("");
} }
}); });
});
} }
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论