|
|
@@ -1,37 +1,16 @@
|
|
|
// 正则表达式
|
|
|
export const regex = {
|
|
|
- phoneNumber: /^1[13456789]\d{9}$/,// 手机号码
|
|
|
password: /^[a-zA-Z0-9]{6,16}$/,// 密码
|
|
|
- email: /^([a-zA-Z0-9_\.\-])+@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/,// 电子邮箱
|
|
|
-}
|
|
|
+};
|
|
|
|
|
|
-// 函数防抖
|
|
|
-export const debounce = (func: Function, interval?: number) => {
|
|
|
- let timer: any;
|
|
|
- const time = interval || 200;// 间隔时间默认0.2秒
|
|
|
- return function (this: object, ...args: any[]) {
|
|
|
- clearTimeout(timer);
|
|
|
- timer = setTimeout(() => {
|
|
|
- func.call(this, args);
|
|
|
- }, time);
|
|
|
- };
|
|
|
-}
|
|
|
-
|
|
|
-// 下载Excel
|
|
|
-export const downloadExcel = (url: string) => {
|
|
|
+// 下载文件
|
|
|
+export const downloadFile = (blob: Blob, fileName: string) => {
|
|
|
+ const downUrl = window.URL.createObjectURL(new Blob([blob]));
|
|
|
const elementA = document.createElement('a');
|
|
|
- elementA.setAttribute('href', url);
|
|
|
+ elementA.href = downUrl;
|
|
|
+ elementA.download = fileName;
|
|
|
elementA.style.display = 'none';
|
|
|
document.body.appendChild(elementA);
|
|
|
elementA.click();
|
|
|
document.body.removeChild(elementA);
|
|
|
-}
|
|
|
-
|
|
|
-// 模拟异步
|
|
|
-export const promise = (response: any, time: number): Promise<any> => {
|
|
|
- return new Promise((resolve, reject) => {
|
|
|
- setTimeout(() => {
|
|
|
- resolve(response);
|
|
|
- }, time * 1000);
|
|
|
- });
|
|
|
-}
|
|
|
+};
|