sculp-js 1.4.1 → 1.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +12 -1
- package/lib/cjs/download.js +34 -4
- package/lib/cjs/index.js +1 -1
- package/lib/cjs/we-decode.js +43 -44
- package/lib/es/download.js +34 -5
- package/lib/es/index.js +2 -2
- package/lib/es/we-decode.js +44 -44
- package/lib/index.d.ts +12 -4
- package/lib/umd/index.js +76 -48
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -20,9 +20,18 @@
|
|
|
20
20
|
- isNumber
|
|
21
21
|
- isUndefined
|
|
22
22
|
- isNull
|
|
23
|
+
- isNullOrUnDef
|
|
23
24
|
- isPrimitive
|
|
25
|
+
- isFunction
|
|
24
26
|
- isObject
|
|
27
|
+
- isArray
|
|
25
28
|
- typeIs
|
|
29
|
+
- isJsonString
|
|
30
|
+
|
|
31
|
+
- encode/decode
|
|
32
|
+
|
|
33
|
+
- weAtob
|
|
34
|
+
- weBtoa
|
|
26
35
|
|
|
27
36
|
- Array
|
|
28
37
|
|
|
@@ -35,6 +44,7 @@
|
|
|
35
44
|
- forEachMap 高性能的深度优先遍历的Map函数, 支持continue、break,可定制id、children
|
|
36
45
|
- searchTreeById 在树中找到 id 为某个值的节点,并返回上游的所有父级节点
|
|
37
46
|
- formatTree 高性能的数组转树函数
|
|
47
|
+
- flatTree 树转数组
|
|
38
48
|
- fuzzySearchTree 模糊搜索函数,返回包含搜索字符的节点及其祖先节点的树
|
|
39
49
|
|
|
40
50
|
- Object
|
|
@@ -54,7 +64,7 @@
|
|
|
54
64
|
|
|
55
65
|
- stringCamelCase
|
|
56
66
|
- stringKebabCase
|
|
57
|
-
-
|
|
67
|
+
- parseQueryParams
|
|
58
68
|
|
|
59
69
|
- Unique
|
|
60
70
|
|
|
@@ -89,6 +99,7 @@
|
|
|
89
99
|
- setStyle
|
|
90
100
|
- getStyle
|
|
91
101
|
- getComputedCssVal
|
|
102
|
+
- getStrWidthPx
|
|
92
103
|
|
|
93
104
|
- Watermark (web)
|
|
94
105
|
|
package/lib/cjs/download.js
CHANGED
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
|
|
7
7
|
'use strict';
|
|
8
8
|
|
|
9
|
+
var type = require('./type.js');
|
|
9
10
|
var url = require('./url.js');
|
|
10
11
|
|
|
11
12
|
/**
|
|
@@ -20,25 +21,53 @@ function downloadURL(url$1, params) {
|
|
|
20
21
|
* 通过 A 链接的方式下载
|
|
21
22
|
* @param {string} href
|
|
22
23
|
* @param {string} filename
|
|
24
|
+
* @param {Function} callback
|
|
23
25
|
*/
|
|
24
|
-
function downloadHref(href, filename) {
|
|
26
|
+
function downloadHref(href, filename, callback) {
|
|
25
27
|
const eleLink = document.createElement('a');
|
|
26
28
|
eleLink.download = filename;
|
|
27
29
|
eleLink.style.display = 'none';
|
|
28
30
|
eleLink.href = href;
|
|
29
31
|
document.body.appendChild(eleLink);
|
|
30
32
|
eleLink.click();
|
|
31
|
-
setTimeout(() =>
|
|
33
|
+
setTimeout(() => {
|
|
34
|
+
document.body.removeChild(eleLink);
|
|
35
|
+
if (type.isFunction(callback)) {
|
|
36
|
+
callback();
|
|
37
|
+
}
|
|
38
|
+
});
|
|
32
39
|
}
|
|
33
40
|
/**
|
|
34
41
|
* 将大文件对象通过 A 链接的方式下载
|
|
35
42
|
* @param {Blob} blob
|
|
36
43
|
* @param {string} filename
|
|
44
|
+
* @param {Function} callback
|
|
37
45
|
*/
|
|
38
|
-
function downloadBlob(blob, filename) {
|
|
46
|
+
function downloadBlob(blob, filename, callback) {
|
|
39
47
|
const objURL = URL.createObjectURL(blob);
|
|
40
48
|
downloadHref(objURL, filename);
|
|
41
|
-
setTimeout(() =>
|
|
49
|
+
setTimeout(() => {
|
|
50
|
+
URL.revokeObjectURL(objURL);
|
|
51
|
+
if (type.isFunction(callback)) {
|
|
52
|
+
callback();
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* 根据URL下载文件(解决跨域a.download不生效问题)
|
|
58
|
+
* @param {string} url
|
|
59
|
+
* @param {string} filename
|
|
60
|
+
* @param {Function} callback
|
|
61
|
+
*/
|
|
62
|
+
function crossDomainDownload(url, filename, callback) {
|
|
63
|
+
const xhr = new XMLHttpRequest();
|
|
64
|
+
xhr.open('GET', url, true);
|
|
65
|
+
xhr.responseType = 'blob';
|
|
66
|
+
xhr.onload = function () {
|
|
67
|
+
if (xhr.status === 200)
|
|
68
|
+
downloadBlob(xhr.response, filename, callback);
|
|
69
|
+
};
|
|
70
|
+
xhr.send();
|
|
42
71
|
}
|
|
43
72
|
/**
|
|
44
73
|
* 将指定数据格式通过 A 链接的方式下载
|
|
@@ -76,6 +105,7 @@ function downloadData(data, fileType, filename, headers) {
|
|
|
76
105
|
}
|
|
77
106
|
}
|
|
78
107
|
|
|
108
|
+
exports.crossDomainDownload = crossDomainDownload;
|
|
79
109
|
exports.downloadBlob = downloadBlob;
|
|
80
110
|
exports.downloadData = downloadData;
|
|
81
111
|
exports.downloadHref = downloadHref;
|
package/lib/cjs/index.js
CHANGED
|
@@ -57,6 +57,7 @@ exports.onDomReady = dom.onDomReady;
|
|
|
57
57
|
exports.removeClass = dom.removeClass;
|
|
58
58
|
exports.setStyle = dom.setStyle;
|
|
59
59
|
exports.smoothScroll = dom.smoothScroll;
|
|
60
|
+
exports.crossDomainDownload = download.crossDomainDownload;
|
|
60
61
|
exports.downloadBlob = download.downloadBlob;
|
|
61
62
|
exports.downloadData = download.downloadData;
|
|
62
63
|
exports.downloadHref = download.downloadHref;
|
|
@@ -139,6 +140,5 @@ exports.forEachMap = tree.forEachMap;
|
|
|
139
140
|
exports.formatTree = tree.formatTree;
|
|
140
141
|
exports.fuzzySearchTree = tree.fuzzySearchTree;
|
|
141
142
|
exports.searchTreeById = tree.searchTreeById;
|
|
142
|
-
exports.weAppJwtDecode = weDecode.weAppJwtDecode;
|
|
143
143
|
exports.weAtob = weDecode.weAtob;
|
|
144
144
|
exports.weBtoa = weDecode.weBtoa;
|
package/lib/cjs/we-decode.js
CHANGED
|
@@ -58,50 +58,49 @@ function weAtob(string) {
|
|
|
58
58
|
}
|
|
59
59
|
return result;
|
|
60
60
|
}
|
|
61
|
-
function b64DecodeUnicode(str) {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
}
|
|
61
|
+
// function b64DecodeUnicode(str) {
|
|
62
|
+
// return decodeURIComponent(
|
|
63
|
+
// exports.weAtob(str).replace(/(.)/g, function (p) {
|
|
64
|
+
// let code = p.charCodeAt(0).toString(16).toUpperCase();
|
|
65
|
+
// if (code.length < 2) {
|
|
66
|
+
// code = '0' + code;
|
|
67
|
+
// }
|
|
68
|
+
// return '%' + code;
|
|
69
|
+
// })
|
|
70
|
+
// );
|
|
71
|
+
// }
|
|
72
|
+
// function base64_url_decode(str) {
|
|
73
|
+
// let output = str.replace(/-/g, '+').replace(/_/g, '/');
|
|
74
|
+
// switch (output.length % 4) {
|
|
75
|
+
// case 0:
|
|
76
|
+
// break;
|
|
77
|
+
// case 2:
|
|
78
|
+
// output += '==';
|
|
79
|
+
// break;
|
|
80
|
+
// case 3:
|
|
81
|
+
// output += '=';
|
|
82
|
+
// break;
|
|
83
|
+
// default:
|
|
84
|
+
// throw new Error('Illegal base64url string!');
|
|
85
|
+
// }
|
|
86
|
+
// try {
|
|
87
|
+
// return b64DecodeUnicode(output);
|
|
88
|
+
// } catch (err) {
|
|
89
|
+
// return exports.weAtob(output);
|
|
90
|
+
// }
|
|
91
|
+
// }
|
|
92
|
+
// export function weAppJwtDecode(token, options) {
|
|
93
|
+
// if (typeof token !== 'string') {
|
|
94
|
+
// throw new Error('Invalid token specified');
|
|
95
|
+
// }
|
|
96
|
+
// options = options || {};
|
|
97
|
+
// const pos = options.header === true ? 0 : 1;
|
|
98
|
+
// try {
|
|
99
|
+
// return JSON.parse(base64_url_decode(token.split('.')[pos]));
|
|
100
|
+
// } catch (e) {
|
|
101
|
+
// throw new Error('Invalid token specified: ' + (e as Error).message);
|
|
102
|
+
// }
|
|
103
|
+
// }
|
|
104
104
|
|
|
105
|
-
exports.weAppJwtDecode = weAppJwtDecode;
|
|
106
105
|
exports.weAtob = weAtob;
|
|
107
106
|
exports.weBtoa = weBtoa;
|
package/lib/es/download.js
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
* Released under the MIT License.
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
+
import { isFunction } from './type.js';
|
|
7
8
|
import { urlSetParams } from './url.js';
|
|
8
9
|
|
|
9
10
|
/**
|
|
@@ -18,25 +19,53 @@ function downloadURL(url, params) {
|
|
|
18
19
|
* 通过 A 链接的方式下载
|
|
19
20
|
* @param {string} href
|
|
20
21
|
* @param {string} filename
|
|
22
|
+
* @param {Function} callback
|
|
21
23
|
*/
|
|
22
|
-
function downloadHref(href, filename) {
|
|
24
|
+
function downloadHref(href, filename, callback) {
|
|
23
25
|
const eleLink = document.createElement('a');
|
|
24
26
|
eleLink.download = filename;
|
|
25
27
|
eleLink.style.display = 'none';
|
|
26
28
|
eleLink.href = href;
|
|
27
29
|
document.body.appendChild(eleLink);
|
|
28
30
|
eleLink.click();
|
|
29
|
-
setTimeout(() =>
|
|
31
|
+
setTimeout(() => {
|
|
32
|
+
document.body.removeChild(eleLink);
|
|
33
|
+
if (isFunction(callback)) {
|
|
34
|
+
callback();
|
|
35
|
+
}
|
|
36
|
+
});
|
|
30
37
|
}
|
|
31
38
|
/**
|
|
32
39
|
* 将大文件对象通过 A 链接的方式下载
|
|
33
40
|
* @param {Blob} blob
|
|
34
41
|
* @param {string} filename
|
|
42
|
+
* @param {Function} callback
|
|
35
43
|
*/
|
|
36
|
-
function downloadBlob(blob, filename) {
|
|
44
|
+
function downloadBlob(blob, filename, callback) {
|
|
37
45
|
const objURL = URL.createObjectURL(blob);
|
|
38
46
|
downloadHref(objURL, filename);
|
|
39
|
-
setTimeout(() =>
|
|
47
|
+
setTimeout(() => {
|
|
48
|
+
URL.revokeObjectURL(objURL);
|
|
49
|
+
if (isFunction(callback)) {
|
|
50
|
+
callback();
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* 根据URL下载文件(解决跨域a.download不生效问题)
|
|
56
|
+
* @param {string} url
|
|
57
|
+
* @param {string} filename
|
|
58
|
+
* @param {Function} callback
|
|
59
|
+
*/
|
|
60
|
+
function crossDomainDownload(url, filename, callback) {
|
|
61
|
+
const xhr = new XMLHttpRequest();
|
|
62
|
+
xhr.open('GET', url, true);
|
|
63
|
+
xhr.responseType = 'blob';
|
|
64
|
+
xhr.onload = function () {
|
|
65
|
+
if (xhr.status === 200)
|
|
66
|
+
downloadBlob(xhr.response, filename, callback);
|
|
67
|
+
};
|
|
68
|
+
xhr.send();
|
|
40
69
|
}
|
|
41
70
|
/**
|
|
42
71
|
* 将指定数据格式通过 A 链接的方式下载
|
|
@@ -74,4 +103,4 @@ function downloadData(data, fileType, filename, headers) {
|
|
|
74
103
|
}
|
|
75
104
|
}
|
|
76
105
|
|
|
77
|
-
export { downloadBlob, downloadData, downloadHref, downloadURL };
|
|
106
|
+
export { crossDomainDownload, downloadBlob, downloadData, downloadHref, downloadURL };
|
package/lib/es/index.js
CHANGED
|
@@ -9,7 +9,7 @@ export { copyText } from './clipboard.js';
|
|
|
9
9
|
export { cookieDel, cookieGet, cookieSet } from './cookie.js';
|
|
10
10
|
export { calculateDate, calculateDateTime, dateParse, dateToEnd, dateToStart, formatDate, isValidDate } from './date.js';
|
|
11
11
|
export { addClass, getComputedCssVal, getStrWidthPx, getStyle, hasClass, isDomReady, onDomReady, removeClass, setStyle, smoothScroll } from './dom.js';
|
|
12
|
-
export { downloadBlob, downloadData, downloadHref, downloadURL } from './download.js';
|
|
12
|
+
export { crossDomainDownload, downloadBlob, downloadData, downloadHref, downloadURL } from './download.js';
|
|
13
13
|
export { cloneDeep, isPlainObject, objectAssign, objectEach, objectEachAsync, objectFill, objectGet, objectHas, objectMap, objectAssign as objectMerge, objectOmit, objectPick } from './object.js';
|
|
14
14
|
export { pathJoin, pathNormalize } from './path.js';
|
|
15
15
|
export { qsParse, qsStringify } from './qs.js';
|
|
@@ -25,4 +25,4 @@ export { HEX_POOL, formatNumber, numberAbbr, numberToHex } from './number.js';
|
|
|
25
25
|
export { UNIQUE_NUMBER_SAFE_LENGTH, uniqueNumber, uniqueString } from './unique.js';
|
|
26
26
|
export { tooltipEvent } from './tooltip.js';
|
|
27
27
|
export { buildTree, flatTree, forEachDeep, forEachMap, formatTree, fuzzySearchTree, searchTreeById } from './tree.js';
|
|
28
|
-
export {
|
|
28
|
+
export { weAtob, weBtoa } from './we-decode.js';
|
package/lib/es/we-decode.js
CHANGED
|
@@ -56,48 +56,48 @@ function weAtob(string) {
|
|
|
56
56
|
}
|
|
57
57
|
return result;
|
|
58
58
|
}
|
|
59
|
-
function b64DecodeUnicode(str) {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
}
|
|
59
|
+
// function b64DecodeUnicode(str) {
|
|
60
|
+
// return decodeURIComponent(
|
|
61
|
+
// exports.weAtob(str).replace(/(.)/g, function (p) {
|
|
62
|
+
// let code = p.charCodeAt(0).toString(16).toUpperCase();
|
|
63
|
+
// if (code.length < 2) {
|
|
64
|
+
// code = '0' + code;
|
|
65
|
+
// }
|
|
66
|
+
// return '%' + code;
|
|
67
|
+
// })
|
|
68
|
+
// );
|
|
69
|
+
// }
|
|
70
|
+
// function base64_url_decode(str) {
|
|
71
|
+
// let output = str.replace(/-/g, '+').replace(/_/g, '/');
|
|
72
|
+
// switch (output.length % 4) {
|
|
73
|
+
// case 0:
|
|
74
|
+
// break;
|
|
75
|
+
// case 2:
|
|
76
|
+
// output += '==';
|
|
77
|
+
// break;
|
|
78
|
+
// case 3:
|
|
79
|
+
// output += '=';
|
|
80
|
+
// break;
|
|
81
|
+
// default:
|
|
82
|
+
// throw new Error('Illegal base64url string!');
|
|
83
|
+
// }
|
|
84
|
+
// try {
|
|
85
|
+
// return b64DecodeUnicode(output);
|
|
86
|
+
// } catch (err) {
|
|
87
|
+
// return exports.weAtob(output);
|
|
88
|
+
// }
|
|
89
|
+
// }
|
|
90
|
+
// export function weAppJwtDecode(token, options) {
|
|
91
|
+
// if (typeof token !== 'string') {
|
|
92
|
+
// throw new Error('Invalid token specified');
|
|
93
|
+
// }
|
|
94
|
+
// options = options || {};
|
|
95
|
+
// const pos = options.header === true ? 0 : 1;
|
|
96
|
+
// try {
|
|
97
|
+
// return JSON.parse(base64_url_decode(token.split('.')[pos]));
|
|
98
|
+
// } catch (e) {
|
|
99
|
+
// throw new Error('Invalid token specified: ' + (e as Error).message);
|
|
100
|
+
// }
|
|
101
|
+
// }
|
|
102
102
|
|
|
103
|
-
export {
|
|
103
|
+
export { weAtob, weBtoa };
|
package/lib/index.d.ts
CHANGED
|
@@ -284,14 +284,23 @@ declare function downloadURL(url: string, params?: LooseParams): void;
|
|
|
284
284
|
* 通过 A 链接的方式下载
|
|
285
285
|
* @param {string} href
|
|
286
286
|
* @param {string} filename
|
|
287
|
+
* @param {Function} callback
|
|
287
288
|
*/
|
|
288
|
-
declare function downloadHref(href: string, filename: string): void;
|
|
289
|
+
declare function downloadHref(href: string, filename: string, callback?: Function): void;
|
|
289
290
|
/**
|
|
290
291
|
* 将大文件对象通过 A 链接的方式下载
|
|
291
292
|
* @param {Blob} blob
|
|
292
293
|
* @param {string} filename
|
|
294
|
+
* @param {Function} callback
|
|
293
295
|
*/
|
|
294
|
-
declare function downloadBlob(blob: Blob, filename: string): void;
|
|
296
|
+
declare function downloadBlob(blob: Blob, filename: string, callback?: Function): void;
|
|
297
|
+
/**
|
|
298
|
+
* 根据URL下载文件(解决跨域a.download不生效问题)
|
|
299
|
+
* @param {string} url
|
|
300
|
+
* @param {string} filename
|
|
301
|
+
* @param {Function} callback
|
|
302
|
+
*/
|
|
303
|
+
declare function crossDomainDownload(url: string, filename: string, callback?: Function): void;
|
|
295
304
|
type FileType = 'json' | 'csv' | 'xls' | 'xlsx';
|
|
296
305
|
/**
|
|
297
306
|
* 将指定数据格式通过 A 链接的方式下载
|
|
@@ -832,6 +841,5 @@ declare function weBtoa(string: string): string;
|
|
|
832
841
|
* @return {string}
|
|
833
842
|
*/
|
|
834
843
|
declare function weAtob(string: string): string;
|
|
835
|
-
declare function weAppJwtDecode(token: any, options: any): any;
|
|
836
844
|
|
|
837
|
-
export { type AnyArray, type AnyFunc, type AnyObject, type ArrayElements, type DateObj, type DateValue, type DebounceFunc, type FileType, HEX_POOL, type ICanvasWM, type ICompressOptions, type IFieldOptions, type ISearchTreeOpts, type ITreeConf, type IdLike, type LooseParamValue, type LooseParams, type ObjectAssignItem, type OnceFunc, type Params, type PartialDeep, type RandomString, type ReadyCallback, type Replacer, STRING_ARABIC_NUMERALS, STRING_LOWERCASE_ALPHA, STRING_POOL, STRING_UPPERCASE_ALPHA, type SetStyle, type SmoothScrollOptions, type Style, type ThrottleFunc, UNIQUE_NUMBER_SAFE_LENGTH, type UniqueString, type Url, type WithChildren, addClass, arrayEach, arrayEachAsync, arrayInsertBefore, arrayLike, arrayRemove, asyncMap, buildTree, calculateDate, calculateDateTime, chooseLocalFile, cloneDeep, compressImg, cookieDel, cookieGet, cookieSet, copyText, dateParse, dateToEnd, dateToStart, debounce, downloadBlob, downloadData, downloadHref, downloadURL, flatTree, forEachDeep, forEachMap, formatDate, formatNumber, formatTree, fuzzySearchTree, genCanvasWM, getComputedCssVal, getGlobal, getStrWidthPx, getStyle, hasClass, isArray, isBigInt, isBoolean, isDate, isDomReady, isError, isFunction, isJsonString, isNaN, isNull, isNullOrUnDef, isNumber, isObject, isPlainObject, isPrimitive, isRegExp, isString, isSymbol, isUndefined, isValidDate, numberAbbr, numberToHex, objectAssign, objectEach, objectEachAsync, objectFill, objectGet, objectHas, objectMap, objectAssign as objectMerge, objectOmit, objectPick, onDomReady, once, parseQueryParams, pathJoin, pathNormalize, qsParse, qsStringify, randomNumber, randomString, randomUuid, removeClass, searchTreeById, setGlobal, setStyle, smoothScroll, stringAssign, stringCamelCase, stringEscapeHtml, stringFill, stringFormat, stringKebabCase, supportCanvas, throttle, tooltipEvent, typeIs, uniqueNumber, uniqueString, urlDelParams, urlParse, urlSetParams, urlStringify, wait,
|
|
845
|
+
export { type AnyArray, type AnyFunc, type AnyObject, type ArrayElements, type DateObj, type DateValue, type DebounceFunc, type FileType, HEX_POOL, type ICanvasWM, type ICompressOptions, type IFieldOptions, type ISearchTreeOpts, type ITreeConf, type IdLike, type LooseParamValue, type LooseParams, type ObjectAssignItem, type OnceFunc, type Params, type PartialDeep, type RandomString, type ReadyCallback, type Replacer, STRING_ARABIC_NUMERALS, STRING_LOWERCASE_ALPHA, STRING_POOL, STRING_UPPERCASE_ALPHA, type SetStyle, type SmoothScrollOptions, type Style, type ThrottleFunc, UNIQUE_NUMBER_SAFE_LENGTH, type UniqueString, type Url, type WithChildren, addClass, arrayEach, arrayEachAsync, arrayInsertBefore, arrayLike, arrayRemove, asyncMap, buildTree, calculateDate, calculateDateTime, chooseLocalFile, cloneDeep, compressImg, cookieDel, cookieGet, cookieSet, copyText, crossDomainDownload, dateParse, dateToEnd, dateToStart, debounce, downloadBlob, downloadData, downloadHref, downloadURL, flatTree, forEachDeep, forEachMap, formatDate, formatNumber, formatTree, fuzzySearchTree, genCanvasWM, getComputedCssVal, getGlobal, getStrWidthPx, getStyle, hasClass, isArray, isBigInt, isBoolean, isDate, isDomReady, isError, isFunction, isJsonString, isNaN, isNull, isNullOrUnDef, isNumber, isObject, isPlainObject, isPrimitive, isRegExp, isString, isSymbol, isUndefined, isValidDate, numberAbbr, numberToHex, objectAssign, objectEach, objectEachAsync, objectFill, objectGet, objectHas, objectMap, objectAssign as objectMerge, objectOmit, objectPick, onDomReady, once, parseQueryParams, pathJoin, pathNormalize, qsParse, qsStringify, randomNumber, randomString, randomUuid, removeClass, searchTreeById, setGlobal, setStyle, smoothScroll, stringAssign, stringCamelCase, stringEscapeHtml, stringFill, stringFormat, stringKebabCase, supportCanvas, throttle, tooltipEvent, typeIs, uniqueNumber, uniqueString, urlDelParams, urlParse, urlSetParams, urlStringify, wait, weAtob, weBtoa };
|
package/lib/umd/index.js
CHANGED
|
@@ -1188,25 +1188,53 @@
|
|
|
1188
1188
|
* 通过 A 链接的方式下载
|
|
1189
1189
|
* @param {string} href
|
|
1190
1190
|
* @param {string} filename
|
|
1191
|
+
* @param {Function} callback
|
|
1191
1192
|
*/
|
|
1192
|
-
function downloadHref(href, filename) {
|
|
1193
|
+
function downloadHref(href, filename, callback) {
|
|
1193
1194
|
const eleLink = document.createElement('a');
|
|
1194
1195
|
eleLink.download = filename;
|
|
1195
1196
|
eleLink.style.display = 'none';
|
|
1196
1197
|
eleLink.href = href;
|
|
1197
1198
|
document.body.appendChild(eleLink);
|
|
1198
1199
|
eleLink.click();
|
|
1199
|
-
setTimeout(() =>
|
|
1200
|
+
setTimeout(() => {
|
|
1201
|
+
document.body.removeChild(eleLink);
|
|
1202
|
+
if (isFunction(callback)) {
|
|
1203
|
+
callback();
|
|
1204
|
+
}
|
|
1205
|
+
});
|
|
1200
1206
|
}
|
|
1201
1207
|
/**
|
|
1202
1208
|
* 将大文件对象通过 A 链接的方式下载
|
|
1203
1209
|
* @param {Blob} blob
|
|
1204
1210
|
* @param {string} filename
|
|
1211
|
+
* @param {Function} callback
|
|
1205
1212
|
*/
|
|
1206
|
-
function downloadBlob(blob, filename) {
|
|
1213
|
+
function downloadBlob(blob, filename, callback) {
|
|
1207
1214
|
const objURL = URL.createObjectURL(blob);
|
|
1208
1215
|
downloadHref(objURL, filename);
|
|
1209
|
-
setTimeout(() =>
|
|
1216
|
+
setTimeout(() => {
|
|
1217
|
+
URL.revokeObjectURL(objURL);
|
|
1218
|
+
if (isFunction(callback)) {
|
|
1219
|
+
callback();
|
|
1220
|
+
}
|
|
1221
|
+
});
|
|
1222
|
+
}
|
|
1223
|
+
/**
|
|
1224
|
+
* 根据URL下载文件(解决跨域a.download不生效问题)
|
|
1225
|
+
* @param {string} url
|
|
1226
|
+
* @param {string} filename
|
|
1227
|
+
* @param {Function} callback
|
|
1228
|
+
*/
|
|
1229
|
+
function crossDomainDownload(url, filename, callback) {
|
|
1230
|
+
const xhr = new XMLHttpRequest();
|
|
1231
|
+
xhr.open('GET', url, true);
|
|
1232
|
+
xhr.responseType = 'blob';
|
|
1233
|
+
xhr.onload = function () {
|
|
1234
|
+
if (xhr.status === 200)
|
|
1235
|
+
downloadBlob(xhr.response, filename, callback);
|
|
1236
|
+
};
|
|
1237
|
+
xhr.send();
|
|
1210
1238
|
}
|
|
1211
1239
|
/**
|
|
1212
1240
|
* 将指定数据格式通过 A 链接的方式下载
|
|
@@ -1349,49 +1377,49 @@
|
|
|
1349
1377
|
}
|
|
1350
1378
|
return result;
|
|
1351
1379
|
}
|
|
1352
|
-
function b64DecodeUnicode(str) {
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
}
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
}
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
}
|
|
1380
|
+
// function b64DecodeUnicode(str) {
|
|
1381
|
+
// return decodeURIComponent(
|
|
1382
|
+
// exports.weAtob(str).replace(/(.)/g, function (p) {
|
|
1383
|
+
// let code = p.charCodeAt(0).toString(16).toUpperCase();
|
|
1384
|
+
// if (code.length < 2) {
|
|
1385
|
+
// code = '0' + code;
|
|
1386
|
+
// }
|
|
1387
|
+
// return '%' + code;
|
|
1388
|
+
// })
|
|
1389
|
+
// );
|
|
1390
|
+
// }
|
|
1391
|
+
// function base64_url_decode(str) {
|
|
1392
|
+
// let output = str.replace(/-/g, '+').replace(/_/g, '/');
|
|
1393
|
+
// switch (output.length % 4) {
|
|
1394
|
+
// case 0:
|
|
1395
|
+
// break;
|
|
1396
|
+
// case 2:
|
|
1397
|
+
// output += '==';
|
|
1398
|
+
// break;
|
|
1399
|
+
// case 3:
|
|
1400
|
+
// output += '=';
|
|
1401
|
+
// break;
|
|
1402
|
+
// default:
|
|
1403
|
+
// throw new Error('Illegal base64url string!');
|
|
1404
|
+
// }
|
|
1405
|
+
// try {
|
|
1406
|
+
// return b64DecodeUnicode(output);
|
|
1407
|
+
// } catch (err) {
|
|
1408
|
+
// return exports.weAtob(output);
|
|
1409
|
+
// }
|
|
1410
|
+
// }
|
|
1411
|
+
// export function weAppJwtDecode(token, options) {
|
|
1412
|
+
// if (typeof token !== 'string') {
|
|
1413
|
+
// throw new Error('Invalid token specified');
|
|
1414
|
+
// }
|
|
1415
|
+
// options = options || {};
|
|
1416
|
+
// const pos = options.header === true ? 0 : 1;
|
|
1417
|
+
// try {
|
|
1418
|
+
// return JSON.parse(base64_url_decode(token.split('.')[pos]));
|
|
1419
|
+
// } catch (e) {
|
|
1420
|
+
// throw new Error('Invalid token specified: ' + (e as Error).message);
|
|
1421
|
+
// }
|
|
1422
|
+
// }
|
|
1395
1423
|
|
|
1396
1424
|
/**
|
|
1397
1425
|
* 判断是否支持canvas
|
|
@@ -2428,6 +2456,7 @@
|
|
|
2428
2456
|
exports.cookieGet = cookieGet;
|
|
2429
2457
|
exports.cookieSet = cookieSet;
|
|
2430
2458
|
exports.copyText = copyText;
|
|
2459
|
+
exports.crossDomainDownload = crossDomainDownload;
|
|
2431
2460
|
exports.dateParse = dateParse;
|
|
2432
2461
|
exports.dateToEnd = dateToEnd;
|
|
2433
2462
|
exports.dateToStart = dateToStart;
|
|
@@ -2513,7 +2542,6 @@
|
|
|
2513
2542
|
exports.urlSetParams = urlSetParams;
|
|
2514
2543
|
exports.urlStringify = urlStringify;
|
|
2515
2544
|
exports.wait = wait;
|
|
2516
|
-
exports.weAppJwtDecode = weAppJwtDecode;
|
|
2517
2545
|
exports.weAtob = weAtob;
|
|
2518
2546
|
exports.weBtoa = weBtoa;
|
|
2519
2547
|
|