|
@@ -27,10 +27,7 @@ export const debounce = <T extends (...args: any) => any>(fn: T, delay: number =
|
|
const place = /(?:\/:([^/]*))/g;
|
|
const place = /(?:\/:([^/]*))/g;
|
|
// 匹配 /:id 是否匹配某个url
|
|
// 匹配 /:id 是否匹配某个url
|
|
export const equalUrl = (tempUrl: string, url: string) => {
|
|
export const equalUrl = (tempUrl: string, url: string) => {
|
|
- const urlRgStr =
|
|
|
|
- "^" +
|
|
|
|
- tempUrl.replace(/\/([^:])/g, (_, d) => `\\/${d}`).replace(place, () => `(?:/[^/]*)`) +
|
|
|
|
- "$";
|
|
|
|
|
|
+ const urlRgStr = "^" + tempUrl.replace(/\/([^:])/g, (_, d) => `\\/${d}`).replace(place, () => `(?:/[^/]*)`) + "$";
|
|
return new RegExp(urlRgStr).test(url);
|
|
return new RegExp(urlRgStr).test(url);
|
|
};
|
|
};
|
|
|
|
|
|
@@ -48,8 +45,7 @@ export const gendUrl = (tempUrl: string, params: { [key: string]: any }) => {
|
|
};
|
|
};
|
|
|
|
|
|
// 匹配一组数组是否是path链接
|
|
// 匹配一组数组是否是path链接
|
|
-export const includesUrl = (tempUrls: Array<string> | readonly string[], url: string) =>
|
|
|
|
- tempUrls.some((tempUrl) => equalUrl(tempUrl, url));
|
|
|
|
|
|
+export const includesUrl = (tempUrls: Array<string> | readonly string[], url: string) => tempUrls.some((tempUrl) => equalUrl(tempUrl, url));
|
|
|
|
|
|
// 字符串转params对象
|
|
// 字符串转params对象
|
|
export const strToParams = (str: string) => {
|
|
export const strToParams = (str: string) => {
|
|
@@ -85,17 +81,10 @@ export const toRawType = (value: unknown): string => {
|
|
return toTypeString(value).slice(8, -1);
|
|
return toTypeString(value).slice(8, -1);
|
|
};
|
|
};
|
|
|
|
|
|
-export const isString = <T>(value: T): T extends string ? true : false =>
|
|
|
|
- (toRawType(value) === "String") as any;
|
|
|
|
|
|
+export const isString = <T>(value: T): T extends string ? true : false => (toRawType(value) === "String") as any;
|
|
|
|
|
|
// 递归复制
|
|
// 递归复制
|
|
-export const recursionCopy = <
|
|
|
|
- T extends object | Array<any>,
|
|
|
|
- R extends object | Array<any>
|
|
|
|
->(
|
|
|
|
- from: R,
|
|
|
|
- to: T
|
|
|
|
-): T & R => {
|
|
|
|
|
|
+export const recursionCopy = <T extends object | Array<any>, R extends object | Array<any>>(from: R, to: T): T & R => {
|
|
if (toRawType(from) !== toRawType(to)) {
|
|
if (toRawType(from) !== toRawType(to)) {
|
|
return to as T & R;
|
|
return to as T & R;
|
|
}
|
|
}
|
|
@@ -115,10 +104,7 @@ export const recursionCopy = <
|
|
const fromItemType = toRawType(fromItem);
|
|
const fromItemType = toRawType(fromItem);
|
|
const toItemType = toRawType(toItem);
|
|
const toItemType = toRawType(toItem);
|
|
|
|
|
|
- if (
|
|
|
|
- fromItemType === toItemType &&
|
|
|
|
- (fromItemType === "Object" || fromItemType === "Array")
|
|
|
|
- ) {
|
|
|
|
|
|
+ if (fromItemType === toItemType && (fromItemType === "Object" || fromItemType === "Array")) {
|
|
(result as any)[fromKey] = recursionCopy(fromItem, toItem);
|
|
(result as any)[fromKey] = recursionCopy(fromItem, toItem);
|
|
} else {
|
|
} else {
|
|
(result as any)[fromKey] = toItem;
|
|
(result as any)[fromKey] = toItem;
|
|
@@ -161,10 +147,7 @@ export const formatDate = (date: Date, fmt: string = "yyyy-MM-dd hh:mm") => {
|
|
(Object.keys(map) as Array<keyof typeof map>).forEach((k) => {
|
|
(Object.keys(map) as Array<keyof typeof map>).forEach((k) => {
|
|
if (new RegExp("(" + k + ")").test(fmt)) {
|
|
if (new RegExp("(" + k + ")").test(fmt)) {
|
|
const val = map[k].toString();
|
|
const val = map[k].toString();
|
|
- fmt = fmt.replace(
|
|
|
|
- RegExp.$1,
|
|
|
|
- RegExp.$1.length === 1 ? val : ("00" + val).substr(val.length)
|
|
|
|
- );
|
|
|
|
|
|
+ fmt = fmt.replace(RegExp.$1, RegExp.$1.length === 1 ? val : ("00" + val).substr(val.length));
|
|
}
|
|
}
|
|
});
|
|
});
|
|
|
|
|
|
@@ -172,10 +155,7 @@ export const formatDate = (date: Date, fmt: string = "yyyy-MM-dd hh:mm") => {
|
|
};
|
|
};
|
|
|
|
|
|
// 函数调用拦截
|
|
// 函数调用拦截
|
|
-export const funIntercept = <T extends (...args: any) => any>(
|
|
|
|
- originFun: T,
|
|
|
|
- proxyFun: (args: Parameters<T>, result: ReturnType<T>) => void
|
|
|
|
-): T =>
|
|
|
|
|
|
+export const funIntercept = <T extends (...args: any) => any>(originFun: T, proxyFun: (args: Parameters<T>, result: ReturnType<T>) => void): T =>
|
|
function (...args: Parameters<T>) {
|
|
function (...args: Parameters<T>) {
|
|
const result = originFun.apply(this, args);
|
|
const result = originFun.apply(this, args);
|
|
proxyFun(args, result);
|
|
proxyFun(args, result);
|
|
@@ -189,8 +169,7 @@ export const round = (num: number, index: number = 2) => {
|
|
};
|
|
};
|
|
|
|
|
|
// setTimeout转promise
|
|
// setTimeout转promise
|
|
-export const asyncTimeout = (mis: number = 0) =>
|
|
|
|
- new Promise((resolve) => setTimeout(resolve, mis));
|
|
|
|
|
|
+export const asyncTimeout = (mis: number = 0) => new Promise((resolve) => setTimeout(resolve, mis));
|
|
|
|
|
|
// 持续检查直到通过
|
|
// 持续检查直到通过
|
|
export const checkPromise = <T = any>(check: () => T) => {
|
|
export const checkPromise = <T = any>(check: () => T) => {
|
|
@@ -296,26 +275,17 @@ const _inRevise = (raw1, raw2, readly: Set<[any, any]>) => {
|
|
readly.add([raw1, raw2]);
|
|
readly.add([raw1, raw2]);
|
|
|
|
|
|
if (rawType1 === "Array") {
|
|
if (rawType1 === "Array") {
|
|
- return (
|
|
|
|
- raw1.length !== raw2.length ||
|
|
|
|
- raw1.some((item1, i) => _inRevise(item1, raw2[i], readly))
|
|
|
|
- );
|
|
|
|
|
|
+ return raw1.length !== raw2.length || raw1.some((item1, i) => _inRevise(item1, raw2[i], readly));
|
|
} else if (rawType1 === "Object") {
|
|
} else if (rawType1 === "Object") {
|
|
const rawKeys1 = Object.keys(raw1).sort();
|
|
const rawKeys1 = Object.keys(raw1).sort();
|
|
const rawKeys2 = Object.keys(raw2).sort();
|
|
const rawKeys2 = Object.keys(raw2).sort();
|
|
|
|
|
|
- return (
|
|
|
|
- _inRevise(rawKeys1, rawKeys2, readly) ||
|
|
|
|
- rawKeys1.some((key) => _inRevise(raw1[key], raw2[key], readly))
|
|
|
|
- );
|
|
|
|
|
|
+ return _inRevise(rawKeys1, rawKeys2, readly) || rawKeys1.some((key) => _inRevise(raw1[key], raw2[key], readly));
|
|
} else if (rawType1 === "Map") {
|
|
} else if (rawType1 === "Map") {
|
|
const rawKeys1 = Array.from(raw1.keys()).sort();
|
|
const rawKeys1 = Array.from(raw1.keys()).sort();
|
|
const rawKeys2 = Array.from(raw2.keys()).sort();
|
|
const rawKeys2 = Array.from(raw2.keys()).sort();
|
|
|
|
|
|
- return (
|
|
|
|
- _inRevise(rawKeys1, rawKeys2, readly) ||
|
|
|
|
- rawKeys1.some((key) => _inRevise(raw1.get(key), raw2.get(key), readly))
|
|
|
|
- );
|
|
|
|
|
|
+ return _inRevise(rawKeys1, rawKeys2, readly) || rawKeys1.some((key) => _inRevise(raw1.get(key), raw2.get(key), readly));
|
|
} else if (rawType1 === "Set") {
|
|
} else if (rawType1 === "Set") {
|
|
return inRevise(Array.from(raw1.values()), Array.from(raw2.values()));
|
|
return inRevise(Array.from(raw1.values()), Array.from(raw2.values()));
|
|
} else {
|
|
} else {
|
|
@@ -493,10 +463,7 @@ export const toDigital = (dms: string, retain = 6) => {
|
|
}
|
|
}
|
|
};
|
|
};
|
|
|
|
|
|
-export const addImmobilityClick = (
|
|
|
|
- dom: HTMLElement,
|
|
|
|
- handler: (ev?: MouseEvent) => any
|
|
|
|
-) => {
|
|
|
|
|
|
+export const addImmobilityClick = (dom: HTMLElement, handler: (ev?: MouseEvent) => any) => {
|
|
const mousedownHandler = (ev: MouseEvent) => {
|
|
const mousedownHandler = (ev: MouseEvent) => {
|
|
const dx = ev.offsetX;
|
|
const dx = ev.offsetX;
|
|
const dy = ev.offsetY;
|
|
const dy = ev.offsetY;
|
|
@@ -560,3 +527,12 @@ export const blobToBase64 = (blob: Blob) => {
|
|
export const getId = () => {
|
|
export const getId = () => {
|
|
return new Date().getTime().toString() + Math.ceil(Math.random() * 1000).toString();
|
|
return new Date().getTime().toString() + Math.ceil(Math.random() * 1000).toString();
|
|
};
|
|
};
|
|
|
|
+
|
|
|
|
+export const getQueryString = (name) => {
|
|
|
|
+ var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
|
|
|
|
+ var r = decodeURIComponent(window.location.search.substr(1)).match(reg);
|
|
|
|
+ if (r != null) {
|
|
|
|
+ return unescape(r[2]);
|
|
|
|
+ }
|
|
|
|
+ return null;
|
|
|
|
+};
|