|
@@ -1,4 +1,4 @@
|
|
|
-import { ref, onMounted } from 'vue';
|
|
|
+import { onMounted, ref } from 'vue';
|
|
|
|
|
|
/**
|
|
|
* 绘制图形验证码
|
|
@@ -31,8 +31,7 @@ export const useImageVerify = (width = 120, height = 32) => {
|
|
|
};
|
|
|
|
|
|
function randomNum(min: number, max: number) {
|
|
|
- const num = Math.floor(Math.random() * (max - min) + min);
|
|
|
- return num;
|
|
|
+ return Math.floor(Math.random() * (max - min) + min);
|
|
|
}
|
|
|
|
|
|
function randomColor(min: number, max: number) {
|
|
@@ -44,14 +43,12 @@ function randomColor(min: number, max: number) {
|
|
|
|
|
|
function draw(dom: HTMLCanvasElement, width: number, height: number) {
|
|
|
let imgCode = '';
|
|
|
-
|
|
|
const Random_STRING: string = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
|
|
|
-
|
|
|
const ctx = dom.getContext('2d');
|
|
|
if (!ctx) return imgCode;
|
|
|
|
|
|
- ctx.fillStyle = randomColor(180, 230);
|
|
|
- ctx.fillRect(0, 0, width, height);
|
|
|
+ ctx.fillStyle = randomColor(255, 255);
|
|
|
+ ctx.fillRect(2, 0, width, height);
|
|
|
for (let i = 0; i < 4; i += 1) {
|
|
|
const text = Random_STRING[randomNum(0, Random_STRING.length)];
|
|
|
imgCode += text;
|