gis-common 3.1.1 → 3.1.3
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/dist/gis-common.es.js +1751 -0
- package/dist/gis-common.umd.js +1 -0
- package/package.json +22 -25
- package/dist/resource.min.js +0 -1
|
@@ -0,0 +1,1751 @@
|
|
|
1
|
+
var AnimateUtils = {
|
|
2
|
+
animate(ele, attr_options, callback, timefn = "swing", speed = 5) {
|
|
3
|
+
for (var attr in attr_options) {
|
|
4
|
+
attr_options[attr] = {
|
|
5
|
+
target: attr === "opacity" ? parseInt(attr_options[attr] * 100) : attr_options[attr],
|
|
6
|
+
iNow: attr === "opacity" ? parseInt(getComputedStyle(ele)[attr] * 100) : parseInt(getComputedStyle(ele)[attr])
|
|
7
|
+
};
|
|
8
|
+
}
|
|
9
|
+
if (timefn === "liner") {
|
|
10
|
+
speed = attr_options[attr].iNow < attr_options[attr].target ? Math.abs(speed) : -Math.abs(speed);
|
|
11
|
+
}
|
|
12
|
+
clearInterval(ele.timer);
|
|
13
|
+
ele.timer = setInterval(function() {
|
|
14
|
+
for (var attr2 in attr_options) {
|
|
15
|
+
var target = attr_options[attr2].target;
|
|
16
|
+
var iNow = attr_options[attr2].iNow;
|
|
17
|
+
if (timefn === "swing") {
|
|
18
|
+
speed = (target - iNow) / 20;
|
|
19
|
+
speed = speed > 0 ? Math.ceil(speed) : Math.floor(speed);
|
|
20
|
+
}
|
|
21
|
+
if (Math.abs(target - iNow) <= Math.abs(speed)) {
|
|
22
|
+
if (attr2 === "opacity") {
|
|
23
|
+
ele.style[attr2] = target / 100;
|
|
24
|
+
} else {
|
|
25
|
+
ele.style[attr2] = target + "px";
|
|
26
|
+
}
|
|
27
|
+
delete attr_options[attr2];
|
|
28
|
+
for (var num in attr_options) {
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
clearInterval(ele.timer);
|
|
32
|
+
typeof callback === "function" ? callback() : "";
|
|
33
|
+
} else {
|
|
34
|
+
attr_options[attr2].iNow += speed;
|
|
35
|
+
if (attr2 === "opacity") {
|
|
36
|
+
ele.style[attr2] = attr_options[attr2].iNow / 100;
|
|
37
|
+
} else {
|
|
38
|
+
ele.style[attr2] = attr_options[attr2].iNow + "px";
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}, 30);
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
var EventType = {
|
|
46
|
+
MAP_RENDER: "mapRender",
|
|
47
|
+
MAP_READY: "mapReady",
|
|
48
|
+
MOUSE_CLICK: "click",
|
|
49
|
+
MOUSE_DOUBLE_CLICK: "dblclick",
|
|
50
|
+
MOUSE_MOVE: "mousemove",
|
|
51
|
+
MOUSE_IN: "mousein",
|
|
52
|
+
MOUSE_OUT: "mouseout",
|
|
53
|
+
MOUSE_RIGHT_CLICK: "mouseRightClick",
|
|
54
|
+
KEY_DOWN: "keyDown",
|
|
55
|
+
KEY_UP: "keyUp",
|
|
56
|
+
DRAW_ACTIVE: "drawActive",
|
|
57
|
+
DRAW_MOVE: "drawMove",
|
|
58
|
+
DRAW_COMPLETE: "drawComplete",
|
|
59
|
+
MQTT_CONNECT: "mqttConnect",
|
|
60
|
+
MQTT_ERROR: "mqttError",
|
|
61
|
+
MQTT_MESSAGE: "mqttMessage",
|
|
62
|
+
MQTT_CLOSE: "mqttClose",
|
|
63
|
+
WEB_SOCKET_CONNECT: "webSocketConnect",
|
|
64
|
+
WEB_SOCKET_ERROR: "webSocketError",
|
|
65
|
+
WEB_SOCKET_MESSAGE: "webSocketMessage",
|
|
66
|
+
WEB_SOCKET_CLOSE: "webSocketClose"
|
|
67
|
+
};
|
|
68
|
+
var ErrorType = {
|
|
69
|
+
LOGIN_EXPIRED: "\u767B\u5F55\u4FE1\u606F\u8FC7\u671F\uFF0C\u8BF7\u91CD\u65B0\u767B\u5F55",
|
|
70
|
+
CROSS_ERROR: "\u8DE8\u57DF\u8BBF\u95EE",
|
|
71
|
+
UNEXIST_RESOURCE: "\u8D44\u6E90\u4E0D\u5B58\u5728",
|
|
72
|
+
TIMEOUT: "\u8BF7\u6C42\u8D85\u65F6",
|
|
73
|
+
INTERNAL_ERROR: "\u5185\u90E8\u9519\u8BEF",
|
|
74
|
+
NETWORK_ERROR: "\u8BF7\u6C42\u5931\u8D25\uFF0C\u8BF7\u68C0\u67E5\u7F51\u7EDC\u662F\u5426\u5DF2\u8FDE\u63A5",
|
|
75
|
+
PROCESS_FAIL: "\u5904\u7406\u5931\u8D25",
|
|
76
|
+
AUTH_VERIFY_ERROR: "\u6743\u9650\u9A8C\u8BC1\u5931\u8D25",
|
|
77
|
+
NO_DATA_FOUND: "\u672A\u627E\u5230\u6570\u636E",
|
|
78
|
+
DUPLICATE_INSTANCE: "\u5B9E\u4F8B\u4E3A\u5355\u4F8B\u6A21\u5F0F\uFF0C\u4E0D\u5141\u8BB8\u91CD\u590D\u6784\u5EFA",
|
|
79
|
+
COORDINATE_ERROR: "\u5750\u6807\u9A8C\u8BC1\u5931\u8D25",
|
|
80
|
+
JSON_PARSE_ERROR: "JSON\u89E3\u6790\u5931\u8D25\uFF0C\u683C\u5F0F\u6709\u8BEF",
|
|
81
|
+
JSON_VALUE_ERROR: "JSON\u65E0\u6B64\u952E",
|
|
82
|
+
PARAMETER_ERROR: "\u9A8C\u8BC1\u6570\u636E\u7C7B\u578B\u5931\u8D25",
|
|
83
|
+
PARAMETER_ERROR_ARRAY: "\u683C\u5F0F\u7C7B\u578B\u9A8C\u8BC1\u5931\u8D25\uFF1A\u5FC5\u987B\u662F\u6570\u7EC4",
|
|
84
|
+
PARAMETER_ERROR_STRING: "\u683C\u5F0F\u7C7B\u578B\u9A8C\u8BC1\u5931\u8D25\uFF1A\u5FC5\u987B\u662F\u5B57\u7B26",
|
|
85
|
+
PARAMETER_ERROR_FUNCTION: "\u683C\u5F0F\u7C7B\u578B\u9A8C\u8BC1\u5931\u8D25\uFF1A\u5FC5\u987B\u662F\u51FD\u6570",
|
|
86
|
+
PARAMETER_ERROR_OBJECT: "\u683C\u5F0F\u7C7B\u578B\u9A8C\u8BC1\u5931\u8D25\uFF1A\u5FC5\u987B\u662F\u5BF9\u8C61",
|
|
87
|
+
PARAMETER_ERROR_LACK: "\u53C2\u6570\u7F3A\u5931",
|
|
88
|
+
STRING_CHECK_LOSS: "\u5B57\u7B26\u7F3A\u5C11\u5173\u952E\u5B57"
|
|
89
|
+
};
|
|
90
|
+
var LayerType = {
|
|
91
|
+
SUPER_MAP_IMAGES: "SuperMapImages",
|
|
92
|
+
SUPER_MAP_DATA: "SuperMapData",
|
|
93
|
+
ARC_GIS_MAP_IMAGES: "ArcGisMapImages",
|
|
94
|
+
ARC_GIS_MAP_DATA: "ArcGisMapData",
|
|
95
|
+
OSGB_LAYER: "OSGBLayer",
|
|
96
|
+
S3M_GROUP: "S3MGroup",
|
|
97
|
+
TERRAIN_LAYER: "TerrainFileLayer"
|
|
98
|
+
};
|
|
99
|
+
const GraphicType = {
|
|
100
|
+
POINT: "point",
|
|
101
|
+
POLYLINE: "polyline",
|
|
102
|
+
POLYGON: "polygon",
|
|
103
|
+
BILLBOARD: "billboard",
|
|
104
|
+
CYLINDER: "cylinder",
|
|
105
|
+
ELLIPSOID: "ellipsoid",
|
|
106
|
+
LABEL: "label",
|
|
107
|
+
MODEL: "model",
|
|
108
|
+
WALL: "wall"
|
|
109
|
+
};
|
|
110
|
+
const MeasureMode = {
|
|
111
|
+
DISTANCE: "distance",
|
|
112
|
+
AREA: "area",
|
|
113
|
+
HEIGHT: "height"
|
|
114
|
+
};
|
|
115
|
+
var CommUtils = {
|
|
116
|
+
getDataType(data) {
|
|
117
|
+
return Object.prototype.toString.call(data).slice(8, -1);
|
|
118
|
+
},
|
|
119
|
+
isEmpty(value) {
|
|
120
|
+
if (value == null) {
|
|
121
|
+
return true;
|
|
122
|
+
}
|
|
123
|
+
const type = this.getDataType(value);
|
|
124
|
+
switch (type) {
|
|
125
|
+
case "String":
|
|
126
|
+
return value.trim() === "";
|
|
127
|
+
case "Array":
|
|
128
|
+
return !value.length;
|
|
129
|
+
case "Object":
|
|
130
|
+
return !Object.keys(value).length;
|
|
131
|
+
case "Boolean":
|
|
132
|
+
return !value;
|
|
133
|
+
default:
|
|
134
|
+
return false;
|
|
135
|
+
}
|
|
136
|
+
},
|
|
137
|
+
isNotEmpty(val) {
|
|
138
|
+
return !this.isEmpty(val);
|
|
139
|
+
},
|
|
140
|
+
json2form(json) {
|
|
141
|
+
const formData = new FormData();
|
|
142
|
+
Object.keys(json).forEach((key) => {
|
|
143
|
+
formData.append(key, json[key] instanceof Object ? JSON.stringify(json[key]) : json[key]);
|
|
144
|
+
});
|
|
145
|
+
return formData;
|
|
146
|
+
},
|
|
147
|
+
json2Query(json) {
|
|
148
|
+
var tempArr = [];
|
|
149
|
+
for (var i in json) {
|
|
150
|
+
var key = i;
|
|
151
|
+
var value = json[i];
|
|
152
|
+
tempArr.push(key + "=" + value);
|
|
153
|
+
}
|
|
154
|
+
var urlParamsStr = tempArr.join("&");
|
|
155
|
+
return urlParamsStr;
|
|
156
|
+
},
|
|
157
|
+
generateGuid() {
|
|
158
|
+
const S4 = function() {
|
|
159
|
+
return ((1 + Math.random()) * 65536 | 0).toString(16).substring(1);
|
|
160
|
+
};
|
|
161
|
+
return S4() + S4() + S4() + S4() + S4() + S4() + S4() + S4();
|
|
162
|
+
},
|
|
163
|
+
decodeDict(...args) {
|
|
164
|
+
let res = "";
|
|
165
|
+
if (args.length > 1) {
|
|
166
|
+
const items = args.slice(1, args.length % 2 === 0 ? args.length - 1 : args.length);
|
|
167
|
+
for (let i = 0; i < items.length; i = i + 2) {
|
|
168
|
+
const item = items[i];
|
|
169
|
+
if (args[0] === item) {
|
|
170
|
+
res = items[i + 1];
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
if (!res && args.length % 2 === 0) {
|
|
174
|
+
res = args[args.length - 1];
|
|
175
|
+
}
|
|
176
|
+
} else {
|
|
177
|
+
res = args[0];
|
|
178
|
+
}
|
|
179
|
+
return res;
|
|
180
|
+
},
|
|
181
|
+
extend(dest, ...args) {
|
|
182
|
+
let i, j, len, src;
|
|
183
|
+
for (j = 0, len = args.length; j < len; j++) {
|
|
184
|
+
src = args[j];
|
|
185
|
+
for (i in src) {
|
|
186
|
+
dest[i] = src[i];
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
return dest;
|
|
190
|
+
},
|
|
191
|
+
rgb2hex(rgb) {
|
|
192
|
+
var hex = "#" + ((1 << 24) + (rgb[0] << 16) + (rgb[1] << 8) + rgb[2]).toString(16).slice(1);
|
|
193
|
+
return hex;
|
|
194
|
+
},
|
|
195
|
+
convertToTree2(data, idPropertyName = "id", parentIdPropertyName = "parentId", childrenPropertyName = "children") {
|
|
196
|
+
const result = [];
|
|
197
|
+
function buildChildren(item) {
|
|
198
|
+
const id = item[idPropertyName];
|
|
199
|
+
const children = data.filter((item2) => item2.hasOwnProperty(parentIdPropertyName) && item2[parentIdPropertyName] === id);
|
|
200
|
+
if (children.length > 0) {
|
|
201
|
+
children.forEach(buildChildren);
|
|
202
|
+
item[childrenPropertyName] = children;
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
for (const item of data) {
|
|
206
|
+
if (data.findIndex((t) => t[idPropertyName] === item[parentIdPropertyName]) === -1) {
|
|
207
|
+
buildChildren(item);
|
|
208
|
+
result.push(item);
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
return result;
|
|
212
|
+
},
|
|
213
|
+
asyncLoadScript(url) {
|
|
214
|
+
return new Promise((resolve, reject) => {
|
|
215
|
+
try {
|
|
216
|
+
var oscript = document.createElement("script");
|
|
217
|
+
if (oscript.readyState) {
|
|
218
|
+
oscript.onreadystatechange = function() {
|
|
219
|
+
if (oscript.readyState === "complete" || oscript.readyState === "loaded") {
|
|
220
|
+
resolve(oscript);
|
|
221
|
+
}
|
|
222
|
+
};
|
|
223
|
+
} else {
|
|
224
|
+
oscript.onload = function() {
|
|
225
|
+
resolve(oscript);
|
|
226
|
+
};
|
|
227
|
+
}
|
|
228
|
+
oscript.type = "text/javascript";
|
|
229
|
+
oscript.src = url;
|
|
230
|
+
document.body.appendChild(oscript);
|
|
231
|
+
} catch (error) {
|
|
232
|
+
reject(error);
|
|
233
|
+
}
|
|
234
|
+
});
|
|
235
|
+
},
|
|
236
|
+
loadStyle(urls) {
|
|
237
|
+
urls.forEach((url) => {
|
|
238
|
+
const css = document.createElement("link");
|
|
239
|
+
css.href = url;
|
|
240
|
+
css.rel = "stylesheet";
|
|
241
|
+
css.type = "text/css";
|
|
242
|
+
document.head.appendChild(css);
|
|
243
|
+
});
|
|
244
|
+
},
|
|
245
|
+
template(str, data) {
|
|
246
|
+
const templateRe = /\{ *([\w_-]+) *\}/g;
|
|
247
|
+
return str.replace(templateRe, function(str2, key) {
|
|
248
|
+
var value = data[key];
|
|
249
|
+
if (value === void 0) {
|
|
250
|
+
throw new Error(ErrorType.JSON_VALUE_ERROR + str2);
|
|
251
|
+
} else if (typeof value === "function") {
|
|
252
|
+
value = value(data);
|
|
253
|
+
}
|
|
254
|
+
return value;
|
|
255
|
+
});
|
|
256
|
+
},
|
|
257
|
+
deleteEmptyProperty(data) {
|
|
258
|
+
return Object.fromEntries(
|
|
259
|
+
Object.keys(data).filter((d) => !this.isEmpty(data[d])).map((i) => [i, data[i]])
|
|
260
|
+
);
|
|
261
|
+
},
|
|
262
|
+
deepAssign() {
|
|
263
|
+
let len = arguments.length, target = arguments[0];
|
|
264
|
+
if (this.getDataType(target) !== "Object") {
|
|
265
|
+
target = {};
|
|
266
|
+
}
|
|
267
|
+
for (let i = 1; i < len; i++) {
|
|
268
|
+
let source = arguments[i];
|
|
269
|
+
if (this.getDataType(source) === "Object") {
|
|
270
|
+
for (let s in source) {
|
|
271
|
+
if (s === "__proto__" || target === source[s]) {
|
|
272
|
+
continue;
|
|
273
|
+
}
|
|
274
|
+
if (this.getDataType(source[s]) === "Object") {
|
|
275
|
+
target[s] = this.deepAssign(target[s], source[s]);
|
|
276
|
+
} else {
|
|
277
|
+
target[s] = source[s];
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
return target;
|
|
283
|
+
},
|
|
284
|
+
handleCopyValue(text) {
|
|
285
|
+
if (!navigator.clipboard && window.isSecureContext) {
|
|
286
|
+
return navigator.clipboard.writeText(text);
|
|
287
|
+
} else {
|
|
288
|
+
const textArea = document.createElement("textarea");
|
|
289
|
+
textArea.style.position = "fixed";
|
|
290
|
+
textArea.style.top = textArea.style.left = "-100vh";
|
|
291
|
+
textArea.style.opacity = "0";
|
|
292
|
+
textArea.value = text;
|
|
293
|
+
document.body.appendChild(textArea);
|
|
294
|
+
textArea.focus();
|
|
295
|
+
textArea.select();
|
|
296
|
+
return new Promise((resolve, reject) => {
|
|
297
|
+
document.execCommand("copy") ? resolve() : reject(new Error("copy failed"));
|
|
298
|
+
textArea.remove();
|
|
299
|
+
});
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
};
|
|
303
|
+
Array.prototype.groupBy = function(f) {
|
|
304
|
+
var groups = {};
|
|
305
|
+
this.forEach(function(o) {
|
|
306
|
+
var group = JSON.stringify(f(o));
|
|
307
|
+
groups[group] = groups[group] || [];
|
|
308
|
+
groups[group].push(o);
|
|
309
|
+
});
|
|
310
|
+
return Object.keys(groups).map((group) => groups[group]);
|
|
311
|
+
};
|
|
312
|
+
Array.prototype.distinct = function(f = (d) => d) {
|
|
313
|
+
const arr = [], obj = {};
|
|
314
|
+
this.forEach((item) => {
|
|
315
|
+
const val = f(item);
|
|
316
|
+
!obj[val] && (obj[val] = arr.push(item));
|
|
317
|
+
});
|
|
318
|
+
return arr;
|
|
319
|
+
};
|
|
320
|
+
Array.prototype.max = function() {
|
|
321
|
+
return Math.max.apply({}, this);
|
|
322
|
+
};
|
|
323
|
+
Array.prototype.min = function() {
|
|
324
|
+
return Math.min.apply({}, this);
|
|
325
|
+
};
|
|
326
|
+
Array.prototype.sum = function() {
|
|
327
|
+
return this.length > 0 ? this.reduce((prev = 0, curr = 0) => prev + curr) : 0;
|
|
328
|
+
};
|
|
329
|
+
Array.prototype.avg = function() {
|
|
330
|
+
return this.length ? this.sum() / this.length : 0;
|
|
331
|
+
};
|
|
332
|
+
Array.prototype.desc = function(f = (d) => d) {
|
|
333
|
+
return this.sort((n1, n2) => f(n2) - f(n1));
|
|
334
|
+
};
|
|
335
|
+
Array.prototype.asc = function(f = (d) => d) {
|
|
336
|
+
return this.sort((n1, n2) => f(n1) - f(n2));
|
|
337
|
+
};
|
|
338
|
+
Array.prototype.clear = function() {
|
|
339
|
+
this.length = 0;
|
|
340
|
+
return this;
|
|
341
|
+
};
|
|
342
|
+
var ArrayUtils = {
|
|
343
|
+
asArray(obj) {
|
|
344
|
+
return CommUtils.isEmpty(obj) ? [] : Array.isArray(obj) ? obj : [obj];
|
|
345
|
+
},
|
|
346
|
+
generateArray(length) {
|
|
347
|
+
return [...new Array(length).keys()];
|
|
348
|
+
},
|
|
349
|
+
union(...args) {
|
|
350
|
+
let res = [];
|
|
351
|
+
args.forEach((arg) => {
|
|
352
|
+
if (Array.isArray(arg)) {
|
|
353
|
+
res = res.concat(arg.filter((v) => !res.includes(v)));
|
|
354
|
+
}
|
|
355
|
+
});
|
|
356
|
+
return res;
|
|
357
|
+
},
|
|
358
|
+
intersection(...args) {
|
|
359
|
+
let res = args[0] || [];
|
|
360
|
+
args.forEach((arg) => {
|
|
361
|
+
if (Array.isArray(arg)) {
|
|
362
|
+
res = res.filter((v) => arg.includes(v));
|
|
363
|
+
}
|
|
364
|
+
});
|
|
365
|
+
return res;
|
|
366
|
+
},
|
|
367
|
+
unionAll(...args) {
|
|
368
|
+
return [...args].flat().filter((d) => !!d);
|
|
369
|
+
},
|
|
370
|
+
difference(...args) {
|
|
371
|
+
return this.union(...args).filter((d) => !this.intersection(...args).includes(d));
|
|
372
|
+
}
|
|
373
|
+
};
|
|
374
|
+
var BrowserUtils = {
|
|
375
|
+
getUrlParams(href = window.location.href, needDecode = true) {
|
|
376
|
+
const reg = /([^&=]+)=([\w\W]*?)(&|$|#)/g;
|
|
377
|
+
const { search, hash } = new URL(href);
|
|
378
|
+
const args = [search, hash];
|
|
379
|
+
let obj = {};
|
|
380
|
+
for (let i = 0; i < args.length; i++) {
|
|
381
|
+
const str = args[i];
|
|
382
|
+
if (str) {
|
|
383
|
+
const s = str.replace(/#|\//g, "");
|
|
384
|
+
const arr = s.split("?");
|
|
385
|
+
if (arr.length > 1) {
|
|
386
|
+
for (let i2 = 1; i2 < arr.length; i2++) {
|
|
387
|
+
let res;
|
|
388
|
+
while (res = reg.exec(arr[i2])) {
|
|
389
|
+
obj[res[1]] = needDecode ? decodeURIComponent(res[2]) : res[2];
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
return obj;
|
|
396
|
+
},
|
|
397
|
+
getExplorer() {
|
|
398
|
+
var explorer = window.navigator.userAgent;
|
|
399
|
+
if (explorer.indexOf("MSIE") >= 0) {
|
|
400
|
+
return "IE";
|
|
401
|
+
}
|
|
402
|
+
if (!!window.ActiveXObject || "ActiveXObject" in window) {
|
|
403
|
+
return "IE";
|
|
404
|
+
} else if (explorer.indexOf("Firefox") >= 0) {
|
|
405
|
+
return "Firefox";
|
|
406
|
+
} else if (explorer.indexOf("Chrome") >= 0) {
|
|
407
|
+
return "Chrome";
|
|
408
|
+
} else if (explorer.indexOf("Opera") >= 0) {
|
|
409
|
+
return "Opera";
|
|
410
|
+
} else if (explorer.indexOf("Safari") >= 0) {
|
|
411
|
+
return "Safari";
|
|
412
|
+
}
|
|
413
|
+
},
|
|
414
|
+
detectOS() {
|
|
415
|
+
let os_type = "";
|
|
416
|
+
const windows = navigator.userAgent.indexOf("Windows", 0) != -1 ? 1 : 0;
|
|
417
|
+
const mac = navigator.userAgent.indexOf("mac", 0) != -1 ? 1 : 0;
|
|
418
|
+
const linux = navigator.userAgent.indexOf("Linux", 0) != -1 ? 1 : 0;
|
|
419
|
+
const unix = navigator.userAgent.indexOf("X11", 0) != -1 ? 1 : 0;
|
|
420
|
+
if (windows)
|
|
421
|
+
os_type = "MS Windows";
|
|
422
|
+
else if (mac)
|
|
423
|
+
os_type = "Apple mac";
|
|
424
|
+
else if (linux)
|
|
425
|
+
os_type = "Linux";
|
|
426
|
+
else if (unix)
|
|
427
|
+
os_type = "Unix";
|
|
428
|
+
return os_type;
|
|
429
|
+
},
|
|
430
|
+
switchFullScreen(status) {
|
|
431
|
+
if (status) {
|
|
432
|
+
const element = document.documentElement;
|
|
433
|
+
if (element.requestFullscreen) {
|
|
434
|
+
element.requestFullscreen();
|
|
435
|
+
} else if (element.msRequestFullscreen) {
|
|
436
|
+
element.msRequestFullscreen();
|
|
437
|
+
} else if (element.mozRequestFullScreen) {
|
|
438
|
+
element.mozRequestFullScreen();
|
|
439
|
+
} else if (element.webkitRequestFullscreen) {
|
|
440
|
+
element.webkitRequestFullscreen();
|
|
441
|
+
}
|
|
442
|
+
} else {
|
|
443
|
+
if (document.exitFullscreen) {
|
|
444
|
+
document.exitFullscreen();
|
|
445
|
+
} else if (document.msExitFullscreen) {
|
|
446
|
+
document.msExitFullscreen();
|
|
447
|
+
} else if (document.mozCancelFullScreen) {
|
|
448
|
+
document.mozCancelFullScreen();
|
|
449
|
+
} else if (document.webkitExitFullscreen) {
|
|
450
|
+
document.webkitExitFullscreen();
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
},
|
|
454
|
+
refreshScale() {
|
|
455
|
+
const baseWidth = document.documentElement.clientWidth;
|
|
456
|
+
const baseHeight = document.documentElement.clientHeight;
|
|
457
|
+
const appStyle = document.getElementById("app").style;
|
|
458
|
+
const realRatio = baseWidth / baseHeight;
|
|
459
|
+
const designRatio = 16 / 9;
|
|
460
|
+
let scaleRate = baseWidth / 1920;
|
|
461
|
+
if (realRatio > designRatio) {
|
|
462
|
+
scaleRate = baseHeight / 1080;
|
|
463
|
+
}
|
|
464
|
+
appStyle.transformOrigin = "left top";
|
|
465
|
+
appStyle.transform = `scale(${scaleRate}) translateX(-49.99%)`;
|
|
466
|
+
appStyle.width = `${baseWidth / scaleRate}px`;
|
|
467
|
+
},
|
|
468
|
+
getHtmlFontSize() {
|
|
469
|
+
const htmlwidth = document.documentElement.clientWidth || document.body.clientWidth;
|
|
470
|
+
const htmlDom = document.querySelector("html");
|
|
471
|
+
htmlDom.style.fontSize = htmlwidth / 192 + "px";
|
|
472
|
+
}
|
|
473
|
+
};
|
|
474
|
+
var Cookie = {
|
|
475
|
+
set: function(name, value, Days = 30) {
|
|
476
|
+
var exp = new Date();
|
|
477
|
+
exp.setTime(exp.getTime() + Days * 24 * 60 * 60 * 1e3);
|
|
478
|
+
document.cookie = name + "=" + escape(value) + ";expires=" + exp.toGMTString();
|
|
479
|
+
},
|
|
480
|
+
remove: function(name) {
|
|
481
|
+
var exp = new Date();
|
|
482
|
+
exp.setTime(exp.getTime() - 1);
|
|
483
|
+
var cval = this.get(name);
|
|
484
|
+
if (cval != null) {
|
|
485
|
+
document.cookie = name + "=" + cval + ";expires=" + exp.toGMTString();
|
|
486
|
+
}
|
|
487
|
+
},
|
|
488
|
+
get: function(name) {
|
|
489
|
+
var arr = document.cookie.match(new RegExp("(^| )" + name + "=([^;]*)(;|$)"));
|
|
490
|
+
if (arr != null) {
|
|
491
|
+
return arr[2];
|
|
492
|
+
} else {
|
|
493
|
+
return "";
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
};
|
|
497
|
+
var CoordsUtils = {
|
|
498
|
+
PI: 3.141592653589793,
|
|
499
|
+
XPI: 3.141592653589793 * 3e3 / 180,
|
|
500
|
+
delta(lat, lng) {
|
|
501
|
+
const a = 6378245;
|
|
502
|
+
const ee = 0.006693421622965943;
|
|
503
|
+
let dLat = this.transformLat(lng - 105, lat - 35);
|
|
504
|
+
let dLon = this.transformLon(lng - 105, lat - 35);
|
|
505
|
+
const radLat = lat / 180 * this.PI;
|
|
506
|
+
let magic = Math.sin(radLat);
|
|
507
|
+
magic = 1 - ee * magic * magic;
|
|
508
|
+
const sqrtMagic = Math.sqrt(magic);
|
|
509
|
+
dLat = dLat * 180 / (a * (1 - ee) / (magic * sqrtMagic) * this.PI);
|
|
510
|
+
dLon = dLon * 180 / (a / sqrtMagic * Math.cos(radLat) * this.PI);
|
|
511
|
+
return { lat: dLat, lng: dLon };
|
|
512
|
+
},
|
|
513
|
+
gcjEncrypt(wgsLat, wgsLon) {
|
|
514
|
+
if (this.outOfChina(wgsLat, wgsLon)) {
|
|
515
|
+
return { lat: wgsLat, lng: wgsLon };
|
|
516
|
+
}
|
|
517
|
+
const d = this.delta(wgsLat, wgsLon);
|
|
518
|
+
return { lat: wgsLat + d.lat, lng: wgsLon + d.lng };
|
|
519
|
+
},
|
|
520
|
+
gcjDecrypt(gcjLat, gcjLon) {
|
|
521
|
+
if (this.outOfChina(gcjLat, gcjLon)) {
|
|
522
|
+
return { lat: gcjLat, lng: gcjLon };
|
|
523
|
+
}
|
|
524
|
+
const d = this.delta(gcjLat, gcjLon);
|
|
525
|
+
return { lat: gcjLat - d.lat, lng: gcjLon - d.lng };
|
|
526
|
+
},
|
|
527
|
+
gcjDecryptExact(gcjLat, gcjLon) {
|
|
528
|
+
const initDelta = 0.01;
|
|
529
|
+
const threshold = 1e-9;
|
|
530
|
+
let dLat = initDelta;
|
|
531
|
+
let dLon = initDelta;
|
|
532
|
+
let mLat = gcjLat - dLat;
|
|
533
|
+
let mLon = gcjLon - dLon;
|
|
534
|
+
let pLat = gcjLat + dLat;
|
|
535
|
+
let pLon = gcjLon + dLon;
|
|
536
|
+
let wgsLat;
|
|
537
|
+
let wgsLon;
|
|
538
|
+
let i = 0;
|
|
539
|
+
while (1) {
|
|
540
|
+
wgsLat = (mLat + pLat) / 2;
|
|
541
|
+
wgsLon = (mLon + pLon) / 2;
|
|
542
|
+
const tmp = this.gcj_encrypt(wgsLat, wgsLon);
|
|
543
|
+
dLat = tmp.lat - gcjLat;
|
|
544
|
+
dLon = tmp.lng - gcjLon;
|
|
545
|
+
if (Math.abs(dLat) < threshold && Math.abs(dLon) < threshold) {
|
|
546
|
+
break;
|
|
547
|
+
}
|
|
548
|
+
if (dLat > 0)
|
|
549
|
+
pLat = wgsLat;
|
|
550
|
+
else
|
|
551
|
+
mLat = wgsLat;
|
|
552
|
+
if (dLon > 0)
|
|
553
|
+
pLon = wgsLon;
|
|
554
|
+
else
|
|
555
|
+
mLon = wgsLon;
|
|
556
|
+
if (++i > 1e4)
|
|
557
|
+
break;
|
|
558
|
+
}
|
|
559
|
+
return { lat: wgsLat, lng: wgsLon };
|
|
560
|
+
},
|
|
561
|
+
bdEncrypt(gcjLat, gcjLon) {
|
|
562
|
+
const x = gcjLon;
|
|
563
|
+
const y = gcjLat;
|
|
564
|
+
const z = Math.sqrt(x * x + y * y) + 2e-5 * Math.sin(y * this.XPI);
|
|
565
|
+
const theta = Math.atan2(y, x) + 3e-6 * Math.cos(x * this.XPI);
|
|
566
|
+
const bdLon = z * Math.cos(theta) + 65e-4;
|
|
567
|
+
const bdLat = z * Math.sin(theta) + 6e-3;
|
|
568
|
+
return { lat: bdLat, lng: bdLon };
|
|
569
|
+
},
|
|
570
|
+
bdDecrypt(bdLat, bdLon) {
|
|
571
|
+
const x = bdLon - 65e-4;
|
|
572
|
+
const y = bdLat - 6e-3;
|
|
573
|
+
const z = Math.sqrt(x * x + y * y) - 2e-5 * Math.sin(y * this.XPI);
|
|
574
|
+
const theta = Math.atan2(y, x) - 3e-6 * Math.cos(x * this.XPI);
|
|
575
|
+
const gcjLon = z * Math.cos(theta);
|
|
576
|
+
const gcjLat = z * Math.sin(theta);
|
|
577
|
+
return { lat: gcjLat, lng: gcjLon };
|
|
578
|
+
},
|
|
579
|
+
mercatorEncrypt(wgsLat, wgsLon) {
|
|
580
|
+
const x = wgsLon * 2003750834e-2 / 180;
|
|
581
|
+
let y = Math.log(Math.tan((90 + wgsLat) * this.PI / 360)) / (this.PI / 180);
|
|
582
|
+
y = y * 2003750834e-2 / 180;
|
|
583
|
+
return { lat: y, lng: x };
|
|
584
|
+
},
|
|
585
|
+
mercatorDecrypt(mercatorLat, mercatorLon) {
|
|
586
|
+
const x = mercatorLon / 2003750834e-2 * 180;
|
|
587
|
+
let y = mercatorLat / 2003750834e-2 * 180;
|
|
588
|
+
y = 180 / this.PI * (2 * Math.atan(Math.exp(y * this.PI / 180)) - this.PI / 2);
|
|
589
|
+
return { lat: y, lng: x };
|
|
590
|
+
},
|
|
591
|
+
distance(latA, lngA, latB, lngB) {
|
|
592
|
+
const earthR = 6371e3;
|
|
593
|
+
const x = Math.cos(latA * this.PI / 180) * Math.cos(latB * this.PI / 180) * Math.cos((lngA - lngB) * this.PI / 180);
|
|
594
|
+
const y = Math.sin(latA * this.PI / 180) * Math.sin(latB * this.PI / 180);
|
|
595
|
+
let s = x + y;
|
|
596
|
+
if (s > 1)
|
|
597
|
+
s = 1;
|
|
598
|
+
if (s < -1)
|
|
599
|
+
s = -1;
|
|
600
|
+
const alpha = Math.acos(s);
|
|
601
|
+
const distance = alpha * earthR;
|
|
602
|
+
return distance;
|
|
603
|
+
},
|
|
604
|
+
outOfChina(lat, lng) {
|
|
605
|
+
if (lng < 72.004 || lng > 137.8347) {
|
|
606
|
+
return true;
|
|
607
|
+
}
|
|
608
|
+
if (lat < 0.8293 || lat > 55.8271) {
|
|
609
|
+
return true;
|
|
610
|
+
}
|
|
611
|
+
return false;
|
|
612
|
+
},
|
|
613
|
+
transformLat(x, y) {
|
|
614
|
+
let ret = -100 + 2 * x + 3 * y + 0.2 * y * y + 0.1 * x * y + 0.2 * Math.sqrt(Math.abs(x));
|
|
615
|
+
ret += (20 * Math.sin(6 * x * this.PI) + 20 * Math.sin(2 * x * this.PI)) * 2 / 3;
|
|
616
|
+
ret += (20 * Math.sin(y * this.PI) + 40 * Math.sin(y / 3 * this.PI)) * 2 / 3;
|
|
617
|
+
ret += (160 * Math.sin(y / 12 * this.PI) + 320 * Math.sin(y * this.PI / 30)) * 2 / 3;
|
|
618
|
+
return ret;
|
|
619
|
+
},
|
|
620
|
+
transformLon(x, y) {
|
|
621
|
+
let ret = 300 + x + 2 * y + 0.1 * x * x + 0.1 * x * y + 0.1 * Math.sqrt(Math.abs(x));
|
|
622
|
+
ret += (20 * Math.sin(6 * x * this.PI) + 20 * Math.sin(2 * x * this.PI)) * 2 / 3;
|
|
623
|
+
ret += (20 * Math.sin(x * this.PI) + 40 * Math.sin(x / 3 * this.PI)) * 2 / 3;
|
|
624
|
+
ret += (150 * Math.sin(x / 12 * this.PI) + 300 * Math.sin(x / 30 * this.PI)) * 2 / 3;
|
|
625
|
+
return ret;
|
|
626
|
+
},
|
|
627
|
+
randomCoordinate(minX, minY, maxX, maxY) {
|
|
628
|
+
return {
|
|
629
|
+
lat: Math.random() * (maxY - minY) + minY,
|
|
630
|
+
lng: Math.random() * (maxX - minX) + minX
|
|
631
|
+
};
|
|
632
|
+
}
|
|
633
|
+
};
|
|
634
|
+
Date.prototype.format = function(fmt) {
|
|
635
|
+
const o = {
|
|
636
|
+
"M+": this.getMonth() + 1,
|
|
637
|
+
"d+": this.getDate(),
|
|
638
|
+
"h+": this.getHours(),
|
|
639
|
+
"m+": this.getMinutes(),
|
|
640
|
+
"s+": this.getSeconds(),
|
|
641
|
+
"q+": Math.floor((this.getMonth() + 3) / 3),
|
|
642
|
+
S: this.getMilliseconds()
|
|
643
|
+
};
|
|
644
|
+
if (/(y+)/.test(fmt))
|
|
645
|
+
fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
|
|
646
|
+
for (const k in o) {
|
|
647
|
+
if (new RegExp("(" + k + ")").test(fmt))
|
|
648
|
+
fmt = fmt.replace(RegExp.$1, RegExp.$1.length === 1 ? o[k] : ("00" + o[k]).substr(("" + o[k]).length));
|
|
649
|
+
}
|
|
650
|
+
return fmt;
|
|
651
|
+
};
|
|
652
|
+
Date.prototype.addDate = function(interval, number) {
|
|
653
|
+
const date = new Date(this);
|
|
654
|
+
switch (interval) {
|
|
655
|
+
case "y":
|
|
656
|
+
date.setFullYear(this.getFullYear() + number);
|
|
657
|
+
break;
|
|
658
|
+
case "q":
|
|
659
|
+
date.setMonth(this.getMonth() + number * 3);
|
|
660
|
+
break;
|
|
661
|
+
case "M":
|
|
662
|
+
date.setMonth(this.getMonth() + number);
|
|
663
|
+
break;
|
|
664
|
+
case "w":
|
|
665
|
+
date.setDate(this.getDate() + number * 7);
|
|
666
|
+
break;
|
|
667
|
+
case "d":
|
|
668
|
+
date.setDate(this.getDate() + number);
|
|
669
|
+
break;
|
|
670
|
+
case "h":
|
|
671
|
+
date.setHours(this.getHours() + number);
|
|
672
|
+
break;
|
|
673
|
+
case "m":
|
|
674
|
+
date.setMinutes(this.getMinutes() + number);
|
|
675
|
+
break;
|
|
676
|
+
case "s":
|
|
677
|
+
date.setSeconds(this.getSeconds() + number);
|
|
678
|
+
break;
|
|
679
|
+
default:
|
|
680
|
+
date.setDate(this.getDate() + number);
|
|
681
|
+
break;
|
|
682
|
+
}
|
|
683
|
+
return date;
|
|
684
|
+
};
|
|
685
|
+
var DateUtils = {
|
|
686
|
+
lastMonthDate: new Date(new Date().getFullYear(), new Date().getMonth() - 1, 1),
|
|
687
|
+
thisMonthDate: new Date(new Date().getFullYear(), new Date().getMonth(), 1),
|
|
688
|
+
nextMonthDate: new Date(new Date().getFullYear(), new Date().getMonth() + 1, 1),
|
|
689
|
+
lastWeekDate: new Date(new Date().getFullYear(), new Date().getMonth(), new Date().getDate() + 1 - 7 - new Date().getDay()),
|
|
690
|
+
thisWeekDate: new Date(new Date().getFullYear(), new Date().getMonth(), new Date().getDate() + 1 - new Date().getDay()),
|
|
691
|
+
nextWeekDate: new Date(new Date().getFullYear(), new Date().getMonth(), new Date().getDate() + 1 + 7 - new Date().getDay()),
|
|
692
|
+
lastDayDate: new Date(new Date().getFullYear(), new Date().getMonth(), new Date().getDate() - 1),
|
|
693
|
+
thisDayDate: new Date(new Date().setHours(0, 0, 0, 0)),
|
|
694
|
+
nextDayDate: new Date(new Date().getFullYear(), new Date().getMonth(), new Date().getDate() + 1),
|
|
695
|
+
parseDate(str) {
|
|
696
|
+
if (typeof str == "string") {
|
|
697
|
+
var results = str.match(/^ *(\d{4})-(\d{1,2})-(\d{1,2}) *$/);
|
|
698
|
+
if (results && results.length > 3)
|
|
699
|
+
return new Date(parseInt(results[1]), parseInt(results[2]) - 1, parseInt(results[3]));
|
|
700
|
+
results = str.match(/^ *(\d{4})-(\d{1,2})-(\d{1,2}) +(\d{1,2}):(\d{1,2}):(\d{1,2}) *$/);
|
|
701
|
+
if (results && results.length > 6)
|
|
702
|
+
return new Date(
|
|
703
|
+
parseInt(results[1]),
|
|
704
|
+
parseInt(results[2]) - 1,
|
|
705
|
+
parseInt(results[3]),
|
|
706
|
+
parseInt(results[4]),
|
|
707
|
+
parseInt(results[5]),
|
|
708
|
+
parseInt(results[6])
|
|
709
|
+
);
|
|
710
|
+
results = str.match(/^ *(\d{4})-(\d{1,2})-(\d{1,2}) +(\d{1,2}):(\d{1,2}):(\d{1,2})\.(\d{1,9}) *$/);
|
|
711
|
+
if (results && results.length > 7)
|
|
712
|
+
return new Date(
|
|
713
|
+
parseInt(results[1]),
|
|
714
|
+
parseInt(results[2]) - 1,
|
|
715
|
+
parseInt(results[3]),
|
|
716
|
+
parseInt(results[4]),
|
|
717
|
+
parseInt(results[5]),
|
|
718
|
+
parseInt(results[6]),
|
|
719
|
+
parseInt(results[7])
|
|
720
|
+
);
|
|
721
|
+
}
|
|
722
|
+
return null;
|
|
723
|
+
},
|
|
724
|
+
formatDateInterval(startTime, endTime) {
|
|
725
|
+
const dateCreateTime = new Date(startTime);
|
|
726
|
+
const dateFinishTime = new Date(endTime);
|
|
727
|
+
const dateInterval = dateFinishTime.getTime() - dateCreateTime.getTime();
|
|
728
|
+
const days = Math.floor(dateInterval / (24 * 3600 * 1e3));
|
|
729
|
+
const leave1 = dateInterval % (24 * 3600 * 1e3);
|
|
730
|
+
const hours = Math.floor(leave1 / (3600 * 1e3));
|
|
731
|
+
const leave2 = leave1 % (3600 * 1e3);
|
|
732
|
+
const minutes = Math.floor(leave2 / (60 * 1e3));
|
|
733
|
+
const leave3 = leave2 % (60 * 1e3);
|
|
734
|
+
const seconds = Math.round(leave3 / 1e3);
|
|
735
|
+
let intervalDes = "";
|
|
736
|
+
if (days > 0) {
|
|
737
|
+
intervalDes += days + "\u5929";
|
|
738
|
+
}
|
|
739
|
+
if (hours > 0) {
|
|
740
|
+
intervalDes += hours + "\u65F6";
|
|
741
|
+
}
|
|
742
|
+
if (minutes > 0) {
|
|
743
|
+
intervalDes += minutes + "\u5206";
|
|
744
|
+
}
|
|
745
|
+
if (seconds > 0) {
|
|
746
|
+
intervalDes += seconds + "\u79D2";
|
|
747
|
+
}
|
|
748
|
+
if (days === 0 && hours === 0 && minutes === 0 && seconds === 0) {
|
|
749
|
+
intervalDes = "\u5C11\u4E8E1\u79D2";
|
|
750
|
+
}
|
|
751
|
+
return intervalDes;
|
|
752
|
+
},
|
|
753
|
+
formatterCounter(times) {
|
|
754
|
+
const checked = function(j) {
|
|
755
|
+
return (j > 10 ? "" : "0") + (j || 0);
|
|
756
|
+
};
|
|
757
|
+
const houres = checked(Math.floor(times / 3600));
|
|
758
|
+
const level1 = times % 3600;
|
|
759
|
+
const minutes = checked(Math.floor(level1 / 60));
|
|
760
|
+
const leave2 = level1 % 60;
|
|
761
|
+
const seconds = checked(Math.round(leave2));
|
|
762
|
+
return `${houres}:${minutes}:${seconds}`;
|
|
763
|
+
},
|
|
764
|
+
sleep(d) {
|
|
765
|
+
}
|
|
766
|
+
};
|
|
767
|
+
function trim(str) {
|
|
768
|
+
return str.trim ? str.trim() : str.replace(/^\s+|\s+$/g, "");
|
|
769
|
+
}
|
|
770
|
+
function splitWords(str) {
|
|
771
|
+
return trim(str).split(/\s+/);
|
|
772
|
+
}
|
|
773
|
+
var DomUtils = {
|
|
774
|
+
getStyle(el, style) {
|
|
775
|
+
let value = el.style[style] || el.currentStyle && el.currentStyle[style];
|
|
776
|
+
if ((!value || value === "auto") && document.defaultView) {
|
|
777
|
+
const css = document.defaultView.getComputedStyle(el, null);
|
|
778
|
+
value = css ? css[style] : null;
|
|
779
|
+
}
|
|
780
|
+
return value === "auto" ? null : value;
|
|
781
|
+
},
|
|
782
|
+
create(tagName, className, container) {
|
|
783
|
+
const el = document.createElement(tagName);
|
|
784
|
+
el.className = className || "";
|
|
785
|
+
if (container) {
|
|
786
|
+
container.appendChild(el);
|
|
787
|
+
}
|
|
788
|
+
return el;
|
|
789
|
+
},
|
|
790
|
+
remove(el) {
|
|
791
|
+
const parent = el.parentNode;
|
|
792
|
+
if (parent) {
|
|
793
|
+
parent.removeChild(el);
|
|
794
|
+
}
|
|
795
|
+
},
|
|
796
|
+
empty(el) {
|
|
797
|
+
while (el.firstChild) {
|
|
798
|
+
el.removeChild(el.firstChild);
|
|
799
|
+
}
|
|
800
|
+
},
|
|
801
|
+
toFront(el) {
|
|
802
|
+
const parent = el.parentNode;
|
|
803
|
+
if (parent && parent.lastChild !== el) {
|
|
804
|
+
parent.appendChild(el);
|
|
805
|
+
}
|
|
806
|
+
},
|
|
807
|
+
toBack(el) {
|
|
808
|
+
const parent = el.parentNode;
|
|
809
|
+
if (parent && parent.firstChild !== el) {
|
|
810
|
+
parent.insertBefore(el, parent.firstChild);
|
|
811
|
+
}
|
|
812
|
+
},
|
|
813
|
+
getClass(el) {
|
|
814
|
+
if (el.correspondingElement) {
|
|
815
|
+
el = el.correspondingElement;
|
|
816
|
+
}
|
|
817
|
+
return el.className.baseVal === void 0 ? el.className : el.className.baseVal;
|
|
818
|
+
},
|
|
819
|
+
hasClass(el, name) {
|
|
820
|
+
if (el.classList !== void 0) {
|
|
821
|
+
return el.classList.contains(name);
|
|
822
|
+
}
|
|
823
|
+
const className = this.getClass(el);
|
|
824
|
+
return className.length > 0 && new RegExp("(^|\\s)" + name + "(\\s|$)").test(className);
|
|
825
|
+
},
|
|
826
|
+
addClass(el, name) {
|
|
827
|
+
if (el.classList !== void 0) {
|
|
828
|
+
const classes = splitWords(name);
|
|
829
|
+
for (let i = 0, len = classes.length; i < len; i++) {
|
|
830
|
+
el.classList.add(classes[i]);
|
|
831
|
+
}
|
|
832
|
+
} else if (!this.hasClass(el, name)) {
|
|
833
|
+
const className = this.getClass(el);
|
|
834
|
+
this.setClass(el, (className ? className + " " : "") + name);
|
|
835
|
+
}
|
|
836
|
+
},
|
|
837
|
+
removeClass(el, name) {
|
|
838
|
+
if (el.classList !== void 0) {
|
|
839
|
+
const classes = splitWords(name);
|
|
840
|
+
classes.forEach((name2) => el.classList.remove(name2));
|
|
841
|
+
} else {
|
|
842
|
+
this.setClass(el, trim((" " + this.getClass(el) + " ").replace(" " + name + " ", " ")));
|
|
843
|
+
}
|
|
844
|
+
},
|
|
845
|
+
setClass(el, name) {
|
|
846
|
+
if (el.className.baseVal === void 0) {
|
|
847
|
+
el.className = name;
|
|
848
|
+
} else {
|
|
849
|
+
el.className.baseVal = name;
|
|
850
|
+
}
|
|
851
|
+
},
|
|
852
|
+
parseFromString(str) {
|
|
853
|
+
const parser = new DOMParser();
|
|
854
|
+
const doc = parser.parseFromString(str, "text/xml");
|
|
855
|
+
return doc.children[0];
|
|
856
|
+
}
|
|
857
|
+
};
|
|
858
|
+
var MathUtils = {
|
|
859
|
+
DEG2RAD: Math.PI / 180,
|
|
860
|
+
RAD2DEG: 180 / Math.PI,
|
|
861
|
+
randInt(low, high) {
|
|
862
|
+
return low + Math.floor(Math.random() * (high - low + 1));
|
|
863
|
+
},
|
|
864
|
+
randFloat(low, high) {
|
|
865
|
+
return low + Math.random() * (high - low);
|
|
866
|
+
},
|
|
867
|
+
degreesToRadians(degrees) {
|
|
868
|
+
return degrees * this.DEG2RAD;
|
|
869
|
+
},
|
|
870
|
+
toRadians(degrees) {
|
|
871
|
+
return degrees * this.DEG2RAD;
|
|
872
|
+
},
|
|
873
|
+
radiansToDegrees(radians) {
|
|
874
|
+
return radians * this.RAD2DEG;
|
|
875
|
+
},
|
|
876
|
+
toDegrees(radians) {
|
|
877
|
+
return radians * this.RAD2DEG;
|
|
878
|
+
},
|
|
879
|
+
formatFloat(value, n = 2) {
|
|
880
|
+
return Math.round(value * Math.pow(10, n)) / Math.pow(10, n);
|
|
881
|
+
}
|
|
882
|
+
};
|
|
883
|
+
var GeoUtils = {
|
|
884
|
+
toRadian: Math.PI / 180,
|
|
885
|
+
R: 6371393,
|
|
886
|
+
isLnglat(lng, lat) {
|
|
887
|
+
return lng && lat && !!(+lat > -90 && +lat < 90 && +lng > -180 && +lng < 180);
|
|
888
|
+
},
|
|
889
|
+
formatLnglat(lng, lat) {
|
|
890
|
+
let res = "";
|
|
891
|
+
function format(value) {
|
|
892
|
+
const a = parseFloat(value);
|
|
893
|
+
const degree = parseInt(a);
|
|
894
|
+
let min = parseInt((a - degree) * 60);
|
|
895
|
+
let sec = (a - degree) * 3600 - min * 60;
|
|
896
|
+
return degree + "\xB0" + min + "\u2032" + sec.toFixed(2) + "\u2033";
|
|
897
|
+
}
|
|
898
|
+
if (lng && lat) {
|
|
899
|
+
res = format(lng) + "," + format(lat);
|
|
900
|
+
}
|
|
901
|
+
return res;
|
|
902
|
+
},
|
|
903
|
+
transformLnglat(lng, lat) {
|
|
904
|
+
function dms2deg(s) {
|
|
905
|
+
var sw = /[sw]/i.test(s);
|
|
906
|
+
var f = sw ? -1 : 1;
|
|
907
|
+
var bits = s.match(/[\d.]+/g);
|
|
908
|
+
var result = 0;
|
|
909
|
+
for (var i = 0, iLen = bits.length; i < iLen; i++) {
|
|
910
|
+
result += bits[i] / f;
|
|
911
|
+
f *= 60;
|
|
912
|
+
}
|
|
913
|
+
return result;
|
|
914
|
+
}
|
|
915
|
+
if (lng && lat) {
|
|
916
|
+
return {
|
|
917
|
+
lng: dms2deg(lng),
|
|
918
|
+
lat: dms2deg(lat)
|
|
919
|
+
};
|
|
920
|
+
}
|
|
921
|
+
},
|
|
922
|
+
rayCasting(p, poly) {
|
|
923
|
+
var px = p.x, py = p.y, flag = false;
|
|
924
|
+
for (var i = 0, l = poly.length, j = l - 1; i < l; j = i, i++) {
|
|
925
|
+
var sx = poly[i].x, sy = poly[i].y, tx = poly[j].x, ty = poly[j].y;
|
|
926
|
+
if (sx === px && sy === py || tx === px && ty === py) {
|
|
927
|
+
return "on";
|
|
928
|
+
}
|
|
929
|
+
if (sy < py && ty >= py || sy >= py && ty < py) {
|
|
930
|
+
var x = sx + (py - sy) * (tx - sx) / (ty - sy);
|
|
931
|
+
if (x === px) {
|
|
932
|
+
return "on";
|
|
933
|
+
}
|
|
934
|
+
if (x > px) {
|
|
935
|
+
flag = !flag;
|
|
936
|
+
}
|
|
937
|
+
}
|
|
938
|
+
}
|
|
939
|
+
return flag ? "in" : "out";
|
|
940
|
+
},
|
|
941
|
+
wgs84PointsDistance(fromPoint, toPoint) {
|
|
942
|
+
var PI = Math.PI;
|
|
943
|
+
function getRad(d) {
|
|
944
|
+
return d * PI / 180;
|
|
945
|
+
}
|
|
946
|
+
if (arguments.length != 2) {
|
|
947
|
+
return 0;
|
|
948
|
+
}
|
|
949
|
+
lon1 = fromPoint.x;
|
|
950
|
+
lat1 = fromPoint.y;
|
|
951
|
+
lon2 = toPoint.x;
|
|
952
|
+
lat2 = toPoint.y;
|
|
953
|
+
var a = 6378137, b = 63567523142e-4, f = 1 / 298.257223563;
|
|
954
|
+
var L = getRad(lon2 - lon1);
|
|
955
|
+
var U1 = Math.atan((1 - f) * Math.tan(getRad(lat1)));
|
|
956
|
+
var U2 = Math.atan((1 - f) * Math.tan(getRad(lat2)));
|
|
957
|
+
var sinU1 = Math.sin(U1), cosU1 = Math.cos(U1);
|
|
958
|
+
var sinU2 = Math.sin(U2), cosU2 = Math.cos(U2);
|
|
959
|
+
var lambda = L, lambdaP, iterLimit = 100;
|
|
960
|
+
do {
|
|
961
|
+
var sinLambda = Math.sin(lambda), cosLambda = Math.cos(lambda);
|
|
962
|
+
var sinSigma = Math.sqrt(
|
|
963
|
+
cosU2 * sinLambda * (cosU2 * sinLambda) + (cosU1 * sinU2 - sinU1 * cosU2 * cosLambda) * (cosU1 * sinU2 - sinU1 * cosU2 * cosLambda)
|
|
964
|
+
);
|
|
965
|
+
if (sinSigma == 0)
|
|
966
|
+
return 0;
|
|
967
|
+
var cosSigma = sinU1 * sinU2 + cosU1 * cosU2 * cosLambda;
|
|
968
|
+
var sigma = Math.atan2(sinSigma, cosSigma);
|
|
969
|
+
var sinAlpha = cosU1 * cosU2 * sinLambda / sinSigma;
|
|
970
|
+
var cosSqAlpha = 1 - sinAlpha * sinAlpha;
|
|
971
|
+
var cos2SigmaM = cosSigma - 2 * sinU1 * sinU2 / cosSqAlpha;
|
|
972
|
+
if (isNaN(cos2SigmaM))
|
|
973
|
+
cos2SigmaM = 0;
|
|
974
|
+
var C = f / 16 * cosSqAlpha * (4 + f * (4 - 3 * cosSqAlpha));
|
|
975
|
+
lambdaP = lambda;
|
|
976
|
+
lambda = L + (1 - C) * f * sinAlpha * (sigma + C * sinSigma * (cos2SigmaM + C * cosSigma * (-1 + 2 * cos2SigmaM * cos2SigmaM)));
|
|
977
|
+
} while (Math.abs(lambda - lambdaP) > 1e-12 && --iterLimit > 0);
|
|
978
|
+
if (iterLimit == 0) {
|
|
979
|
+
return NaN;
|
|
980
|
+
}
|
|
981
|
+
var uSq = cosSqAlpha * (a * a - b * b) / (b * b);
|
|
982
|
+
var A = 1 + uSq / 16384 * (4096 + uSq * (-768 + uSq * (320 - 175 * uSq)));
|
|
983
|
+
var B = uSq / 1024 * (256 + uSq * (-128 + uSq * (74 - 47 * uSq)));
|
|
984
|
+
var deltaSigma = B * sinSigma * (cos2SigmaM + B / 4 * (cosSigma * (-1 + 2 * cos2SigmaM * cos2SigmaM) - B / 6 * cos2SigmaM * (-3 + 4 * sinSigma * sinSigma) * (-3 + 4 * cos2SigmaM * cos2SigmaM)));
|
|
985
|
+
var s = b * A * (sigma - deltaSigma);
|
|
986
|
+
return s;
|
|
987
|
+
},
|
|
988
|
+
rotatePoint(p1, p2, \u03B8) {
|
|
989
|
+
const x = (p1.x - p2.x) * Math.cos(Math.PI / 180 * -\u03B8) - (p1.y - p2.y) * Math.sin(Math.PI / 180 * -\u03B8) + p2.x;
|
|
990
|
+
const y = (p1.x - p2.x) * Math.sin(Math.PI / 180 * -\u03B8) + (p1.y - p2.y) * Math.cos(Math.PI / 180 * -\u03B8) + p2.y;
|
|
991
|
+
return { x, y };
|
|
992
|
+
},
|
|
993
|
+
calcBearAndDis(p1, p2) {
|
|
994
|
+
const { x: x1, y: y1 } = p1;
|
|
995
|
+
const { x: x2, y: y2 } = p2;
|
|
996
|
+
const dx = x2 - x1;
|
|
997
|
+
const dy = y2 - y1;
|
|
998
|
+
const distance = Math.sqrt(dx * dx + dy * dy);
|
|
999
|
+
const angleInRadians = Math.atan2(dy, dx);
|
|
1000
|
+
const angle = (angleInRadians * (180 / Math.PI) + 360 + 90) % 360;
|
|
1001
|
+
return { angle, distance };
|
|
1002
|
+
},
|
|
1003
|
+
calcBearAndDisByPoints(latlng1, latlng2) {
|
|
1004
|
+
var f1 = parseFloat(latlng1.lat), l1 = parseFloat(latlng1.lng), f2 = parseFloat(latlng2.lat), l2 = parseFloat(latlng2.lng);
|
|
1005
|
+
var y = Math.sin((l2 - l1) * this.toRadian) * Math.cos(f2 * this.toRadian);
|
|
1006
|
+
var x = Math.cos(f1 * this.toRadian) * Math.sin(f2 * this.toRadian) - Math.sin(f1 * this.toRadian) * Math.cos(f2 * this.toRadian) * Math.cos((l2 - l1) * this.toRadian);
|
|
1007
|
+
var angle = Math.atan2(y, x) * (180 / Math.PI);
|
|
1008
|
+
var deltaF = (f2 - f1) * this.toRadian;
|
|
1009
|
+
var deltaL = (l2 - l1) * this.toRadian;
|
|
1010
|
+
var a = Math.sin(deltaF / 2) * Math.sin(deltaF / 2) + Math.cos(f1 * this.toRadian) * Math.cos(f2 * this.toRadian) * Math.sin(deltaL / 2) * Math.sin(deltaL / 2);
|
|
1011
|
+
var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
|
|
1012
|
+
var distance = this.R * c;
|
|
1013
|
+
return {
|
|
1014
|
+
angle,
|
|
1015
|
+
distance
|
|
1016
|
+
};
|
|
1017
|
+
},
|
|
1018
|
+
calcPointByBearAndDis(latlng, angle, distance) {
|
|
1019
|
+
const sLat = MathUtils.toRadians(parseFloat(latlng.lat));
|
|
1020
|
+
const sLng = MathUtils.toRadians(parseFloat(latlng.lng));
|
|
1021
|
+
angle = parseFloat(angle);
|
|
1022
|
+
distance = parseFloat(distance);
|
|
1023
|
+
const d = distance / this.R;
|
|
1024
|
+
angle = MathUtils.toRadians(angle);
|
|
1025
|
+
const lat = Math.asin(Math.sin(sLat) * Math.cos(d) + Math.cos(sLat) * Math.sin(d) * Math.cos(angle));
|
|
1026
|
+
const lon = sLng + Math.atan2(Math.sin(angle) * Math.sin(d) * Math.cos(sLat), Math.cos(d) - Math.sin(sLat) * Math.sin(lat));
|
|
1027
|
+
return {
|
|
1028
|
+
lat: MathUtils.toDegrees(lat),
|
|
1029
|
+
lng: MathUtils.toDegrees(lon)
|
|
1030
|
+
};
|
|
1031
|
+
},
|
|
1032
|
+
mercatorTolonlat(x, y) {
|
|
1033
|
+
const lng = x / 2003750834e-2 * 180;
|
|
1034
|
+
var mmy = y / 2003750834e-2 * 180;
|
|
1035
|
+
const lat = 180 / Math.PI * (2 * Math.atan(Math.exp(mmy * Math.PI / 180)) - Math.PI / 2);
|
|
1036
|
+
return { lng, lat };
|
|
1037
|
+
},
|
|
1038
|
+
lonlatToMercator(lng, lat) {
|
|
1039
|
+
var earthRad = 6378137;
|
|
1040
|
+
const x = lng * Math.PI / 180 * earthRad;
|
|
1041
|
+
var a = lat * Math.PI / 180;
|
|
1042
|
+
const y = earthRad / 2 * Math.log((1 + Math.sin(a)) / (1 - Math.sin(a)));
|
|
1043
|
+
return { x, y };
|
|
1044
|
+
}
|
|
1045
|
+
};
|
|
1046
|
+
var FileUtils = {
|
|
1047
|
+
convertBase64ToBlob(data) {
|
|
1048
|
+
var mimeString = data.split(",")[0].split(":")[1].split(";")[0];
|
|
1049
|
+
var byteString = window.atob(data.split(",")[1]);
|
|
1050
|
+
var ab = new ArrayBuffer(byteString.length);
|
|
1051
|
+
var ia = new Uint8Array(ab);
|
|
1052
|
+
for (var i = 0; i < byteString.length; i++) {
|
|
1053
|
+
ia[i] = byteString.charCodeAt(i);
|
|
1054
|
+
}
|
|
1055
|
+
var bb = window.BlobBuilder || window.WebKitBlobBuilder || window.MozBlobBuilder;
|
|
1056
|
+
if (bb) {
|
|
1057
|
+
bb = new (window.BlobBuilder || window.WebKitBlobBuilder || window.MozBlobBuilder)();
|
|
1058
|
+
bb.append(ab);
|
|
1059
|
+
return bb.getBlob(mimeString);
|
|
1060
|
+
} else {
|
|
1061
|
+
bb = new Blob([ab], {
|
|
1062
|
+
type: mimeString
|
|
1063
|
+
});
|
|
1064
|
+
return bb;
|
|
1065
|
+
}
|
|
1066
|
+
},
|
|
1067
|
+
convertUrlToBase64(url, width, height) {
|
|
1068
|
+
return new Promise(function(resolve, reject) {
|
|
1069
|
+
var img = new Image();
|
|
1070
|
+
img.crossOrigin = "Anonymous";
|
|
1071
|
+
img.src = url;
|
|
1072
|
+
img.onload = function() {
|
|
1073
|
+
var canvas = document.createElement("canvas");
|
|
1074
|
+
canvas.width = width || img.width;
|
|
1075
|
+
canvas.height = height || img.height;
|
|
1076
|
+
var ctx = canvas.getContext("2d");
|
|
1077
|
+
ctx.drawImage(img, 0, 0, img.width, img.height);
|
|
1078
|
+
var ext = img.src.substring(img.src.lastIndexOf(".") + 1).toLowerCase();
|
|
1079
|
+
var dataURL = canvas.toDataURL("image/" + ext);
|
|
1080
|
+
var base64 = {
|
|
1081
|
+
dataURL,
|
|
1082
|
+
type: "image/" + ext,
|
|
1083
|
+
ext
|
|
1084
|
+
};
|
|
1085
|
+
resolve(base64);
|
|
1086
|
+
};
|
|
1087
|
+
});
|
|
1088
|
+
},
|
|
1089
|
+
convertBase64ToFile(dataurl, filename) {
|
|
1090
|
+
var arr = dataurl.split(","), mime = arr[0].match(/:(.*?);/)[1], bstr = atob(arr[1]), n = bstr.length, u8arr = new Uint8Array(n);
|
|
1091
|
+
while (n--) {
|
|
1092
|
+
u8arr[n] = bstr.charCodeAt(n);
|
|
1093
|
+
}
|
|
1094
|
+
let file = new File([u8arr], filename, { type: mime });
|
|
1095
|
+
return file;
|
|
1096
|
+
},
|
|
1097
|
+
downloadFromFile(data, saveName) {
|
|
1098
|
+
if (typeof data == "object") {
|
|
1099
|
+
if (data instanceof Blob) {
|
|
1100
|
+
data = URL.createObjectURL(data);
|
|
1101
|
+
} else {
|
|
1102
|
+
const str = JSON.stringify(data);
|
|
1103
|
+
const blob = new Blob([str], { type: "text/json" });
|
|
1104
|
+
data = window.URL.createObjectURL(blob);
|
|
1105
|
+
}
|
|
1106
|
+
} else if (typeof data == "string" && data.indexOf("http") === -1) {
|
|
1107
|
+
const blob = new Blob([data], { type: "text/json" });
|
|
1108
|
+
data = window.URL.createObjectURL(blob);
|
|
1109
|
+
}
|
|
1110
|
+
var link = document.createElement("a");
|
|
1111
|
+
link.href = data;
|
|
1112
|
+
link.download = saveName || "";
|
|
1113
|
+
link.click();
|
|
1114
|
+
window.URL.revokeObjectURL(link.href);
|
|
1115
|
+
}
|
|
1116
|
+
};
|
|
1117
|
+
var OptimizeUtils = {
|
|
1118
|
+
debounce(func, wait, immediate = true) {
|
|
1119
|
+
let timeout, args, context, timestamp, result;
|
|
1120
|
+
const later = function() {
|
|
1121
|
+
const last = +new Date() - timestamp;
|
|
1122
|
+
if (last < wait && last > 0) {
|
|
1123
|
+
timeout = setTimeout(later, wait - last);
|
|
1124
|
+
} else {
|
|
1125
|
+
timeout = null;
|
|
1126
|
+
if (!immediate) {
|
|
1127
|
+
result = func.apply(context, args);
|
|
1128
|
+
if (!timeout)
|
|
1129
|
+
context = args = null;
|
|
1130
|
+
}
|
|
1131
|
+
}
|
|
1132
|
+
};
|
|
1133
|
+
return function(...args2) {
|
|
1134
|
+
context = this;
|
|
1135
|
+
timestamp = +new Date();
|
|
1136
|
+
const callNow = immediate && !timeout;
|
|
1137
|
+
if (!timeout)
|
|
1138
|
+
timeout = setTimeout(later, wait);
|
|
1139
|
+
if (callNow) {
|
|
1140
|
+
result = func.apply(context, args2);
|
|
1141
|
+
context = args2 = null;
|
|
1142
|
+
}
|
|
1143
|
+
return result;
|
|
1144
|
+
};
|
|
1145
|
+
},
|
|
1146
|
+
throttle(func, wait, type) {
|
|
1147
|
+
if (type === 1) {
|
|
1148
|
+
var previous = 0;
|
|
1149
|
+
} else if (type === 2) {
|
|
1150
|
+
var timeout;
|
|
1151
|
+
}
|
|
1152
|
+
return function() {
|
|
1153
|
+
let context = this;
|
|
1154
|
+
let args = arguments;
|
|
1155
|
+
if (type === 1) {
|
|
1156
|
+
let now = Date.now();
|
|
1157
|
+
if (now - previous > wait) {
|
|
1158
|
+
func.apply(context, args);
|
|
1159
|
+
previous = now;
|
|
1160
|
+
}
|
|
1161
|
+
} else if (type === 2) {
|
|
1162
|
+
if (!timeout) {
|
|
1163
|
+
timeout = setTimeout(() => {
|
|
1164
|
+
timeout = null;
|
|
1165
|
+
func.apply(context, args);
|
|
1166
|
+
}, wait);
|
|
1167
|
+
}
|
|
1168
|
+
}
|
|
1169
|
+
};
|
|
1170
|
+
},
|
|
1171
|
+
recurve(fun, frequency = 500, duration = 5e3) {
|
|
1172
|
+
let timer = 0;
|
|
1173
|
+
setTimeout(function fn() {
|
|
1174
|
+
timer++;
|
|
1175
|
+
if (timer < Math.floor(duration / frequency)) {
|
|
1176
|
+
fun.call(this);
|
|
1177
|
+
setTimeout(fn, frequency);
|
|
1178
|
+
}
|
|
1179
|
+
});
|
|
1180
|
+
}
|
|
1181
|
+
};
|
|
1182
|
+
var StringUtils = {
|
|
1183
|
+
checkStr(str, type) {
|
|
1184
|
+
switch (type) {
|
|
1185
|
+
case "phone":
|
|
1186
|
+
return /^1[3|4|5|6|7|8|9][0-9]{9}$/.test(str);
|
|
1187
|
+
case "tel":
|
|
1188
|
+
return /^(0\d{2,3}-\d{7,8})(-\d{1,4})?$/.test(str);
|
|
1189
|
+
case "card":
|
|
1190
|
+
return /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/.test(str);
|
|
1191
|
+
case "pwd":
|
|
1192
|
+
return /^[a-zA-Z]\w{5,17}$/.test(str);
|
|
1193
|
+
case "postal":
|
|
1194
|
+
return /[1-9]\d{5}(?!\d)/.test(str);
|
|
1195
|
+
case "QQ":
|
|
1196
|
+
return /^[1-9][0-9]{4,9}$/.test(str);
|
|
1197
|
+
case "email":
|
|
1198
|
+
return /^[\w-]+(\.[\w-]+)*@[\w-]+(\.[\w-]+)+$/.test(str);
|
|
1199
|
+
case "money":
|
|
1200
|
+
return /^\d*(?:\.\d{0,2})?$/.test(str);
|
|
1201
|
+
case "URL":
|
|
1202
|
+
return /(http|ftp|https):\/\/[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^=%&:/~\+#]*[\w\-\@?^=%&/~\+#])?/.test(str);
|
|
1203
|
+
case "IP":
|
|
1204
|
+
return /((?:(?:25[0-5]|2[0-4]\\d|[01]?\\d?\\d)\\.){3}(?:25[0-5]|2[0-4]\\d|[01]?\\d?\\d))/.test(str);
|
|
1205
|
+
case "date":
|
|
1206
|
+
return /^(\d{4})\-(\d{2})\-(\d{2}) (\d{2})(?:\:\d{2}|:(\d{2}):(\d{2}))$/.test(str) || /^(\d{4})\-(\d{2})\-(\d{2})$/.test(str);
|
|
1207
|
+
case "number":
|
|
1208
|
+
return /^[0-9]$/.test(str);
|
|
1209
|
+
case "english":
|
|
1210
|
+
return /^[a-zA-Z]+$/.test(str);
|
|
1211
|
+
case "chinese":
|
|
1212
|
+
return /^[\u4E00-\u9FA5]+$/.test(str);
|
|
1213
|
+
case "lower":
|
|
1214
|
+
return /^[a-z]+$/.test(str);
|
|
1215
|
+
case "upper":
|
|
1216
|
+
return /^[A-Z]+$/.test(str);
|
|
1217
|
+
case "HTML":
|
|
1218
|
+
return /<("[^"]*"|'[^']*'|[^'">])*>/.test(str);
|
|
1219
|
+
default:
|
|
1220
|
+
return true;
|
|
1221
|
+
}
|
|
1222
|
+
},
|
|
1223
|
+
changeCase(str, type) {
|
|
1224
|
+
type = type || 4;
|
|
1225
|
+
switch (type) {
|
|
1226
|
+
case 1:
|
|
1227
|
+
return str.replace(/\b\w+\b/g, function(word) {
|
|
1228
|
+
return word.substring(0, 1).toUpperCase() + word.substring(1).toLowerCase();
|
|
1229
|
+
});
|
|
1230
|
+
case 2:
|
|
1231
|
+
return str.replace(/\b\w+\b/g, function(word) {
|
|
1232
|
+
return word.substring(0, 1).toLowerCase() + word.substring(1).toUpperCase();
|
|
1233
|
+
});
|
|
1234
|
+
case 3:
|
|
1235
|
+
return str.split("").map(function(word) {
|
|
1236
|
+
if (/[a-z]/.test(word)) {
|
|
1237
|
+
return word.toUpperCase();
|
|
1238
|
+
} else {
|
|
1239
|
+
return word.toLowerCase();
|
|
1240
|
+
}
|
|
1241
|
+
}).join("");
|
|
1242
|
+
case 4:
|
|
1243
|
+
return str.toUpperCase();
|
|
1244
|
+
case 5:
|
|
1245
|
+
return str.toLowerCase();
|
|
1246
|
+
default:
|
|
1247
|
+
return str;
|
|
1248
|
+
}
|
|
1249
|
+
},
|
|
1250
|
+
tag(strArray, ...args) {
|
|
1251
|
+
args = args.map((val) => {
|
|
1252
|
+
switch (CommUtils.getDataType(val)) {
|
|
1253
|
+
case "Object":
|
|
1254
|
+
return val || "{}";
|
|
1255
|
+
case "Array":
|
|
1256
|
+
return val || "[]";
|
|
1257
|
+
default:
|
|
1258
|
+
return val || "";
|
|
1259
|
+
}
|
|
1260
|
+
});
|
|
1261
|
+
return strArray.reduce((prev, next, index) => `${prev}${args[index - 1]}${next}`);
|
|
1262
|
+
},
|
|
1263
|
+
getByteLength(str) {
|
|
1264
|
+
return str.replace(/[\u0391-\uFFE5]/g, "aa").length;
|
|
1265
|
+
},
|
|
1266
|
+
subStringByte(str, start, n) {
|
|
1267
|
+
var r = /[^\x00-\xff]/g;
|
|
1268
|
+
if (str.replace(r, "mm").length <= n) {
|
|
1269
|
+
return str;
|
|
1270
|
+
}
|
|
1271
|
+
var m = Math.floor(n / 2);
|
|
1272
|
+
for (var i = m; i < str.length; i++) {
|
|
1273
|
+
let sub = str.substring(start, i);
|
|
1274
|
+
if (sub.replace(r, "mm").length >= n) {
|
|
1275
|
+
return sub;
|
|
1276
|
+
}
|
|
1277
|
+
}
|
|
1278
|
+
return str;
|
|
1279
|
+
},
|
|
1280
|
+
asString(value) {
|
|
1281
|
+
if (CommUtils.isEmpty(value)) {
|
|
1282
|
+
return "";
|
|
1283
|
+
} else {
|
|
1284
|
+
switch (CommUtils.getDataType()) {
|
|
1285
|
+
case "Object":
|
|
1286
|
+
case "Array":
|
|
1287
|
+
return JSON.stringify(value);
|
|
1288
|
+
default:
|
|
1289
|
+
return value;
|
|
1290
|
+
}
|
|
1291
|
+
}
|
|
1292
|
+
}
|
|
1293
|
+
};
|
|
1294
|
+
var AssertUtils = {
|
|
1295
|
+
notNull(data) {
|
|
1296
|
+
if (CommUtils.isEmpty(data)) {
|
|
1297
|
+
throw Error("\u4E0D\u80FD\u4E3A\u7A7A:>>>" + data);
|
|
1298
|
+
}
|
|
1299
|
+
},
|
|
1300
|
+
legalLnglat(lng, lat) {
|
|
1301
|
+
if (!GeoUtils.isLnglat(lng, lat)) {
|
|
1302
|
+
throw Error(ErrorType.COORDINATE_ERROR);
|
|
1303
|
+
}
|
|
1304
|
+
},
|
|
1305
|
+
contain(str, ...args) {
|
|
1306
|
+
let res = false;
|
|
1307
|
+
const len = args.length || 0;
|
|
1308
|
+
for (let i = 0, l = len; i < l; i++) {
|
|
1309
|
+
res = str.indexOf(args[i]) >= 0;
|
|
1310
|
+
}
|
|
1311
|
+
if (res) {
|
|
1312
|
+
throw Error(ErrorType.STRING_CHECK_LOSS);
|
|
1313
|
+
}
|
|
1314
|
+
},
|
|
1315
|
+
verify: {
|
|
1316
|
+
array(data) {
|
|
1317
|
+
if (CommUtils.getDataType(data) !== "Array") {
|
|
1318
|
+
throw Error(ErrorType.PARAMETER_ERROR_ARRAY + ":>>>" + data);
|
|
1319
|
+
}
|
|
1320
|
+
},
|
|
1321
|
+
function(data) {
|
|
1322
|
+
if (CommUtils.getDataType(data) !== "Function") {
|
|
1323
|
+
throw Error(ErrorType.PARAMETER_ERROR_FUNCTION + ":>>>" + data);
|
|
1324
|
+
}
|
|
1325
|
+
},
|
|
1326
|
+
object(data) {
|
|
1327
|
+
if (CommUtils.getDataType(data) !== "Object") {
|
|
1328
|
+
throw Error(ErrorType.PARAMETER_ERROR_OBJECT + ":>>>" + data);
|
|
1329
|
+
}
|
|
1330
|
+
}
|
|
1331
|
+
},
|
|
1332
|
+
legalJSON(data) {
|
|
1333
|
+
try {
|
|
1334
|
+
JSON.parse(data);
|
|
1335
|
+
} catch (err) {
|
|
1336
|
+
throw Error(ErrorType.JSON_PARSE_ERROR + ":>>>" + data);
|
|
1337
|
+
}
|
|
1338
|
+
},
|
|
1339
|
+
legalData(data, type) {
|
|
1340
|
+
const bool = StringUtils.checkStr(data, type);
|
|
1341
|
+
let typename = "";
|
|
1342
|
+
switch (type) {
|
|
1343
|
+
case "phone":
|
|
1344
|
+
typename = "\u7535\u8BDD";
|
|
1345
|
+
break;
|
|
1346
|
+
case "tel":
|
|
1347
|
+
typename = "\u5EA7\u673A";
|
|
1348
|
+
break;
|
|
1349
|
+
case "card":
|
|
1350
|
+
typename = "\u8EAB\u4EFD\u8BC1";
|
|
1351
|
+
break;
|
|
1352
|
+
case "pwd":
|
|
1353
|
+
typename = "\u5BC6\u7801";
|
|
1354
|
+
break;
|
|
1355
|
+
case "postal":
|
|
1356
|
+
typename = "\u90AE\u653F\u7F16\u7801";
|
|
1357
|
+
break;
|
|
1358
|
+
case "QQ":
|
|
1359
|
+
typename = "QQ";
|
|
1360
|
+
break;
|
|
1361
|
+
case "email":
|
|
1362
|
+
typename = "\u90AE\u7BB1";
|
|
1363
|
+
break;
|
|
1364
|
+
case "money":
|
|
1365
|
+
typename = "\u91D1\u989D";
|
|
1366
|
+
break;
|
|
1367
|
+
case "URL":
|
|
1368
|
+
typename = "\u7F51\u5740";
|
|
1369
|
+
break;
|
|
1370
|
+
case "IP":
|
|
1371
|
+
typename = "IP";
|
|
1372
|
+
break;
|
|
1373
|
+
case "date":
|
|
1374
|
+
typename = "\u65E5\u671F\u65F6\u95F4";
|
|
1375
|
+
break;
|
|
1376
|
+
case "number":
|
|
1377
|
+
typename = "\u6570\u5B57";
|
|
1378
|
+
break;
|
|
1379
|
+
case "english":
|
|
1380
|
+
typename = "\u82F1\u6587";
|
|
1381
|
+
break;
|
|
1382
|
+
case "chinese":
|
|
1383
|
+
typename = "\u4E2D\u6587";
|
|
1384
|
+
break;
|
|
1385
|
+
case "lower":
|
|
1386
|
+
typename = "\u5C0F\u5199";
|
|
1387
|
+
break;
|
|
1388
|
+
case "upper":
|
|
1389
|
+
typename = "\u5927\u5199";
|
|
1390
|
+
break;
|
|
1391
|
+
case "HTML":
|
|
1392
|
+
typename = "HTML\u6807\u8BB0";
|
|
1393
|
+
break;
|
|
1394
|
+
}
|
|
1395
|
+
if (!bool) {
|
|
1396
|
+
throw Error(ErrorType.PARAMETER_ERROR + ":>>>\u4E0D\u662F" + typename);
|
|
1397
|
+
}
|
|
1398
|
+
}
|
|
1399
|
+
};
|
|
1400
|
+
class AudioPlayer {
|
|
1401
|
+
constructor(url) {
|
|
1402
|
+
this.audio = new Audio();
|
|
1403
|
+
this.audio.src = url;
|
|
1404
|
+
}
|
|
1405
|
+
play() {
|
|
1406
|
+
!this.muted && this.audio.play();
|
|
1407
|
+
}
|
|
1408
|
+
pause() {
|
|
1409
|
+
this.audio.pause();
|
|
1410
|
+
}
|
|
1411
|
+
get muted() {
|
|
1412
|
+
return this.audio.muted;
|
|
1413
|
+
}
|
|
1414
|
+
set muted(val) {
|
|
1415
|
+
this.audio.muted = val;
|
|
1416
|
+
}
|
|
1417
|
+
}
|
|
1418
|
+
class CanvasDrawer {
|
|
1419
|
+
constructor(el) {
|
|
1420
|
+
if (CommUtils.getDataType(el) === "String") {
|
|
1421
|
+
el = document.querySelector("#" + el);
|
|
1422
|
+
}
|
|
1423
|
+
this.ctx = el.getContext("2d");
|
|
1424
|
+
}
|
|
1425
|
+
drawLine(startX, startY, endX, endY, options = {}) {
|
|
1426
|
+
this.cxt.beginPath();
|
|
1427
|
+
const width = options.width || 1;
|
|
1428
|
+
const color = options.color || "#000";
|
|
1429
|
+
this.cxt.lineWidth = width;
|
|
1430
|
+
this.cxt.fillStyle = color;
|
|
1431
|
+
this.cxt.moveTo(startX, startY);
|
|
1432
|
+
this.cxt.lineTo(endX, endY);
|
|
1433
|
+
this.cxt.closePath();
|
|
1434
|
+
this.cxt.fill();
|
|
1435
|
+
}
|
|
1436
|
+
drawArc(x, y, radius, startAngle, endAngle, anticlockwise, isFill, bgColor) {
|
|
1437
|
+
if (isFill) {
|
|
1438
|
+
this.cxt.fillStyle = bgColor;
|
|
1439
|
+
this.cxt.beginPath();
|
|
1440
|
+
this.cxt.arc(x, y, radius, MathUtils.degreesToRadians(startAngle), MathUtils.degreesToRadians(endAngle), anticlockwise);
|
|
1441
|
+
this.cxt.closePath();
|
|
1442
|
+
this.cxt.fill();
|
|
1443
|
+
} else {
|
|
1444
|
+
this.cxt.strokeStyle = bgColor;
|
|
1445
|
+
this.cxt.beginPath();
|
|
1446
|
+
this.cxt.arc(x, y, radius, MathUtils.degreesToRadians(startAngle), MathUtils.degreesToRadians(endAngle), anticlockwise);
|
|
1447
|
+
this.cxt.stroke();
|
|
1448
|
+
}
|
|
1449
|
+
}
|
|
1450
|
+
}
|
|
1451
|
+
function EventDispatcher() {
|
|
1452
|
+
}
|
|
1453
|
+
Object.assign(EventDispatcher.prototype, {
|
|
1454
|
+
addEventListener(type, listener, context, mutexStatus = false) {
|
|
1455
|
+
if (this._listeners === void 0)
|
|
1456
|
+
this._listeners = {};
|
|
1457
|
+
this._mutex = this._mutex || {};
|
|
1458
|
+
this._context = context;
|
|
1459
|
+
const mutex = this._mutex;
|
|
1460
|
+
const listeners = this._listeners;
|
|
1461
|
+
if (listeners[type] === void 0) {
|
|
1462
|
+
listeners[type] = [];
|
|
1463
|
+
}
|
|
1464
|
+
if (listeners[type].indexOf(listener) === -1) {
|
|
1465
|
+
if (mutexStatus) {
|
|
1466
|
+
mutex[type] = listener;
|
|
1467
|
+
}
|
|
1468
|
+
listeners[type].push(listener);
|
|
1469
|
+
}
|
|
1470
|
+
return this;
|
|
1471
|
+
},
|
|
1472
|
+
hasEventListener(type, listener) {
|
|
1473
|
+
if (this._listeners === void 0)
|
|
1474
|
+
return false;
|
|
1475
|
+
const listeners = this._listeners;
|
|
1476
|
+
return listeners[type] !== void 0 && listeners[type].indexOf(listener) !== -1;
|
|
1477
|
+
},
|
|
1478
|
+
removeEventListener(type, listener) {
|
|
1479
|
+
if (this._listeners === void 0)
|
|
1480
|
+
return;
|
|
1481
|
+
const listeners = this._listeners;
|
|
1482
|
+
const listenerArray = listeners[type];
|
|
1483
|
+
if (this._mutex[type] === listener) {
|
|
1484
|
+
this._mutex[type] = null;
|
|
1485
|
+
}
|
|
1486
|
+
if (listenerArray !== void 0) {
|
|
1487
|
+
const index = listenerArray.map((d) => d.toString()).indexOf(listener.toString());
|
|
1488
|
+
if (index !== -1) {
|
|
1489
|
+
listenerArray.splice(index, 1);
|
|
1490
|
+
}
|
|
1491
|
+
}
|
|
1492
|
+
},
|
|
1493
|
+
dispatchEvent(event) {
|
|
1494
|
+
if (this._listeners === void 0)
|
|
1495
|
+
return;
|
|
1496
|
+
const listeners = this._listeners;
|
|
1497
|
+
const listenerArray = listeners[event.type];
|
|
1498
|
+
if (listenerArray !== void 0) {
|
|
1499
|
+
event.target = this;
|
|
1500
|
+
const array = listenerArray.slice(0);
|
|
1501
|
+
if (this._mutex[event.type]) {
|
|
1502
|
+
const find = array.find((item) => item === this._mutex[event.type]);
|
|
1503
|
+
find.call(this._context || this, event);
|
|
1504
|
+
return;
|
|
1505
|
+
}
|
|
1506
|
+
for (let i = 0, l = array.length; i < l; i++) {
|
|
1507
|
+
array[i].call(this._context || this, event);
|
|
1508
|
+
}
|
|
1509
|
+
}
|
|
1510
|
+
},
|
|
1511
|
+
removeAllListener() {
|
|
1512
|
+
this._mutex = {};
|
|
1513
|
+
for (const key in this._listeners) {
|
|
1514
|
+
this._listeners[key] = [];
|
|
1515
|
+
}
|
|
1516
|
+
}
|
|
1517
|
+
});
|
|
1518
|
+
Object.assign(Map.prototype, {
|
|
1519
|
+
isEmpty() {
|
|
1520
|
+
return this.size === 0;
|
|
1521
|
+
},
|
|
1522
|
+
_values() {
|
|
1523
|
+
return Array.from(Map.prototype.values.call(this));
|
|
1524
|
+
},
|
|
1525
|
+
_keys() {
|
|
1526
|
+
return Array.from(Map.prototype.keys.call(this));
|
|
1527
|
+
},
|
|
1528
|
+
_entries() {
|
|
1529
|
+
return Array.from(Map.prototype.entries.call(this));
|
|
1530
|
+
}
|
|
1531
|
+
});
|
|
1532
|
+
function HashMap() {
|
|
1533
|
+
return /* @__PURE__ */ new Map();
|
|
1534
|
+
}
|
|
1535
|
+
HashMap.fromEntries = function(array = []) {
|
|
1536
|
+
const hashMap = new HashMap();
|
|
1537
|
+
array.forEach((element) => {
|
|
1538
|
+
if (Array.isArray(element) && element.length === 2) {
|
|
1539
|
+
hashMap.set(element[0], element[1]);
|
|
1540
|
+
}
|
|
1541
|
+
});
|
|
1542
|
+
return hashMap;
|
|
1543
|
+
};
|
|
1544
|
+
class WebSocketClient extends EventDispatcher {
|
|
1545
|
+
constructor(url = "ws://127.0.0.1:10088") {
|
|
1546
|
+
super();
|
|
1547
|
+
this.maxCheckTimes = 10;
|
|
1548
|
+
this.url = url;
|
|
1549
|
+
this.checkTimes = 0;
|
|
1550
|
+
this.connectStatus = false;
|
|
1551
|
+
this.connect();
|
|
1552
|
+
this.connCheckStatus(this.maxCheckTimes);
|
|
1553
|
+
WebSocketClient.instance = this;
|
|
1554
|
+
}
|
|
1555
|
+
connect() {
|
|
1556
|
+
this.disconnect();
|
|
1557
|
+
if (this.url) {
|
|
1558
|
+
try {
|
|
1559
|
+
console.info("\u521B\u5EFAws\u8FDE\u63A5>>>" + this.url);
|
|
1560
|
+
this.client = new WebSocket(this.url);
|
|
1561
|
+
if (this.client) {
|
|
1562
|
+
const self = this;
|
|
1563
|
+
this.client.onopen = function(message) {
|
|
1564
|
+
self.dispatchEvent({
|
|
1565
|
+
type: EventType.WEB_SOCKET_CONNECT,
|
|
1566
|
+
message
|
|
1567
|
+
});
|
|
1568
|
+
};
|
|
1569
|
+
this.client.onmessage = function(message) {
|
|
1570
|
+
self.connectStatus = true;
|
|
1571
|
+
self.dispatchEvent({
|
|
1572
|
+
type: EventType.WEB_SOCKET_MESSAGE,
|
|
1573
|
+
message
|
|
1574
|
+
});
|
|
1575
|
+
};
|
|
1576
|
+
this.client.onclose = function(message) {
|
|
1577
|
+
self.dispatchEvent({
|
|
1578
|
+
type: EventType.WEB_SOCKET_CLOSE,
|
|
1579
|
+
message
|
|
1580
|
+
});
|
|
1581
|
+
};
|
|
1582
|
+
if (this.checkTimes === this.maxCheckTimes) {
|
|
1583
|
+
this.client.onerror = function(message) {
|
|
1584
|
+
self.dispatchEvent({
|
|
1585
|
+
type: EventType.WEB_SOCKET_ERROR,
|
|
1586
|
+
message
|
|
1587
|
+
});
|
|
1588
|
+
};
|
|
1589
|
+
}
|
|
1590
|
+
}
|
|
1591
|
+
} catch (ex) {
|
|
1592
|
+
console.error("\u521B\u5EFAws\u8FDE\u63A5\u5931\u8D25" + this.url + ":" + ex);
|
|
1593
|
+
}
|
|
1594
|
+
}
|
|
1595
|
+
}
|
|
1596
|
+
disconnect() {
|
|
1597
|
+
if (this.client) {
|
|
1598
|
+
try {
|
|
1599
|
+
console.log("ws\u65AD\u5F00\u8FDE\u63A5" + this.url);
|
|
1600
|
+
this.client.close();
|
|
1601
|
+
this.client = null;
|
|
1602
|
+
} catch (ex) {
|
|
1603
|
+
this.client = null;
|
|
1604
|
+
}
|
|
1605
|
+
}
|
|
1606
|
+
}
|
|
1607
|
+
connCheckStatus(times) {
|
|
1608
|
+
if (this.checkTimes > times)
|
|
1609
|
+
return;
|
|
1610
|
+
setTimeout(() => {
|
|
1611
|
+
this.checkTimes++;
|
|
1612
|
+
if (this.client && this.client.readyState !== 0 && this.client.readyState !== 1) {
|
|
1613
|
+
this.connect();
|
|
1614
|
+
}
|
|
1615
|
+
this.connCheckStatus(times);
|
|
1616
|
+
}, 2e3);
|
|
1617
|
+
}
|
|
1618
|
+
send(message) {
|
|
1619
|
+
if (this.client && this.client.readyState === 1) {
|
|
1620
|
+
this.client.send(message);
|
|
1621
|
+
return true;
|
|
1622
|
+
}
|
|
1623
|
+
console.error(this.url + "\u6D88\u606F\u53D1\u9001\u5931\u8D25\uFF1A" + message);
|
|
1624
|
+
return false;
|
|
1625
|
+
}
|
|
1626
|
+
heartbeat() {
|
|
1627
|
+
setTimeout(() => {
|
|
1628
|
+
if (this.client && this.client.readyState === 1) {
|
|
1629
|
+
this.send("HeartBeat");
|
|
1630
|
+
}
|
|
1631
|
+
console.log("HeartBeat," + this.url);
|
|
1632
|
+
setTimeout(this.heartbeat, 3e4);
|
|
1633
|
+
}, 1e3);
|
|
1634
|
+
}
|
|
1635
|
+
static getInstance() {
|
|
1636
|
+
if (WebSocketClient.instance) {
|
|
1637
|
+
return WebSocketClient.instance;
|
|
1638
|
+
} else {
|
|
1639
|
+
return Object.freeze(new WebSocketClient());
|
|
1640
|
+
}
|
|
1641
|
+
}
|
|
1642
|
+
static get _instance() {
|
|
1643
|
+
return this.getInstance();
|
|
1644
|
+
}
|
|
1645
|
+
}
|
|
1646
|
+
class WebStorage {
|
|
1647
|
+
constructor(type = 1) {
|
|
1648
|
+
this.cacheType = type;
|
|
1649
|
+
if (type === 1) {
|
|
1650
|
+
this.storage = window.localStorage;
|
|
1651
|
+
} else if (type === 2) {
|
|
1652
|
+
this.storage = window.sessionStorage;
|
|
1653
|
+
} else {
|
|
1654
|
+
throw new Error(ErrorType.PARAMETER_ERROR);
|
|
1655
|
+
}
|
|
1656
|
+
}
|
|
1657
|
+
setItem(key, value, expired) {
|
|
1658
|
+
const tempObj = { key, value };
|
|
1659
|
+
if (this.cacheType === 1) {
|
|
1660
|
+
const currTime = Date.now();
|
|
1661
|
+
if (expired) {
|
|
1662
|
+
tempObj.expired = currTime + expired * 1e3;
|
|
1663
|
+
}
|
|
1664
|
+
}
|
|
1665
|
+
this.storage[key] = JSON.stringify(tempObj);
|
|
1666
|
+
return tempObj;
|
|
1667
|
+
}
|
|
1668
|
+
getItem(key) {
|
|
1669
|
+
const storageData = this.storage.getItem(key) || null;
|
|
1670
|
+
const tempObj = JSON.parse(storageData) || {};
|
|
1671
|
+
if (this.cacheType === 1) {
|
|
1672
|
+
const expired = tempObj.expired || Date.now();
|
|
1673
|
+
if (Date.now() > expired) {
|
|
1674
|
+
this.remove(key);
|
|
1675
|
+
return null;
|
|
1676
|
+
}
|
|
1677
|
+
}
|
|
1678
|
+
return tempObj.value;
|
|
1679
|
+
}
|
|
1680
|
+
remove(keys) {
|
|
1681
|
+
if (keys) {
|
|
1682
|
+
if (keys.indexOf(",") > -1) {
|
|
1683
|
+
keys.split(",").forEach((key) => {
|
|
1684
|
+
this.storage.removeItem(key);
|
|
1685
|
+
});
|
|
1686
|
+
} else {
|
|
1687
|
+
this.storage.removeItem(keys);
|
|
1688
|
+
}
|
|
1689
|
+
}
|
|
1690
|
+
}
|
|
1691
|
+
clear() {
|
|
1692
|
+
this.storage.clear();
|
|
1693
|
+
}
|
|
1694
|
+
}
|
|
1695
|
+
class DevicePixelRatio {
|
|
1696
|
+
constructor(magnification = 1) {
|
|
1697
|
+
this.magnification = magnification;
|
|
1698
|
+
}
|
|
1699
|
+
_getSystem() {
|
|
1700
|
+
var agent = navigator.userAgent.toLowerCase();
|
|
1701
|
+
if (agent.indexOf("windows") >= 0) {
|
|
1702
|
+
return true;
|
|
1703
|
+
}
|
|
1704
|
+
}
|
|
1705
|
+
_addHandler(element, type, handler) {
|
|
1706
|
+
if (element.addEventListener) {
|
|
1707
|
+
element.addEventListener(type, handler, false);
|
|
1708
|
+
} else if (element.attachEvent) {
|
|
1709
|
+
element.attachEvent("on" + type, handler);
|
|
1710
|
+
} else {
|
|
1711
|
+
element["on" + type] = handler;
|
|
1712
|
+
}
|
|
1713
|
+
}
|
|
1714
|
+
_correct() {
|
|
1715
|
+
let pageWidth = window.innerWidth;
|
|
1716
|
+
if (typeof pageWidth != "number") {
|
|
1717
|
+
if (document.compatMode == "CSS1Compat") {
|
|
1718
|
+
pageWidth = document.documentElement.clientWidth;
|
|
1719
|
+
} else {
|
|
1720
|
+
pageWidth = document.body.clientWidth;
|
|
1721
|
+
}
|
|
1722
|
+
}
|
|
1723
|
+
if (pageWidth <= 750) {
|
|
1724
|
+
const baseSize = 75;
|
|
1725
|
+
const scale = document.documentElement.clientWidth / pageWidth;
|
|
1726
|
+
document.documentElement.style.fontSize = this.magnification * baseSize * Math.min(scale, 2) + "px";
|
|
1727
|
+
} else if (pageWidth > 750 && pageWidth <= 1200) {
|
|
1728
|
+
const baseSize = 85;
|
|
1729
|
+
const scale = document.documentElement.clientWidth / pageWidth;
|
|
1730
|
+
document.documentElement.style.fontSize = this.magnification * baseSize * Math.min(scale, 2) + "px";
|
|
1731
|
+
} else {
|
|
1732
|
+
const baseSize = 100;
|
|
1733
|
+
const scale = document.documentElement.clientWidth / 1920;
|
|
1734
|
+
document.documentElement.style.fontSize = this.magnification * baseSize * Math.min(scale, 2) + "px";
|
|
1735
|
+
}
|
|
1736
|
+
}
|
|
1737
|
+
_watch() {
|
|
1738
|
+
let t = this;
|
|
1739
|
+
t._addHandler(window, "resize", function() {
|
|
1740
|
+
t._correct();
|
|
1741
|
+
});
|
|
1742
|
+
}
|
|
1743
|
+
init() {
|
|
1744
|
+
let t = this;
|
|
1745
|
+
if (t._getSystem()) {
|
|
1746
|
+
t._correct();
|
|
1747
|
+
t._watch();
|
|
1748
|
+
}
|
|
1749
|
+
}
|
|
1750
|
+
}
|
|
1751
|
+
export { AnimateUtils, ArrayUtils, AssertUtils, AudioPlayer, BrowserUtils, CanvasDrawer, Cookie, CoordsUtils, DateUtils, DevicePixelRatio, DomUtils, ErrorType, EventDispatcher, EventType, FileUtils, GeoUtils, GraphicType, HashMap, LayerType, MathUtils, MeasureMode, OptimizeUtils, StringUtils, CommUtils as Utils, WebSocketClient, WebStorage };
|