tools-min-ns 1.5.2
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 +85 -0
- package/esm/array/ArrayUtil.d.ts +109 -0
- package/esm/array/ArrayUtil.js +242 -0
- package/esm/array/TreeUtil.d.ts +151 -0
- package/esm/array/TreeUtil.js +412 -0
- package/esm/base/BaseUtil.d.ts +91 -0
- package/esm/base/BaseUtil.js +148 -0
- package/esm/browser/BrowserUtil.d.ts +57 -0
- package/esm/browser/BrowserUtil.js +337 -0
- package/esm/browser/fingerprint.d.ts +120 -0
- package/esm/browser/fingerprint.js +1469 -0
- package/esm/check/CheckUtil.d.ts +110 -0
- package/esm/check/CheckUtil.js +465 -0
- package/esm/common.d.ts +43 -0
- package/esm/common.js +44 -0
- package/esm/config.d.ts +7 -0
- package/esm/config.js +7 -0
- package/esm/cookie/CookieUtil.d.ts +56 -0
- package/esm/cookie/CookieUtil.js +12 -0
- package/esm/cookie/cookie.d.ts +2 -0
- package/esm/cookie/cookie.js +104 -0
- package/esm/date/DateUtil.d.ts +261 -0
- package/esm/date/DateUtil.js +763 -0
- package/esm/env/EnvUtil.d.ts +27 -0
- package/esm/env/EnvUtil.js +29 -0
- package/esm/env/env.d.ts +41 -0
- package/esm/env/env.js +106 -0
- package/esm/func/FunctionUtil.d.ts +77 -0
- package/esm/func/FunctionUtil.js +215 -0
- package/esm/index.d.ts +19 -0
- package/esm/index.js +19 -0
- package/esm/number/NumberUtil.d.ts +96 -0
- package/esm/number/NumberUtil.js +256 -0
- package/esm/object/ObjectUtil.d.ts +41 -0
- package/esm/object/ObjectUtil.js +158 -0
- package/esm/pwd/PasswordUtil.d.ts +33 -0
- package/esm/pwd/PasswordUtil.js +68 -0
- package/esm/pwd/crypto.d.ts +6 -0
- package/esm/pwd/crypto.js +1824 -0
- package/esm/request/RequestUtil.d.ts +52 -0
- package/esm/request/RequestUtil.js +53 -0
- package/esm/request/jsonp.d.ts +18 -0
- package/esm/request/jsonp.js +73 -0
- package/esm/request/mgop/env.d.ts +7 -0
- package/esm/request/mgop/env.js +15 -0
- package/esm/request/mgop/index.d.ts +3 -0
- package/esm/request/mgop/index.js +276 -0
- package/esm/request/mgop/responseCode.d.ts +20 -0
- package/esm/request/mgop/responseCode.js +37 -0
- package/esm/request/mgop/type.d.ts +34 -0
- package/esm/request/mgop/type.js +1 -0
- package/esm/request/uniRquest/index.d.ts +2 -0
- package/esm/request/uniRquest/index.js +66 -0
- package/esm/request/uniRquest/miniapp/index.d.ts +2 -0
- package/esm/request/uniRquest/miniapp/index.js +29 -0
- package/esm/request/uniRquest/miniapp-bytedance/index.d.ts +2 -0
- package/esm/request/uniRquest/miniapp-bytedance/index.js +41 -0
- package/esm/request/uniRquest/types.d.ts +65 -0
- package/esm/request/uniRquest/types.js +36 -0
- package/esm/request/uniRquest/utils.d.ts +9 -0
- package/esm/request/uniRquest/utils.js +69 -0
- package/esm/request/uniRquest/web/index.d.ts +2 -0
- package/esm/request/uniRquest/web/index.js +85 -0
- package/esm/request/uniRquest/wechat-miniprogram/index.d.ts +2 -0
- package/esm/request/uniRquest/wechat-miniprogram/index.js +41 -0
- package/esm/request/uniRquest/weex/index.d.ts +14 -0
- package/esm/request/uniRquest/weex/index.js +59 -0
- package/esm/storage/StorageUtil.d.ts +19 -0
- package/esm/storage/StorageUtil.js +75 -0
- package/esm/string/StringUtil.d.ts +392 -0
- package/esm/string/StringUtil.js +556 -0
- package/esm/system/SystemUtil.d.ts +46 -0
- package/esm/system/SystemUtil.js +122 -0
- package/esm/transfer/MapTransferUtil.d.ts +54 -0
- package/esm/transfer/MapTransferUtil.js +160 -0
- package/esm/transfer/TransferUtil.d.ts +98 -0
- package/esm/transfer/TransferUtil.js +323 -0
- package/esm/types.d.ts +25 -0
- package/esm/types.js +1 -0
- package/esm/url/UrlUtil.d.ts +30 -0
- package/esm/url/UrlUtil.js +85 -0
- package/lib/array/ArrayUtil.d.ts +109 -0
- package/lib/array/ArrayUtil.js +252 -0
- package/lib/array/TreeUtil.d.ts +151 -0
- package/lib/array/TreeUtil.js +422 -0
- package/lib/base/BaseUtil.d.ts +91 -0
- package/lib/base/BaseUtil.js +153 -0
- package/lib/browser/BrowserUtil.d.ts +57 -0
- package/lib/browser/BrowserUtil.js +347 -0
- package/lib/browser/fingerprint.d.ts +120 -0
- package/lib/browser/fingerprint.js +1500 -0
- package/lib/check/CheckUtil.d.ts +110 -0
- package/lib/check/CheckUtil.js +475 -0
- package/lib/common.d.ts +43 -0
- package/lib/common.js +50 -0
- package/lib/config.d.ts +7 -0
- package/lib/config.js +12 -0
- package/lib/cookie/CookieUtil.d.ts +56 -0
- package/lib/cookie/CookieUtil.js +22 -0
- package/lib/cookie/cookie.d.ts +2 -0
- package/lib/cookie/cookie.js +109 -0
- package/lib/date/DateUtil.d.ts +261 -0
- package/lib/date/DateUtil.js +773 -0
- package/lib/env/EnvUtil.d.ts +27 -0
- package/lib/env/EnvUtil.js +39 -0
- package/lib/env/env.d.ts +41 -0
- package/lib/env/env.js +112 -0
- package/lib/func/FunctionUtil.d.ts +77 -0
- package/lib/func/FunctionUtil.js +225 -0
- package/lib/index.d.ts +19 -0
- package/lib/index.js +144 -0
- package/lib/number/NumberUtil.d.ts +96 -0
- package/lib/number/NumberUtil.js +266 -0
- package/lib/object/ObjectUtil.d.ts +41 -0
- package/lib/object/ObjectUtil.js +168 -0
- package/lib/pwd/PasswordUtil.d.ts +33 -0
- package/lib/pwd/PasswordUtil.js +78 -0
- package/lib/pwd/crypto.d.ts +6 -0
- package/lib/pwd/crypto.js +1829 -0
- package/lib/request/RequestUtil.d.ts +52 -0
- package/lib/request/RequestUtil.js +94 -0
- package/lib/request/jsonp.d.ts +18 -0
- package/lib/request/jsonp.js +80 -0
- package/lib/request/mgop/env.d.ts +7 -0
- package/lib/request/mgop/env.js +21 -0
- package/lib/request/mgop/index.d.ts +3 -0
- package/lib/request/mgop/index.js +289 -0
- package/lib/request/mgop/responseCode.d.ts +20 -0
- package/lib/request/mgop/responseCode.js +42 -0
- package/lib/request/mgop/type.d.ts +34 -0
- package/lib/request/mgop/type.js +5 -0
- package/lib/request/uniRquest/index.d.ts +2 -0
- package/lib/request/uniRquest/index.js +77 -0
- package/lib/request/uniRquest/miniapp/index.d.ts +2 -0
- package/lib/request/uniRquest/miniapp/index.js +35 -0
- package/lib/request/uniRquest/miniapp-bytedance/index.d.ts +2 -0
- package/lib/request/uniRquest/miniapp-bytedance/index.js +47 -0
- package/lib/request/uniRquest/types.d.ts +65 -0
- package/lib/request/uniRquest/types.js +42 -0
- package/lib/request/uniRquest/utils.d.ts +9 -0
- package/lib/request/uniRquest/utils.js +83 -0
- package/lib/request/uniRquest/web/index.d.ts +2 -0
- package/lib/request/uniRquest/web/index.js +91 -0
- package/lib/request/uniRquest/wechat-miniprogram/index.d.ts +2 -0
- package/lib/request/uniRquest/wechat-miniprogram/index.js +47 -0
- package/lib/request/uniRquest/weex/index.d.ts +14 -0
- package/lib/request/uniRquest/weex/index.js +65 -0
- package/lib/storage/StorageUtil.d.ts +19 -0
- package/lib/storage/StorageUtil.js +85 -0
- package/lib/string/StringUtil.d.ts +392 -0
- package/lib/string/StringUtil.js +566 -0
- package/lib/system/SystemUtil.d.ts +46 -0
- package/lib/system/SystemUtil.js +132 -0
- package/lib/transfer/MapTransferUtil.d.ts +54 -0
- package/lib/transfer/MapTransferUtil.js +165 -0
- package/lib/transfer/TransferUtil.d.ts +98 -0
- package/lib/transfer/TransferUtil.js +333 -0
- package/lib/types.d.ts +25 -0
- package/lib/types.js +5 -0
- package/lib/url/UrlUtil.d.ts +30 -0
- package/lib/url/UrlUtil.js +95 -0
- package/package.json +56 -0
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 系统工具
|
|
3
|
+
* @description
|
|
4
|
+
* @author nanshen
|
|
5
|
+
* @creat 2021-09-15 14:24:57
|
|
6
|
+
*/
|
|
7
|
+
import TransferUtil from '../transfer/TransferUtil';
|
|
8
|
+
var SystemUtil;
|
|
9
|
+
(function (SystemUtil) {
|
|
10
|
+
/**
|
|
11
|
+
* @name 把fileList转换为stringList(仅用于antd组件上传)
|
|
12
|
+
* @param list 文件list
|
|
13
|
+
* @example
|
|
14
|
+
* const list = [{ fileList: { response: { data: 'asfja.png' },{ fileList: { response: { data: 'asfja1.png' }]
|
|
15
|
+
* getUrlByFileList(list) => 'asfja.png,asfja1.png'
|
|
16
|
+
*/
|
|
17
|
+
SystemUtil.getUrlByFileList = function (list) {
|
|
18
|
+
var _a;
|
|
19
|
+
var newList = ((_a = list === null || list === void 0 ? void 0 : list.fileList) === null || _a === void 0 ? void 0 : _a.map(function (ele) {
|
|
20
|
+
var _a;
|
|
21
|
+
return (_a = ele.response) === null || _a === void 0 ? void 0 : _a.data;
|
|
22
|
+
}).filter(function (ele) {
|
|
23
|
+
return ele;
|
|
24
|
+
})) || [];
|
|
25
|
+
return newList.length ? "".concat(newList) : undefined;
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* 通过url地址下载文件
|
|
29
|
+
* @param url 地址
|
|
30
|
+
* @param name 文件名
|
|
31
|
+
* @example
|
|
32
|
+
* downloadFile('http://XXX.txt','text.txt')
|
|
33
|
+
*/
|
|
34
|
+
function downloadFile(url, name) {
|
|
35
|
+
var a = document.createElement('a');
|
|
36
|
+
a.setAttribute('href', url);
|
|
37
|
+
if (name) a.setAttribute('download', name);
|
|
38
|
+
a.setAttribute('target', '_blank');
|
|
39
|
+
var clickEvent = document.createEvent('MouseEvents');
|
|
40
|
+
clickEvent.initEvent('click', true, true);
|
|
41
|
+
a.dispatchEvent(clickEvent);
|
|
42
|
+
}
|
|
43
|
+
SystemUtil.downloadFile = downloadFile;
|
|
44
|
+
/**
|
|
45
|
+
* 通过base64下载文件
|
|
46
|
+
* @param base64 base64字符串
|
|
47
|
+
* @param name 文件名
|
|
48
|
+
* @example
|
|
49
|
+
* downloadFileByBase64('data:text/plain;base64,dGV4dDF0ZXh0Mg==','text.txt')
|
|
50
|
+
*/
|
|
51
|
+
function downloadFileByBase64(base64, name) {
|
|
52
|
+
var myBlob = TransferUtil.getBlobByBase64(base64);
|
|
53
|
+
if (!myBlob) return;
|
|
54
|
+
var myUrl = URL.createObjectURL(myBlob);
|
|
55
|
+
downloadFile(myUrl, name);
|
|
56
|
+
}
|
|
57
|
+
SystemUtil.downloadFileByBase64 = downloadFileByBase64;
|
|
58
|
+
/**
|
|
59
|
+
* 通过Blob下载文件
|
|
60
|
+
* @param response BlobPart
|
|
61
|
+
* @param name 文件名
|
|
62
|
+
*/
|
|
63
|
+
SystemUtil.downloadFileByBlob = function (response, name) {
|
|
64
|
+
var myBlob = new Blob([response], {
|
|
65
|
+
type: 'application/vnd.ms-excel,charset=utf-8'
|
|
66
|
+
});
|
|
67
|
+
if (!myBlob) return;
|
|
68
|
+
var myUrl = URL.createObjectURL(myBlob);
|
|
69
|
+
downloadFile(myUrl, name);
|
|
70
|
+
};
|
|
71
|
+
/**
|
|
72
|
+
* 拷贝文本至剪切板
|
|
73
|
+
* @param text 文本
|
|
74
|
+
* @example
|
|
75
|
+
* copyText2Clipboard('🦄🌈');
|
|
76
|
+
*/
|
|
77
|
+
function copyText2Clipboard(text) {
|
|
78
|
+
var _a;
|
|
79
|
+
// 创建一个界面外的文本输入框
|
|
80
|
+
var element = document.createElement('textarea');
|
|
81
|
+
// 缓存之前激活的dom
|
|
82
|
+
var previouslyFocusedElement = document.activeElement;
|
|
83
|
+
// 赋值
|
|
84
|
+
element.value = text;
|
|
85
|
+
// Prevent keyboard from showing on mobile
|
|
86
|
+
element.setAttribute('readonly', '');
|
|
87
|
+
// 界面外的css赋值
|
|
88
|
+
element.style.contain = 'strict';
|
|
89
|
+
element.style.position = 'absolute';
|
|
90
|
+
element.style.left = '-9999px';
|
|
91
|
+
element.style.fontSize = '12pt'; // Prevent zooming on iOS
|
|
92
|
+
// 创建选区
|
|
93
|
+
var selection = document.getSelection();
|
|
94
|
+
var originalRange;
|
|
95
|
+
if ((selection === null || selection === void 0 ? void 0 : selection.rangeCount) > 0) {
|
|
96
|
+
originalRange = selection === null || selection === void 0 ? void 0 : selection.getRangeAt(0);
|
|
97
|
+
}
|
|
98
|
+
// 插入的dom中
|
|
99
|
+
document.body.append(element);
|
|
100
|
+
// 选中
|
|
101
|
+
element.select();
|
|
102
|
+
// Explicit selection workaround for iOS
|
|
103
|
+
element.selectionStart = 0;
|
|
104
|
+
element.selectionEnd = text.length;
|
|
105
|
+
var isSuccess = false;
|
|
106
|
+
try {
|
|
107
|
+
isSuccess = document.execCommand('copy');
|
|
108
|
+
} catch (_) {}
|
|
109
|
+
element.remove();
|
|
110
|
+
if (originalRange) {
|
|
111
|
+
// 把原本dom中的选区还原到dom中
|
|
112
|
+
selection === null || selection === void 0 ? void 0 : selection.removeAllRanges();
|
|
113
|
+
selection === null || selection === void 0 ? void 0 : selection.addRange(originalRange);
|
|
114
|
+
}
|
|
115
|
+
// Get the focus back on the previously focused element, if any
|
|
116
|
+
// focus选中
|
|
117
|
+
(_a = previouslyFocusedElement === null || previouslyFocusedElement === void 0 ? void 0 : previouslyFocusedElement.focus) === null || _a === void 0 ? void 0 : _a.call(previouslyFocusedElement);
|
|
118
|
+
return isSuccess;
|
|
119
|
+
}
|
|
120
|
+
SystemUtil.copyText2Clipboard = copyText2Clipboard;
|
|
121
|
+
})(SystemUtil || (SystemUtil = {}));
|
|
122
|
+
export default SystemUtil;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
declare namespace MapTransferUtil {
|
|
2
|
+
/**
|
|
3
|
+
* 百度坐标系 (BD-09) 与 火星坐标系 (GCJ-02)的转换
|
|
4
|
+
* 即 百度 转 谷歌、高德
|
|
5
|
+
* @param bd_lon
|
|
6
|
+
* @param bd_lat
|
|
7
|
+
* @returns {*[]}
|
|
8
|
+
*/
|
|
9
|
+
function bd09togcj02(bd_lon: number, bd_lat: number): number[];
|
|
10
|
+
/**
|
|
11
|
+
* 火星坐标系 (GCJ-02) 与百度坐标系 (BD-09) 的转换
|
|
12
|
+
* 即谷歌、高德 转 百度
|
|
13
|
+
* @param lng
|
|
14
|
+
* @param lat
|
|
15
|
+
* @returns {*[]}
|
|
16
|
+
*/
|
|
17
|
+
function gcj02tobd09(lng: number, lat: number): number[];
|
|
18
|
+
/**
|
|
19
|
+
* 百度坐标转wgs84
|
|
20
|
+
* @param {*} lng
|
|
21
|
+
* @param {*} lat
|
|
22
|
+
* @returns
|
|
23
|
+
*/
|
|
24
|
+
function bd09towgs84(lng: number, lat: number): number[];
|
|
25
|
+
/**
|
|
26
|
+
* wgs84转百度
|
|
27
|
+
* @param {*} lng
|
|
28
|
+
* @param {*} lat
|
|
29
|
+
* @returns
|
|
30
|
+
*/
|
|
31
|
+
function wgs84tobd09(lng: number, lat: number): number[];
|
|
32
|
+
/**
|
|
33
|
+
* WGS84转GCj02
|
|
34
|
+
* @param lng
|
|
35
|
+
* @param lat
|
|
36
|
+
* @returns {*[]}
|
|
37
|
+
*/
|
|
38
|
+
function wgs84togcj02(lng: number, lat: number): number[];
|
|
39
|
+
/**
|
|
40
|
+
* GCJ02 转换为 WGS84
|
|
41
|
+
* @param lng
|
|
42
|
+
* @param lat
|
|
43
|
+
* @returns {*[]}
|
|
44
|
+
*/
|
|
45
|
+
function gcj02towgs84(lng: number, lat: number): number[];
|
|
46
|
+
/**
|
|
47
|
+
* 判断是否在国内,不在国内则不做偏移
|
|
48
|
+
* @param lng
|
|
49
|
+
* @param lat
|
|
50
|
+
* @returns {boolean}
|
|
51
|
+
*/
|
|
52
|
+
function out_of_china(lng: number, lat: number): boolean;
|
|
53
|
+
}
|
|
54
|
+
export default MapTransferUtil;
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
var __read = this && this.__read || function (o, n) {
|
|
2
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
3
|
+
if (!m) return o;
|
|
4
|
+
var i = m.call(o),
|
|
5
|
+
r,
|
|
6
|
+
ar = [],
|
|
7
|
+
e;
|
|
8
|
+
try {
|
|
9
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
10
|
+
} catch (error) {
|
|
11
|
+
e = {
|
|
12
|
+
error: error
|
|
13
|
+
};
|
|
14
|
+
} finally {
|
|
15
|
+
try {
|
|
16
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
17
|
+
} finally {
|
|
18
|
+
if (e) throw e.error;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
return ar;
|
|
22
|
+
};
|
|
23
|
+
// 定义一些常量
|
|
24
|
+
var x_PI = 3.14159265358979324 * 3000.0 / 180.0;
|
|
25
|
+
var PI = 3.1415926535897932384626;
|
|
26
|
+
var a = 6378245.0;
|
|
27
|
+
var ee = 0.00669342162296594323;
|
|
28
|
+
var MapTransferUtil;
|
|
29
|
+
(function (MapTransferUtil) {
|
|
30
|
+
/**
|
|
31
|
+
* 百度坐标系 (BD-09) 与 火星坐标系 (GCJ-02)的转换
|
|
32
|
+
* 即 百度 转 谷歌、高德
|
|
33
|
+
* @param bd_lon
|
|
34
|
+
* @param bd_lat
|
|
35
|
+
* @returns {*[]}
|
|
36
|
+
*/
|
|
37
|
+
function bd09togcj02(bd_lon, bd_lat) {
|
|
38
|
+
var x_pi = 3.14159265358979324 * 3000.0 / 180.0;
|
|
39
|
+
var x = bd_lon - 0.0065;
|
|
40
|
+
var y = bd_lat - 0.006;
|
|
41
|
+
var z = Math.sqrt(x * x + y * y) - 0.00002 * Math.sin(y * x_pi);
|
|
42
|
+
var theta = Math.atan2(y, x) - 0.000003 * Math.cos(x * x_pi);
|
|
43
|
+
var gg_lng = z * Math.cos(theta);
|
|
44
|
+
var gg_lat = z * Math.sin(theta);
|
|
45
|
+
return [gg_lng, gg_lat];
|
|
46
|
+
}
|
|
47
|
+
MapTransferUtil.bd09togcj02 = bd09togcj02;
|
|
48
|
+
/**
|
|
49
|
+
* 火星坐标系 (GCJ-02) 与百度坐标系 (BD-09) 的转换
|
|
50
|
+
* 即谷歌、高德 转 百度
|
|
51
|
+
* @param lng
|
|
52
|
+
* @param lat
|
|
53
|
+
* @returns {*[]}
|
|
54
|
+
*/
|
|
55
|
+
function gcj02tobd09(lng, lat) {
|
|
56
|
+
var z = Math.sqrt(lng * lng + lat * lat) + 0.00002 * Math.sin(lat * x_PI);
|
|
57
|
+
var theta = Math.atan2(lat, lng) + 0.000003 * Math.cos(lng * x_PI);
|
|
58
|
+
var bd_lng = z * Math.cos(theta) + 0.0065;
|
|
59
|
+
var bd_lat = z * Math.sin(theta) + 0.006;
|
|
60
|
+
return [bd_lng, bd_lat];
|
|
61
|
+
}
|
|
62
|
+
MapTransferUtil.gcj02tobd09 = gcj02tobd09;
|
|
63
|
+
/**
|
|
64
|
+
* 百度坐标转wgs84
|
|
65
|
+
* @param {*} lng
|
|
66
|
+
* @param {*} lat
|
|
67
|
+
* @returns
|
|
68
|
+
*/
|
|
69
|
+
function bd09towgs84(lng, lat) {
|
|
70
|
+
var _a = __read(bd09togcj02(lng, lat), 2),
|
|
71
|
+
gcjLng = _a[0],
|
|
72
|
+
gcjLat = _a[1];
|
|
73
|
+
return gcj02towgs84(gcjLng, gcjLat);
|
|
74
|
+
}
|
|
75
|
+
MapTransferUtil.bd09towgs84 = bd09towgs84;
|
|
76
|
+
/**
|
|
77
|
+
* wgs84转百度
|
|
78
|
+
* @param {*} lng
|
|
79
|
+
* @param {*} lat
|
|
80
|
+
* @returns
|
|
81
|
+
*/
|
|
82
|
+
function wgs84tobd09(lng, lat) {
|
|
83
|
+
var _a = __read(wgs84togcj02(lng, lat), 2),
|
|
84
|
+
gcjLng = _a[0],
|
|
85
|
+
gcjLat = _a[1];
|
|
86
|
+
return gcj02tobd09(gcjLng, gcjLat);
|
|
87
|
+
}
|
|
88
|
+
MapTransferUtil.wgs84tobd09 = wgs84tobd09;
|
|
89
|
+
/**
|
|
90
|
+
* WGS84转GCj02
|
|
91
|
+
* @param lng
|
|
92
|
+
* @param lat
|
|
93
|
+
* @returns {*[]}
|
|
94
|
+
*/
|
|
95
|
+
function wgs84togcj02(lng, lat) {
|
|
96
|
+
if (out_of_china(lng, lat)) {
|
|
97
|
+
return [lng, lat];
|
|
98
|
+
}
|
|
99
|
+
var dlat = transformlat(lng - 105.0, lat - 35.0);
|
|
100
|
+
var dlng = transformlng(lng - 105.0, lat - 35.0);
|
|
101
|
+
var radlat = lat / 180.0 * PI;
|
|
102
|
+
var magic = Math.sin(radlat);
|
|
103
|
+
magic = 1 - ee * magic * magic;
|
|
104
|
+
var sqrtmagic = Math.sqrt(magic);
|
|
105
|
+
dlat = dlat * 180.0 / (a * (1 - ee) / (magic * sqrtmagic) * PI);
|
|
106
|
+
dlng = dlng * 180.0 / (a / sqrtmagic * Math.cos(radlat) * PI);
|
|
107
|
+
var mglat = lat + dlat;
|
|
108
|
+
var mglng = lng + dlng;
|
|
109
|
+
return [mglng, mglat];
|
|
110
|
+
}
|
|
111
|
+
MapTransferUtil.wgs84togcj02 = wgs84togcj02;
|
|
112
|
+
/**
|
|
113
|
+
* GCJ02 转换为 WGS84
|
|
114
|
+
* @param lng
|
|
115
|
+
* @param lat
|
|
116
|
+
* @returns {*[]}
|
|
117
|
+
*/
|
|
118
|
+
function gcj02towgs84(lng, lat) {
|
|
119
|
+
if (out_of_china(lng, lat)) {
|
|
120
|
+
return [lng, lat];
|
|
121
|
+
}
|
|
122
|
+
var dlat = transformlat(lng - 105.0, lat - 35.0);
|
|
123
|
+
var dlng = transformlng(lng - 105.0, lat - 35.0);
|
|
124
|
+
var radlat = lat / 180.0 * PI;
|
|
125
|
+
var magic = Math.sin(radlat);
|
|
126
|
+
magic = 1 - ee * magic * magic;
|
|
127
|
+
var sqrtmagic = Math.sqrt(magic);
|
|
128
|
+
dlat = dlat * 180.0 / (a * (1 - ee) / (magic * sqrtmagic) * PI);
|
|
129
|
+
dlng = dlng * 180.0 / (a / sqrtmagic * Math.cos(radlat) * PI);
|
|
130
|
+
var mglat = lat + dlat;
|
|
131
|
+
var mglng = lng + dlng;
|
|
132
|
+
return [lng * 2 - mglng, lat * 2 - mglat];
|
|
133
|
+
}
|
|
134
|
+
MapTransferUtil.gcj02towgs84 = gcj02towgs84;
|
|
135
|
+
function transformlat(lng, lat) {
|
|
136
|
+
var ret = -100.0 + 2.0 * lng + 3.0 * lat + 0.2 * lat * lat + 0.1 * lng * lat + 0.2 * Math.sqrt(Math.abs(lng));
|
|
137
|
+
ret += (20.0 * Math.sin(6.0 * lng * PI) + 20.0 * Math.sin(2.0 * lng * PI)) * 2.0 / 3.0;
|
|
138
|
+
ret += (20.0 * Math.sin(lat * PI) + 40.0 * Math.sin(lat / 3.0 * PI)) * 2.0 / 3.0;
|
|
139
|
+
ret += (160.0 * Math.sin(lat / 12.0 * PI) + 320 * Math.sin(lat * PI / 30.0)) * 2.0 / 3.0;
|
|
140
|
+
return ret;
|
|
141
|
+
}
|
|
142
|
+
function transformlng(lng, lat) {
|
|
143
|
+
var ret = 300.0 + lng + 2.0 * lat + 0.1 * lng * lng + 0.1 * lng * lat + 0.1 * Math.sqrt(Math.abs(lng));
|
|
144
|
+
ret += (20.0 * Math.sin(6.0 * lng * PI) + 20.0 * Math.sin(2.0 * lng * PI)) * 2.0 / 3.0;
|
|
145
|
+
ret += (20.0 * Math.sin(lng * PI) + 40.0 * Math.sin(lng / 3.0 * PI)) * 2.0 / 3.0;
|
|
146
|
+
ret += (150.0 * Math.sin(lng / 12.0 * PI) + 300.0 * Math.sin(lng / 30.0 * PI)) * 2.0 / 3.0;
|
|
147
|
+
return ret;
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* 判断是否在国内,不在国内则不做偏移
|
|
151
|
+
* @param lng
|
|
152
|
+
* @param lat
|
|
153
|
+
* @returns {boolean}
|
|
154
|
+
*/
|
|
155
|
+
function out_of_china(lng, lat) {
|
|
156
|
+
return lng < 72.004 || lng > 137.8347 || lat < 0.8293 || lat > 55.8271 || false;
|
|
157
|
+
}
|
|
158
|
+
MapTransferUtil.out_of_china = out_of_china;
|
|
159
|
+
})(MapTransferUtil || (MapTransferUtil = {}));
|
|
160
|
+
export default MapTransferUtil;
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
declare namespace TransferUtil {
|
|
2
|
+
/**
|
|
3
|
+
* 字符串转成base64编码
|
|
4
|
+
* @param { String } str 字符串
|
|
5
|
+
* @example
|
|
6
|
+
* base64Encode('nanshen') => bmFuc2hlbg==
|
|
7
|
+
*/
|
|
8
|
+
function base64Encode(str: string): string;
|
|
9
|
+
/**
|
|
10
|
+
* base64解码成字符串
|
|
11
|
+
* @param { String } str base64字符串
|
|
12
|
+
* @example
|
|
13
|
+
* base64Decode('bmFuc2hlbg==') => nanshen
|
|
14
|
+
*/
|
|
15
|
+
function base64Decode(str: string): string;
|
|
16
|
+
/**
|
|
17
|
+
* 将文件转成base64
|
|
18
|
+
* @param file 文件
|
|
19
|
+
* @example
|
|
20
|
+
* const fn = async () => {
|
|
21
|
+
* const newFile = new File(['text1', 'text2'], 'test.txt', {type: 'text/plain'})
|
|
22
|
+
* const data = await getBase64ByFile(newFile)
|
|
23
|
+
* console.log(data); => data:text/plain;base64,dGV4dDF0ZXh0Mg==
|
|
24
|
+
* }
|
|
25
|
+
* fn()
|
|
26
|
+
*/
|
|
27
|
+
function getBase64ByFile(file: any): Promise<unknown> | undefined;
|
|
28
|
+
/**
|
|
29
|
+
* 将base64转成文件
|
|
30
|
+
* @param file 文件
|
|
31
|
+
* @example
|
|
32
|
+
* getFileByBase64('data:text/plain;base64,dGV4dDF0ZXh0Mg==','test.txt') => new File(['text1', 'text2'], 'test.txt', {type: 'text/plain'})
|
|
33
|
+
*/
|
|
34
|
+
function getFileByBase64(base64: string, filename: string): File | undefined;
|
|
35
|
+
/**
|
|
36
|
+
* base64转blob流
|
|
37
|
+
* @param base64 base64字符串
|
|
38
|
+
* @example
|
|
39
|
+
* getBlobByBase64('data:text/plain;base64,dGV4dDF0ZXh0Mg==') => new Blob(['text1', 'text2'], {type : 'text/plain'})
|
|
40
|
+
*/
|
|
41
|
+
function getBlobByBase64(base64: string): Blob | undefined;
|
|
42
|
+
/**
|
|
43
|
+
* blob流转换为base64
|
|
44
|
+
* @param blob blob流
|
|
45
|
+
* @example
|
|
46
|
+
* const fn = async () => {
|
|
47
|
+
* const newBlob = new Blob(['text1', 'text2'], {type : 'text/plain'})
|
|
48
|
+
* const data = await blobToDataURI(newBlob)
|
|
49
|
+
* console.log(data); => data:text/plain;base64,dGV4dDF0ZXh0Mg==
|
|
50
|
+
* }
|
|
51
|
+
* fn()
|
|
52
|
+
*/
|
|
53
|
+
function blobToDataURI(blob: any): Promise<unknown> | undefined;
|
|
54
|
+
/**
|
|
55
|
+
* html编码(转义)
|
|
56
|
+
* @param { String } text 需要转义的字符串
|
|
57
|
+
* @param { Boolean } useDom 转换方法选择
|
|
58
|
+
* @example
|
|
59
|
+
* htmlEncode('<p>你好</p>') => <p>你好</p>
|
|
60
|
+
*/
|
|
61
|
+
function htmlEncode(text: string, useDom?: boolean): string;
|
|
62
|
+
/**
|
|
63
|
+
* html解码(反转义)
|
|
64
|
+
* @param { String } text 需要反转义的字符串
|
|
65
|
+
* @param { Boolean } useDom 转换方法选择
|
|
66
|
+
* @example
|
|
67
|
+
* htmlDecode('<p>你好</p>') => <p>你好</p>
|
|
68
|
+
*/
|
|
69
|
+
function htmlDecode(text: string, useDom?: boolean): string;
|
|
70
|
+
/**
|
|
71
|
+
* 现金额转大写
|
|
72
|
+
* @param n 阿拉伯数字
|
|
73
|
+
* @example
|
|
74
|
+
* digitUppercase(1) => 壹元整
|
|
75
|
+
*/
|
|
76
|
+
function digitUppercase(n: number): string;
|
|
77
|
+
/**
|
|
78
|
+
* 数字转大写
|
|
79
|
+
* @param n 阿拉伯数字
|
|
80
|
+
* @example
|
|
81
|
+
* digitUppercase(1) => 一
|
|
82
|
+
*/
|
|
83
|
+
function toChinesNum(num: number): string;
|
|
84
|
+
/**
|
|
85
|
+
* 数字大于千万亿加单位
|
|
86
|
+
* @param value 阿拉伯数字
|
|
87
|
+
* @param index 保留几位小数(默认为2)
|
|
88
|
+
* @example
|
|
89
|
+
* numPlusUnit(1213) => 1.21千
|
|
90
|
+
*/
|
|
91
|
+
function numPlusUnit(value: number, index?: number): string;
|
|
92
|
+
/**
|
|
93
|
+
* 字节转单位
|
|
94
|
+
* @param bytes - 字节
|
|
95
|
+
*/
|
|
96
|
+
const getFileSizeByBytes: (bytes: number) => string;
|
|
97
|
+
}
|
|
98
|
+
export default TransferUtil;
|