|
@@ -11,10 +11,7 @@ export const dateFormat = (date: Date, fmt: string) => {
|
|
S: date.getMilliseconds(), //毫秒
|
|
S: date.getMilliseconds(), //毫秒
|
|
};
|
|
};
|
|
if (/(y+)/.test(fmt)) {
|
|
if (/(y+)/.test(fmt)) {
|
|
- fmt = fmt.replace(
|
|
|
|
- RegExp.$1,
|
|
|
|
- (date.getFullYear() + "").substr(4 - RegExp.$1.length)
|
|
|
|
- );
|
|
|
|
|
|
+ fmt = fmt.replace(RegExp.$1, (date.getFullYear() + "").substr(4 - RegExp.$1.length));
|
|
}
|
|
}
|
|
for (var k in o) {
|
|
for (var k in o) {
|
|
if (new RegExp("(" + k + ")").test(fmt)) {
|
|
if (new RegExp("(" + k + ")").test(fmt)) {
|
|
@@ -39,6 +36,17 @@ export const copyText = (text: string) => {
|
|
document.body.removeChild(input);
|
|
document.body.removeChild(input);
|
|
};
|
|
};
|
|
|
|
|
|
|
|
+// 防抖
|
|
|
|
+export const debounce = <T extends (...args: any) => any>(fn: T, delay: number = 160) => {
|
|
|
|
+ let timeout: any;
|
|
|
|
+
|
|
|
|
+ return function <This>(this: This, ...args: Parameters<T>) {
|
|
|
|
+ clearTimeout(timeout);
|
|
|
|
+ timeout = setTimeout(() => {
|
|
|
|
+ fn.apply(this, args);
|
|
|
|
+ }, delay);
|
|
|
|
+ };
|
|
|
|
+};
|
|
export const throttle = <Args extends any[]>(
|
|
export const throttle = <Args extends any[]>(
|
|
fn: (...args: Args) => void,
|
|
fn: (...args: Args) => void,
|
|
deley: number
|
|
deley: number
|
|
@@ -161,10 +169,7 @@ export function encodePwd(str: string, strv = "") {
|
|
if (strv) {
|
|
if (strv) {
|
|
const strv1 = strv.substring(0, NUM);
|
|
const strv1 = strv.substring(0, NUM);
|
|
const strv2 = strv.substring(NUM);
|
|
const strv2 = strv.substring(NUM);
|
|
- return [
|
|
|
|
- front + str2 + middle + str1 + end,
|
|
|
|
- front + strv2 + middle + strv1 + end,
|
|
|
|
- ];
|
|
|
|
|
|
+ return [front + str2 + middle + str1 + end, front + strv2 + middle + strv1 + end];
|
|
}
|
|
}
|
|
|
|
|
|
return front + str2 + middle + str1 + end;
|
|
return front + str2 + middle + str1 + end;
|
|
@@ -229,10 +234,7 @@ export const drawImage = (
|
|
) => {
|
|
) => {
|
|
let dWidth = bg_w / imgWidth; // canvas与图片的宽度比例
|
|
let dWidth = bg_w / imgWidth; // canvas与图片的宽度比例
|
|
let dHeight = bg_h / imgHeight; // canvas与图片的高度比例
|
|
let dHeight = bg_h / imgHeight; // canvas与图片的高度比例
|
|
- if (
|
|
|
|
- (imgWidth > bg_w && imgHeight > bg_h) ||
|
|
|
|
- (imgWidth < bg_w && imgHeight < bg_h)
|
|
|
|
- ) {
|
|
|
|
|
|
+ if ((imgWidth > bg_w && imgHeight > bg_h) || (imgWidth < bg_w && imgHeight < bg_h)) {
|
|
if (dWidth > dHeight) {
|
|
if (dWidth > dHeight) {
|
|
ctx.drawImage(
|
|
ctx.drawImage(
|
|
imgPath,
|
|
imgPath,
|