审计代码优化

This commit is contained in:
BianLzhaoMin 2024-08-30 17:45:46 +08:00
parent f00b9310bd
commit 8cfbf163c0
7 changed files with 1478 additions and 1222 deletions

View File

@ -4,27 +4,27 @@
* @param wait 延迟执行毫秒数 * @param wait 延迟执行毫秒数
* @param immediate true - 立即执行 false - 延迟执行 * @param immediate true - 立即执行 false - 延迟执行
*/ */
export const debounce = function(func, wait = 1000, immediate = true) { export const debounce = function (func, wait = 1000, immediate = true) {
let timer; let timer;
console.log(1); // console.log(1);
return function() { return function () {
console.log(123); // console.log(123);
let context = this, let context = this,
args = arguments; args = arguments;
if (timer) clearTimeout(timer); if (timer) clearTimeout(timer);
if (immediate) { if (immediate) {
let callNow = !timer; let callNow = !timer;
timer = setTimeout(() => { timer = setTimeout(() => {
timer = null; timer = null;
}, wait); }, wait);
if (callNow) func.apply(context, args); if (callNow) func.apply(context, args);
} else { } else {
timer = setTimeout(() => { timer = setTimeout(() => {
func.apply(context, args); func.apply(context, args);
}, wait) }, wait);
} }
} };
} };
/** /**
* @desc 函数节流 * @desc 函数节流
* @param func 函数 * @param func 函数
@ -32,25 +32,25 @@ export const debounce = function(func, wait = 1000, immediate = true) {
* @param type 1 使用表时间戳在时间段开始的时候触发 2 使用表定时器在时间段结束的时候触发 * @param type 1 使用表时间戳在时间段开始的时候触发 2 使用表定时器在时间段结束的时候触发
*/ */
export const throttle = (func, wait = 1000, type = 1) => { export const throttle = (func, wait = 1000, type = 1) => {
let previous = 0; let previous = 0;
let timeout; let timeout;
return function() { return function () {
let context = this; let context = this;
let args = arguments; let args = arguments;
if (type === 1) { if (type === 1) {
let now = Date.now(); let now = Date.now();
if (now - previous > wait) { if (now - previous > wait) {
func.apply(context, args); func.apply(context, args);
previous = now; previous = now;
} }
} else if (type === 2) { } else if (type === 2) {
if (!timeout) { if (!timeout) {
timeout = setTimeout(() => { timeout = setTimeout(() => {
timeout = null; timeout = null;
func.apply(context, args) func.apply(context, args);
}, wait) }, wait);
} }
} }
} };
} };

View File

@ -1,34 +1,28 @@
// 此版本发布于2023-03-27 // 此版本发布于2023-03-27
const version = '2.0.36' const version = "2.0.36";
// 开发环境才提示,生产环境不会提示 // 开发环境才提示,生产环境不会提示
if (process.env.NODE_ENV === 'development') { if (process.env.NODE_ENV === "development") {
console.log(`\n %c uView V${version} %c https://uviewui.com/ \n\n`, 'color: #ffffff; background: #3c9cff; padding:5px 0; border-radius: 5px;'); // console.log(`\n %c uView V${version} %c https://uviewui.com/ \n\n`, 'color: #ffffff; background: #3c9cff; padding:5px 0; border-radius: 5px;');
} }
export default { export default {
v: version, v: version,
version, version,
// 主题名称 // 主题名称
type: [ type: ["primary", "success", "info", "error", "warning"],
'primary',
'success',
'info',
'error',
'warning'
],
// 颜色部分本来可以通过scss的:export导出供js使用但是奈何nvue不支持 // 颜色部分本来可以通过scss的:export导出供js使用但是奈何nvue不支持
color: { color: {
'u-primary': '#2979ff', "u-primary": "#2979ff",
'u-warning': '#ff9900', "u-warning": "#ff9900",
'u-success': '#19be6b', "u-success": "#19be6b",
'u-error': '#fa3534', "u-error": "#fa3534",
'u-info': '#909399', "u-info": "#909399",
'u-main-color': '#303133', "u-main-color": "#303133",
'u-content-color': '#606266', "u-content-color": "#606266",
'u-tips-color': '#909399', "u-tips-color": "#909399",
'u-light-color': '#c0c4cc' "u-light-color": "#c0c4cc",
}, },
// 默认单位可以通过配置为rpx那么在用于传入组件大小参数为数值时就默认为rpx // 默认单位可以通过配置为rpx那么在用于传入组件大小参数为数值时就默认为rpx
unit: 'px' unit: "px",
} };

View File

@ -6,7 +6,7 @@ let _boundaryCheckingState = true; // 是否进行越界检查的全局开关
* @example strip(0.09999999999999998)=0.1 * @example strip(0.09999999999999998)=0.1
*/ */
function strip(num, precision = 15) { function strip(num, precision = 15) {
return +parseFloat(Number(num).toPrecision(precision)); return +parseFloat(Number(num).toPrecision(precision));
} }
/** /**
@ -15,10 +15,10 @@ function strip(num, precision = 15) {
* @param {*number} num Input number * @param {*number} num Input number
*/ */
function digitLength(num) { function digitLength(num) {
// Get digit length of e // Get digit length of e
const eSplit = num.toString().split(/[eE]/); const eSplit = num.toString().split(/[eE]/);
const len = (eSplit[0].split('.')[1] || '').length - +(eSplit[1] || 0); const len = (eSplit[0].split(".")[1] || "").length - +(eSplit[1] || 0);
return len > 0 ? len : 0; return len > 0 ? len : 0;
} }
/** /**
@ -27,11 +27,11 @@ function digitLength(num) {
* @param {*number} num 输入数 * @param {*number} num 输入数
*/ */
function float2Fixed(num) { function float2Fixed(num) {
if (num.toString().indexOf('e') === -1) { if (num.toString().indexOf("e") === -1) {
return Number(num.toString().replace('.', '')); return Number(num.toString().replace(".", ""));
} }
const dLen = digitLength(num); const dLen = digitLength(num);
return dLen > 0 ? strip(Number(num) * Math.pow(10, dLen)) : Number(num); return dLen > 0 ? strip(Number(num) * Math.pow(10, dLen)) : Number(num);
} }
/** /**
@ -40,11 +40,11 @@ function float2Fixed(num) {
* @param {*number} num 输入数 * @param {*number} num 输入数
*/ */
function checkBoundary(num) { function checkBoundary(num) {
if (_boundaryCheckingState) { if (_boundaryCheckingState) {
if (num > Number.MAX_SAFE_INTEGER || num < Number.MIN_SAFE_INTEGER) { if (num > Number.MAX_SAFE_INTEGER || num < Number.MIN_SAFE_INTEGER) {
console.warn(`${num} 超出了精度限制,结果可能不正确`); // console.warn(`${num} 超出了精度限制,结果可能不正确`);
}
} }
}
} }
/** /**
@ -54,14 +54,14 @@ function checkBoundary(num) {
* @private * @private
*/ */
function iteratorOperation(arr, operation) { function iteratorOperation(arr, operation) {
const [num1, num2, ...others] = arr; const [num1, num2, ...others] = arr;
let res = operation(num1, num2); let res = operation(num1, num2);
others.forEach((num) => { others.forEach((num) => {
res = operation(res, num); res = operation(res, num);
}); });
return res; return res;
} }
/** /**
@ -69,19 +69,19 @@ function iteratorOperation(arr, operation) {
* @export * @export
*/ */
export function times(...nums) { export function times(...nums) {
if (nums.length > 2) { if (nums.length > 2) {
return iteratorOperation(nums, times); return iteratorOperation(nums, times);
} }
const [num1, num2] = nums; const [num1, num2] = nums;
const num1Changed = float2Fixed(num1); const num1Changed = float2Fixed(num1);
const num2Changed = float2Fixed(num2); const num2Changed = float2Fixed(num2);
const baseNum = digitLength(num1) + digitLength(num2); const baseNum = digitLength(num1) + digitLength(num2);
const leftValue = num1Changed * num2Changed; const leftValue = num1Changed * num2Changed;
checkBoundary(leftValue); checkBoundary(leftValue);
return leftValue / Math.pow(10, baseNum); return leftValue / Math.pow(10, baseNum);
} }
/** /**
@ -89,15 +89,18 @@ export function times(...nums) {
* @export * @export
*/ */
export function plus(...nums) { export function plus(...nums) {
if (nums.length > 2) { if (nums.length > 2) {
return iteratorOperation(nums, plus); return iteratorOperation(nums, plus);
} }
const [num1, num2] = nums; const [num1, num2] = nums;
// 取最大的小数位 // 取最大的小数位
const baseNum = Math.pow(10, Math.max(digitLength(num1), digitLength(num2))); const baseNum = Math.pow(
// 把小数都转为整数然后再计算 10,
return (times(num1, baseNum) + times(num2, baseNum)) / baseNum; Math.max(digitLength(num1), digitLength(num2))
);
// 把小数都转为整数然后再计算
return (times(num1, baseNum) + times(num2, baseNum)) / baseNum;
} }
/** /**
@ -105,13 +108,16 @@ export function plus(...nums) {
* @export * @export
*/ */
export function minus(...nums) { export function minus(...nums) {
if (nums.length > 2) { if (nums.length > 2) {
return iteratorOperation(nums, minus); return iteratorOperation(nums, minus);
} }
const [num1, num2] = nums; const [num1, num2] = nums;
const baseNum = Math.pow(10, Math.max(digitLength(num1), digitLength(num2))); const baseNum = Math.pow(
return (times(num1, baseNum) - times(num2, baseNum)) / baseNum; 10,
Math.max(digitLength(num1), digitLength(num2))
);
return (times(num1, baseNum) - times(num2, baseNum)) / baseNum;
} }
/** /**
@ -119,17 +125,20 @@ export function minus(...nums) {
* @export * @export
*/ */
export function divide(...nums) { export function divide(...nums) {
if (nums.length > 2) { if (nums.length > 2) {
return iteratorOperation(nums, divide); return iteratorOperation(nums, divide);
} }
const [num1, num2] = nums; const [num1, num2] = nums;
const num1Changed = float2Fixed(num1); const num1Changed = float2Fixed(num1);
const num2Changed = float2Fixed(num2); const num2Changed = float2Fixed(num2);
checkBoundary(num1Changed); checkBoundary(num1Changed);
checkBoundary(num2Changed); checkBoundary(num2Changed);
// 重要这里必须用strip进行修正 // 重要这里必须用strip进行修正
return times(num1Changed / num2Changed, strip(Math.pow(10, digitLength(num2) - digitLength(num1)))); return times(
num1Changed / num2Changed,
strip(Math.pow(10, digitLength(num2) - digitLength(num1)))
);
} }
/** /**
@ -137,13 +146,13 @@ export function divide(...nums) {
* @export * @export
*/ */
export function round(num, ratio) { export function round(num, ratio) {
const base = Math.pow(10, ratio); const base = Math.pow(10, ratio);
let result = divide(Math.round(Math.abs(times(num, base))), base); let result = divide(Math.round(Math.abs(times(num, base))), base);
if (num < 0 && result !== 0) { if (num < 0 && result !== 0) {
result = times(result, -1); result = times(result, -1);
} }
// 位数不足则补0 // 位数不足则补0
return result; return result;
} }
/** /**
@ -152,16 +161,14 @@ export function round(num, ratio) {
* @export * @export
*/ */
export function enableBoundaryChecking(flag = true) { export function enableBoundaryChecking(flag = true) {
_boundaryCheckingState = flag; _boundaryCheckingState = flag;
} }
export default { export default {
times, times,
plus, plus,
minus, minus,
divide, divide,
round, round,
enableBoundaryChecking, enableBoundaryChecking,
}; };

File diff suppressed because it is too large Load Diff

View File

@ -11,98 +11,98 @@
* HBuilderX: beat-3.0.4 alpha-3.0.4 * HBuilderX: beat-3.0.4 alpha-3.0.4
*/ */
import dispatchRequest from './dispatchRequest' import dispatchRequest from "./dispatchRequest";
import InterceptorManager from './InterceptorManager' import InterceptorManager from "./InterceptorManager";
import mergeConfig from './mergeConfig' import mergeConfig from "./mergeConfig";
import defaults from './defaults' import defaults from "./defaults";
import { isPlainObject } from '../utils' import { isPlainObject } from "../utils";
import clone from '../utils/clone' import clone from "../utils/clone";
export default class Request { export default class Request {
/** /**
* @param {Object} arg - 全局配置 * @param {Object} arg - 全局配置
* @param {String} arg.baseURL - 全局根路径 * @param {String} arg.baseURL - 全局根路径
* @param {Object} arg.header - 全局header * @param {Object} arg.header - 全局header
* @param {String} arg.method = [GET|POST|PUT|DELETE|CONNECT|HEAD|OPTIONS|TRACE] - 全局默认请求方式 * @param {String} arg.method = [GET|POST|PUT|DELETE|CONNECT|HEAD|OPTIONS|TRACE] - 全局默认请求方式
* @param {String} arg.dataType = [json] - 全局默认的dataType * @param {String} arg.dataType = [json] - 全局默认的dataType
* @param {String} arg.responseType = [text|arraybuffer] - 全局默认的responseType支付宝小程序不支持 * @param {String} arg.responseType = [text|arraybuffer] - 全局默认的responseType支付宝小程序不支持
* @param {Object} arg.custom - 全局默认的自定义参数 * @param {Object} arg.custom - 全局默认的自定义参数
* @param {Number} arg.timeout - 全局默认的超时时间单位 ms默认60000H5(HBuilderX 2.9.9+)APP(HBuilderX 2.9.9+)微信小程序2.10.0支付宝小程序 * @param {Number} arg.timeout - 全局默认的超时时间单位 ms默认60000H5(HBuilderX 2.9.9+)APP(HBuilderX 2.9.9+)微信小程序2.10.0支付宝小程序
* @param {Boolean} arg.sslVerify - 全局默认的是否验证 ssl 证书默认true.仅App安卓端支持HBuilderX 2.3.3+ * @param {Boolean} arg.sslVerify - 全局默认的是否验证 ssl 证书默认true.仅App安卓端支持HBuilderX 2.3.3+
* @param {Boolean} arg.withCredentials - 全局默认的跨域请求时是否携带凭证cookies默认false仅H5支持HBuilderX 2.6.15+ * @param {Boolean} arg.withCredentials - 全局默认的跨域请求时是否携带凭证cookies默认false仅H5支持HBuilderX 2.6.15+
* @param {Boolean} arg.firstIpv4 - 全DNS解析时优先使用ipv4默认false App-Android 支持 (HBuilderX 2.8.0+) * @param {Boolean} arg.firstIpv4 - 全DNS解析时优先使用ipv4默认false App-Android 支持 (HBuilderX 2.8.0+)
* @param {Function(statusCode):Boolean} arg.validateStatus - 全局默认的自定义验证器默认statusCode >= 200 && statusCode < 300 * @param {Function(statusCode):Boolean} arg.validateStatus - 全局默认的自定义验证器默认statusCode >= 200 && statusCode < 300
*/ */
constructor(arg = {}) { constructor(arg = {}) {
if (!isPlainObject(arg)) { if (!isPlainObject(arg)) {
arg = {} arg = {};
console.warn('设置全局参数必须接收一个Object') // console.warn('设置全局参数必须接收一个Object')
} }
this.config = clone({ ...defaults, ...arg }) this.config = clone({ ...defaults, ...arg });
this.interceptors = { this.interceptors = {
request: new InterceptorManager(), request: new InterceptorManager(),
response: new InterceptorManager() response: new InterceptorManager(),
} };
} }
/** /**
* @Function * @Function
* @param {Request~setConfigCallback} f - 设置全局默认配置 * @param {Request~setConfigCallback} f - 设置全局默认配置
*/ */
setConfig(f) { setConfig(f) {
this.config = f(this.config) this.config = f(this.config);
} }
middleware(config) { middleware(config) {
config = mergeConfig(this.config, config) config = mergeConfig(this.config, config);
const chain = [dispatchRequest, undefined] const chain = [dispatchRequest, undefined];
let promise = Promise.resolve(config) let promise = Promise.resolve(config);
this.interceptors.request.forEach((interceptor) => { this.interceptors.request.forEach((interceptor) => {
chain.unshift(interceptor.fulfilled, interceptor.rejected) chain.unshift(interceptor.fulfilled, interceptor.rejected);
}) });
this.interceptors.response.forEach((interceptor) => { this.interceptors.response.forEach((interceptor) => {
chain.push(interceptor.fulfilled, interceptor.rejected) chain.push(interceptor.fulfilled, interceptor.rejected);
}) });
while (chain.length) { while (chain.length) {
promise = promise.then(chain.shift(), chain.shift()) promise = promise.then(chain.shift(), chain.shift());
} }
return promise return promise;
} }
/** /**
* @Function * @Function
* @param {Object} config - 请求配置项 * @param {Object} config - 请求配置项
* @prop {String} options.url - 请求路径 * @prop {String} options.url - 请求路径
* @prop {Object} options.data - 请求参数 * @prop {Object} options.data - 请求参数
* @prop {Object} [options.responseType = config.responseType] [text|arraybuffer] - 响应的数据类型 * @prop {Object} [options.responseType = config.responseType] [text|arraybuffer] - 响应的数据类型
* @prop {Object} [options.dataType = config.dataType] - 如果设为 json会尝试对返回的数据做一次 JSON.parse * @prop {Object} [options.dataType = config.dataType] - 如果设为 json会尝试对返回的数据做一次 JSON.parse
* @prop {Object} [options.header = config.header] - 请求header * @prop {Object} [options.header = config.header] - 请求header
* @prop {Object} [options.method = config.method] - 请求方法 * @prop {Object} [options.method = config.method] - 请求方法
* @returns {Promise<unknown>} * @returns {Promise<unknown>}
*/ */
request(config = {}) { request(config = {}) {
return this.middleware(config) return this.middleware(config);
} }
get(url, options = {}) { get(url, options = {}) {
return this.middleware({ return this.middleware({
url, url,
method: 'GET', method: "GET",
...options ...options,
}) });
} }
post(url, data, options = {}) { post(url, data, options = {}) {
return this.middleware({ return this.middleware({
url, url,
data, data,
method: 'POST', method: "POST",
...options ...options,
}) });
} }
// #ifndef MP-ALIPAY // #ifndef MP-ALIPAY
@ -110,9 +110,9 @@ export default class Request {
return this.middleware({ return this.middleware({
url, url,
data, data,
method: 'PUT', method: "PUT",
...options ...options,
}) });
} }
// #endif // #endif
@ -122,9 +122,9 @@ export default class Request {
return this.middleware({ return this.middleware({
url, url,
data, data,
method: 'DELETE', method: "DELETE",
...options ...options,
}) });
} }
// #endif // #endif
@ -134,9 +134,9 @@ export default class Request {
return this.middleware({ return this.middleware({
url, url,
data, data,
method: 'CONNECT', method: "CONNECT",
...options ...options,
}) });
} }
// #endif // #endif
@ -146,9 +146,9 @@ export default class Request {
return this.middleware({ return this.middleware({
url, url,
data, data,
method: 'HEAD', method: "HEAD",
...options ...options,
}) });
} }
// #endif // #endif
@ -158,9 +158,9 @@ export default class Request {
return this.middleware({ return this.middleware({
url, url,
data, data,
method: 'OPTIONS', method: "OPTIONS",
...options ...options,
}) });
} }
// #endif // #endif
@ -170,23 +170,23 @@ export default class Request {
return this.middleware({ return this.middleware({
url, url,
data, data,
method: 'TRACE', method: "TRACE",
...options ...options,
}) });
} }
// #endif // #endif
upload(url, config = {}) { upload(url, config = {}) {
config.url = url config.url = url;
config.method = 'UPLOAD' config.method = "UPLOAD";
return this.middleware(config) return this.middleware(config);
} }
download(url, config = {}) { download(url, config = {}) {
config.url = url config.url = url;
config.method = 'DOWNLOAD' config.method = "DOWNLOAD";
return this.middleware(config) return this.middleware(config);
} }
} }

File diff suppressed because it is too large Load Diff

View File

@ -3,7 +3,7 @@
export class Mcaptcha { export class Mcaptcha {
constructor(options) { constructor(options) {
this.options = options; this.options = options;
this.fontSize = options.height * 3 / 6; this.fontSize = (options.height * 3) / 6;
this.init(); this.init();
this.refresh(); this.refresh();
} }
@ -13,17 +13,80 @@ export class Mcaptcha {
this.ctx.setFillStyle(this.randomColor(180, 240)); this.ctx.setFillStyle(this.randomColor(180, 240));
} }
refresh() { refresh() {
var code = ''; var code = "";
var txtArr = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 0, 1, 2, 3, 4, 5, 6, 7, 8, 9] var txtArr = [
"a",
"b",
"c",
"d",
"e",
"f",
"g",
"h",
"i",
"j",
"k",
"l",
"m",
"n",
"o",
"p",
"q",
"r",
"s",
"t",
"u",
"v",
"w",
"x",
"y",
"z",
"A",
"B",
"C",
"D",
"E",
"F",
"G",
"H",
"I",
"J",
"K",
"L",
"M",
"N",
"O",
"P",
"Q",
"R",
"S",
"T",
"U",
"V",
"W",
"X",
"Y",
"Z",
0,
1,
2,
3,
4,
5,
6,
7,
8,
9,
];
for (var i = 0; i < 4; i++) { for (var i = 0; i < 4; i++) {
code += txtArr[this.randomNum(0, txtArr.length)]; code += txtArr[this.randomNum(0, txtArr.length)];
} }
this.options.createCodeImg = code; this.options.createCodeImg = code;
let arr = (code + '').split(''); let arr = (code + "").split("");
if (arr.length === 0) { if (arr.length === 0) {
arr = ['e', 'r', 'r', 'o', 'r']; arr = ["e", "r", "r", "o", "r"];
}; }
let offsetLeft = this.options.width * 0.6 / (arr.length - 1); let offsetLeft = (this.options.width * 0.6) / (arr.length - 1);
let marginLeft = this.options.width * 0.2; let marginLeft = this.options.width * 0.2;
arr.forEach((item, index) => { arr.forEach((item, index) => {
this.ctx.setFillStyle(this.randomColor(0, 180)); this.ctx.setFillStyle(this.randomColor(0, 180));
@ -32,22 +95,34 @@ export class Mcaptcha {
let dis = offsetLeft * index + marginLeft - size * 0.3; let dis = offsetLeft * index + marginLeft - size * 0.3;
let deg = this.randomNum(-30, 30); let deg = this.randomNum(-30, 30);
this.ctx.translate(dis, this.options.height * 0.5); this.ctx.translate(dis, this.options.height * 0.5);
this.ctx.rotate(deg * Math.PI / 180); this.ctx.rotate((deg * Math.PI) / 180);
this.ctx.fillText(item, 0, 0); this.ctx.fillText(item, 0, 0);
this.ctx.rotate(-deg * Math.PI / 180); this.ctx.rotate((-deg * Math.PI) / 180);
this.ctx.translate(-dis, -this.options.height * 0.5); this.ctx.translate(-dis, -this.options.height * 0.5);
}) });
for (var i = 0; i < 4; i++) { for (var i = 0; i < 4; i++) {
this.ctx.strokeStyle = this.randomColor(40, 180); this.ctx.strokeStyle = this.randomColor(40, 180);
this.ctx.beginPath(); this.ctx.beginPath();
this.ctx.moveTo(this.randomNum(0, this.options.width), this.randomNum(0, this.options.height)); this.ctx.moveTo(
this.ctx.lineTo(this.randomNum(0, this.options.width), this.randomNum(0, this.options.height)); this.randomNum(0, this.options.width),
this.randomNum(0, this.options.height)
);
this.ctx.lineTo(
this.randomNum(0, this.options.width),
this.randomNum(0, this.options.height)
);
this.ctx.stroke(); this.ctx.stroke();
} }
for (var i = 0; i < this.options.width / 4; i++) { for (var i = 0; i < this.options.width / 4; i++) {
this.ctx.fillStyle = this.randomColor(0, 255); this.ctx.fillStyle = this.randomColor(0, 255);
this.ctx.beginPath(); this.ctx.beginPath();
this.ctx.arc(this.randomNum(0, this.options.width), this.randomNum(0, this.options.height), 1, 0, 2 * Math.PI); this.ctx.arc(
this.randomNum(0, this.options.width),
this.randomNum(0, this.options.height),
1,
0,
2 * Math.PI
);
this.ctx.fill(); this.ctx.fill();
} }
this.ctx.draw(); this.ctx.draw();
@ -55,8 +130,8 @@ export class Mcaptcha {
validate(code) { validate(code) {
var code = code.toLowerCase(); var code = code.toLowerCase();
var v_code = this.options.createCodeImg.toLowerCase(); var v_code = this.options.createCodeImg.toLowerCase();
console.log(code) // console.log(code)
console.log(v_code.substring(v_code.length - 4)) // console.log(v_code.substring(v_code.length - 4))
if (code == v_code.substring(v_code.length - 4)) { if (code == v_code.substring(v_code.length - 4)) {
return true; return true;
} else { } else {
@ -72,4 +147,4 @@ export class Mcaptcha {
let b = this.randomNum(min, max); let b = this.randomNum(min, max);
return "rgb(" + r + "," + g + "," + b + ")"; return "rgb(" + r + "," + g + "," + b + ")";
} }
} }