提交 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,53 +44,56 @@ function randomColor(min: number, max: number) { ...@@ -42,53 +44,56 @@ 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,
let imgCode = ""; width: number,
let captchaCode = ""; height: number
const now = new Date().getTime().toString(); ): Promise<string> {
getCaptcha(now).then(res => { return new Promise(resolve => {
if (res.code === "0") { let imgCode = "";
captchaCode = res.data; const now = new Date().getTime().toString();
useUserStoreHook().SET_VERIFYCODE(captchaCode); getCaptcha(now).then(res => {
useUserStoreHook().SET_CAPTCHATIME(now); if (res.code === "0") {
const ctx = dom.getContext("2d"); const captchaCode = res.data;
if (!ctx) return imgCode; useUserStoreHook().SET_VERIFYCODE(captchaCode);
ctx.fillStyle = randomColor(180, 230); useUserStoreHook().SET_CAPTCHATIME(now);
ctx.fillRect(0, 0, width, height); const ctx = dom.getContext("2d");
for (let i = 0; i < captchaCode.length; i += 1) { if (!ctx) return resolve(imgCode);
// const text = NUMBER_STRING[randomNum(0, NUMBER_STRING.length)]; ctx.fillStyle = randomColor(180, 230);
const text = captchaCode[i]; ctx.fillRect(0, 0, width, height);
imgCode += text; for (let i = 0; i < captchaCode.length; i += 1) {
const fontSize = randomNum(18, 41); const text = captchaCode[i];
const deg = randomNum(-30, 30); imgCode += text;
ctx.font = `${fontSize}px Simhei`; const fontSize = randomNum(18, 41);
ctx.textBaseline = "top"; const deg = randomNum(-30, 30);
ctx.fillStyle = randomColor(80, 150); ctx.font = `${fontSize}px Simhei`;
ctx.save(); ctx.textBaseline = "top";
ctx.translate(30 * i + 15, 15); ctx.fillStyle = randomColor(80, 150);
ctx.rotate((deg * Math.PI) / 180); ctx.save();
ctx.fillText(text, -15 + 5, -15); ctx.translate(30 * i + 15, 15);
ctx.restore(); ctx.rotate((deg * Math.PI) / 180);
} ctx.fillText(text, -15 + 5, -15);
for (let i = 0; i < 5; i += 1) { ctx.restore();
ctx.beginPath(); }
ctx.moveTo(randomNum(0, width), randomNum(0, height)); for (let i = 0; i < 5; i += 1) {
ctx.lineTo(randomNum(0, width), randomNum(0, height)); ctx.beginPath();
ctx.strokeStyle = randomColor(180, 230); ctx.moveTo(randomNum(0, width), randomNum(0, height));
ctx.closePath(); ctx.lineTo(randomNum(0, width), randomNum(0, height));
ctx.stroke(); ctx.strokeStyle = randomColor(180, 230);
} ctx.closePath();
for (let i = 0; i < 41; i += 1) { ctx.stroke();
ctx.beginPath(); }
ctx.arc(randomNum(0, width), randomNum(0, height), 1, 0, 2 * Math.PI); for (let i = 0; i < 41; i += 1) {
ctx.closePath(); ctx.beginPath();
ctx.fillStyle = randomColor(150, 200); ctx.arc(randomNum(0, width), randomNum(0, height), 1, 0, 2 * Math.PI);
ctx.fill(); ctx.closePath();
ctx.fillStyle = randomColor(150, 200);
ctx.fill();
}
resolve(imgCode);
} else {
resolve("");
} }
return imgCode as string; });
} else {
return "";
}
}); });
} }
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论