gis-common 4.2.24 → 4.2.26
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/constant/ErrorType.d.ts +16 -13
- package/dist/constant/FormType.d.ts +6 -0
- package/dist/constant/GraphicTypes.d.ts +7 -5
- package/dist/constant/LayerType.d.ts +7 -7
- package/dist/constant/index.d.ts +1 -0
- package/dist/core/EventDispatcher.d.ts +2 -0
- package/dist/core/MqttClient.d.ts +3 -3
- package/dist/core/WebSocketClient.d.ts +2 -1
- package/dist/gis-common.es.js +1080 -1085
- package/dist/gis-common.umd.js +1 -1
- package/dist/utils/AssertUtil.d.ts +0 -9
- package/dist/utils/ExceptionUtil.d.ts +15 -0
- package/dist/utils/MathUtil.d.ts +1 -1
- package/dist/utils/StringUtil.d.ts +0 -25
- package/dist/utils/ValidateUtil.d.ts +20 -0
- package/dist/utils/index.d.ts +2 -0
- package/package.json +1 -1
package/dist/gis-common.es.js
CHANGED
|
@@ -30,9 +30,6 @@ var EventType = /* @__PURE__ */ ((EventType2) => {
|
|
|
30
30
|
})(EventType || {});
|
|
31
31
|
var ErrorType = /* @__PURE__ */ ((ErrorType2) => {
|
|
32
32
|
ErrorType2["LOGIN_EXPIRED"] = "登录信息过期,请重新登录";
|
|
33
|
-
ErrorType2["CROSS_ERROR"] = "不允许跨站点访问资源";
|
|
34
|
-
ErrorType2["NO_DATA_FOUND"] = "资源不存在";
|
|
35
|
-
ErrorType2["TIMEOUT"] = "请求超时";
|
|
36
33
|
ErrorType2["INTERNAL_ERROR"] = "内部错误";
|
|
37
34
|
ErrorType2["NETWORK_ERROR"] = "请求失败,请检查网络是否已连接";
|
|
38
35
|
ErrorType2["PROCESS_FAIL"] = "任务处理失败";
|
|
@@ -40,32 +37,44 @@ var ErrorType = /* @__PURE__ */ ((ErrorType2) => {
|
|
|
40
37
|
ErrorType2["AUTH_VERIFY_ERROR"] = "权限验证失败";
|
|
41
38
|
ErrorType2["INSTANCE_DUPLICATE"] = "实例为单例模式,不允许重复构建";
|
|
42
39
|
ErrorType2["JSON_PARSE_ERROR"] = "JSON解析失败,格式有误";
|
|
43
|
-
ErrorType2["JSON_VALUE_ERROR"] = "JSON无此键";
|
|
44
40
|
ErrorType2["STRING_CHECK_LOSS"] = "字符串缺少关键字";
|
|
45
|
-
ErrorType2["PARAMETER_ERROR"] = "
|
|
46
|
-
ErrorType2["PARAMETER_ERROR_ARRAY"] = "
|
|
47
|
-
ErrorType2["PARAMETER_ERROR_STRING"] = "
|
|
48
|
-
ErrorType2["PARAMETER_ERROR_FUNCTION"] = "
|
|
49
|
-
ErrorType2["PARAMETER_ERROR_OBJECT"] = "
|
|
50
|
-
ErrorType2["PARAMETER_ERROR_INTEGER"] = "
|
|
51
|
-
ErrorType2["PARAMETER_ERROR_NUMBER"] = "
|
|
52
|
-
ErrorType2["PARAMETER_ERROR_LACK"] = "
|
|
41
|
+
ErrorType2["PARAMETER_ERROR"] = "验证参数类型失败";
|
|
42
|
+
ErrorType2["PARAMETER_ERROR_ARRAY"] = "验证参数类型失败,必须是数组";
|
|
43
|
+
ErrorType2["PARAMETER_ERROR_STRING"] = "验证参数类型失败,必须是字符";
|
|
44
|
+
ErrorType2["PARAMETER_ERROR_FUNCTION"] = "验证参数类型失败,必须是函数";
|
|
45
|
+
ErrorType2["PARAMETER_ERROR_OBJECT"] = "验证参数类型失败,必须是对象";
|
|
46
|
+
ErrorType2["PARAMETER_ERROR_INTEGER"] = "验证参数类型失败,必须是整型";
|
|
47
|
+
ErrorType2["PARAMETER_ERROR_NUMBER"] = "验证参数类型失败,必须是数值";
|
|
48
|
+
ErrorType2["PARAMETER_ERROR_LACK"] = "验证参数类型失败,必须非空";
|
|
49
|
+
ErrorType2["PARAMETER_ERROR_ENUM"] = "验证参数类型失败,必须是指定的值";
|
|
53
50
|
ErrorType2["DATA_ERROR"] = "格式类型验证失败";
|
|
54
51
|
ErrorType2["DATA_ERROR_COORDINATE"] = "格式类型验证失败,必须是坐标";
|
|
55
52
|
ErrorType2["DATA_ERROR_COLOR"] = "格式类型验证失败,必须是颜色代码";
|
|
56
53
|
ErrorType2["DATA_ERROR_GEOJSON"] = "格式类型验证失败,必须是GeoJSON";
|
|
54
|
+
ErrorType2["REQUEST_ERROR"] = "请求资源失败";
|
|
55
|
+
ErrorType2["REQUEST_ERROR_CROSS"] = "不允许跨站点访问资源";
|
|
56
|
+
ErrorType2["REQUEST_ERROR_TIMEOUT"] = "请求超时,请检查网络";
|
|
57
|
+
ErrorType2["REQUEST_ERROR_NOT_FOUND"] = "请求资源不存在";
|
|
58
|
+
ErrorType2["REQUEST_ERROR_FORBIDDEN"] = "请求资源禁止访问";
|
|
59
|
+
ErrorType2["REQUEST_ERROR_EMPTY"] = "请求数据记录为空";
|
|
57
60
|
return ErrorType2;
|
|
58
61
|
})(ErrorType || {});
|
|
59
62
|
var LayerType = /* @__PURE__ */ ((LayerType2) => {
|
|
60
|
-
LayerType2["SUPER_MAP_IMAGES"] = "
|
|
61
|
-
LayerType2["SUPER_MAP_DATA"] = "
|
|
62
|
-
LayerType2["ARC_GIS_MAP_IMAGES"] = "
|
|
63
|
-
LayerType2["ARC_GIS_MAP_DATA"] = "
|
|
64
|
-
LayerType2["OSGB_LAYER"] = "
|
|
65
|
-
LayerType2["S3M_GROUP"] = "
|
|
66
|
-
LayerType2["TERRAIN_LAYER"] = "
|
|
63
|
+
LayerType2[LayerType2["SUPER_MAP_IMAGES"] = 0] = "SUPER_MAP_IMAGES";
|
|
64
|
+
LayerType2[LayerType2["SUPER_MAP_DATA"] = 1] = "SUPER_MAP_DATA";
|
|
65
|
+
LayerType2[LayerType2["ARC_GIS_MAP_IMAGES"] = 2] = "ARC_GIS_MAP_IMAGES";
|
|
66
|
+
LayerType2[LayerType2["ARC_GIS_MAP_DATA"] = 3] = "ARC_GIS_MAP_DATA";
|
|
67
|
+
LayerType2[LayerType2["OSGB_LAYER"] = 4] = "OSGB_LAYER";
|
|
68
|
+
LayerType2[LayerType2["S3M_GROUP"] = 5] = "S3M_GROUP";
|
|
69
|
+
LayerType2[LayerType2["TERRAIN_LAYER"] = 6] = "TERRAIN_LAYER";
|
|
67
70
|
return LayerType2;
|
|
68
71
|
})(LayerType || {});
|
|
72
|
+
var FormType = /* @__PURE__ */ ((FormType2) => {
|
|
73
|
+
FormType2[FormType2["ADD"] = 0] = "ADD";
|
|
74
|
+
FormType2[FormType2["MODIFY"] = 1] = "MODIFY";
|
|
75
|
+
FormType2[FormType2["DETAIL"] = 2] = "DETAIL";
|
|
76
|
+
return FormType2;
|
|
77
|
+
})(FormType || {});
|
|
69
78
|
var GraphicType = /* @__PURE__ */ ((GraphicType2) => {
|
|
70
79
|
GraphicType2["POINT"] = "Point";
|
|
71
80
|
GraphicType2["POLYLINE"] = "Polyline";
|
|
@@ -77,9 +86,11 @@ var GraphicType = /* @__PURE__ */ ((GraphicType2) => {
|
|
|
77
86
|
GraphicType2["LABEL"] = "Label";
|
|
78
87
|
GraphicType2["MODEL"] = "Model";
|
|
79
88
|
GraphicType2["WALL"] = "Wall";
|
|
89
|
+
GraphicType2["CIRCLE"] = "Circle";
|
|
80
90
|
return GraphicType2;
|
|
81
91
|
})(GraphicType || {});
|
|
82
92
|
var LineSymbol = /* @__PURE__ */ ((LineSymbol2) => {
|
|
93
|
+
LineSymbol2[LineSymbol2["SOLID"] = 0] = "SOLID";
|
|
83
94
|
LineSymbol2["DASH"] = "10,5";
|
|
84
95
|
LineSymbol2["DOT"] = "3";
|
|
85
96
|
LineSymbol2["DASHDOT"] = "10,3,3,3";
|
|
@@ -87,10 +98,10 @@ var LineSymbol = /* @__PURE__ */ ((LineSymbol2) => {
|
|
|
87
98
|
return LineSymbol2;
|
|
88
99
|
})(LineSymbol || {});
|
|
89
100
|
var MeasureMode = /* @__PURE__ */ ((MeasureMode2) => {
|
|
90
|
-
MeasureMode2["DISTANCE"] = "
|
|
91
|
-
MeasureMode2["AREA"] = "
|
|
92
|
-
MeasureMode2["HEIGHT"] = "
|
|
93
|
-
MeasureMode2["ANGLE"] = "
|
|
101
|
+
MeasureMode2[MeasureMode2["DISTANCE"] = 0] = "DISTANCE";
|
|
102
|
+
MeasureMode2[MeasureMode2["AREA"] = 1] = "AREA";
|
|
103
|
+
MeasureMode2[MeasureMode2["HEIGHT"] = 2] = "HEIGHT";
|
|
104
|
+
MeasureMode2[MeasureMode2["ANGLE"] = 3] = "ANGLE";
|
|
94
105
|
return MeasureMode2;
|
|
95
106
|
})(MeasureMode || {});
|
|
96
107
|
class AudioPlayer {
|
|
@@ -121,7 +132,7 @@ class AudioPlayer {
|
|
|
121
132
|
}
|
|
122
133
|
class Cookie {
|
|
123
134
|
static set(name, value, days = 30) {
|
|
124
|
-
if (typeof name !== "string" || typeof
|
|
135
|
+
if (typeof name !== "string" || typeof days !== "number") {
|
|
125
136
|
throw new Error("Invalid arguments");
|
|
126
137
|
}
|
|
127
138
|
const exp = /* @__PURE__ */ new Date();
|
|
@@ -145,870 +156,876 @@ class Cookie {
|
|
|
145
156
|
}
|
|
146
157
|
}
|
|
147
158
|
}
|
|
148
|
-
const
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
159
|
+
const Util = {
|
|
160
|
+
/**
|
|
161
|
+
* 获取数据类型
|
|
162
|
+
*
|
|
163
|
+
* @param data 待判断的数据
|
|
164
|
+
* @returns 返回数据类型字符串
|
|
165
|
+
*/
|
|
166
|
+
getDataType(data) {
|
|
167
|
+
return Object.prototype.toString.call(data).slice(8, -1);
|
|
153
168
|
},
|
|
154
|
-
|
|
155
|
-
return
|
|
169
|
+
asArray(obj) {
|
|
170
|
+
return this.isEmpty(obj) ? [] : Array.isArray(obj) ? obj : [obj];
|
|
171
|
+
},
|
|
172
|
+
asNumber(a) {
|
|
173
|
+
return Number.isNaN(Number(a)) ? 0 : Number(a);
|
|
156
174
|
},
|
|
157
175
|
/**
|
|
158
|
-
*
|
|
176
|
+
* 将值转换为字符串
|
|
159
177
|
*
|
|
160
|
-
* @param
|
|
161
|
-
* @returns
|
|
178
|
+
* @param value 要转换的值
|
|
179
|
+
* @returns 转换后的字符串,如果值为空,则返回空字符串
|
|
162
180
|
*/
|
|
163
|
-
|
|
164
|
-
|
|
181
|
+
asString(value) {
|
|
182
|
+
if (this.isEmpty(value)) {
|
|
183
|
+
return "";
|
|
184
|
+
} else {
|
|
185
|
+
switch (this.getDataType(value)) {
|
|
186
|
+
case "Object":
|
|
187
|
+
case "Array":
|
|
188
|
+
return JSON.stringify(value);
|
|
189
|
+
default:
|
|
190
|
+
return value;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
165
193
|
},
|
|
166
194
|
/**
|
|
167
|
-
*
|
|
195
|
+
* 判断传入的值是否为空
|
|
168
196
|
*
|
|
169
|
-
* @param
|
|
170
|
-
* @returns
|
|
197
|
+
* @param value 待判断的值
|
|
198
|
+
* @returns 返回布尔值,表示是否为空
|
|
171
199
|
*/
|
|
172
|
-
|
|
173
|
-
|
|
200
|
+
isEmpty(value) {
|
|
201
|
+
if (value == null) {
|
|
202
|
+
return true;
|
|
203
|
+
}
|
|
204
|
+
const type = this.getDataType(value);
|
|
205
|
+
switch (type) {
|
|
206
|
+
case "String":
|
|
207
|
+
return value.trim() === "";
|
|
208
|
+
case "Array":
|
|
209
|
+
return !value.length;
|
|
210
|
+
case "Object":
|
|
211
|
+
return !Object.keys(value).length;
|
|
212
|
+
case "Boolean":
|
|
213
|
+
return !value;
|
|
214
|
+
default:
|
|
215
|
+
return false;
|
|
216
|
+
}
|
|
174
217
|
},
|
|
175
|
-
|
|
176
|
-
|
|
218
|
+
/**
|
|
219
|
+
* 将JSON对象转换为FormData对象
|
|
220
|
+
*
|
|
221
|
+
* @param json 待转换的JSON对象,其属性值为字符串或Blob类型
|
|
222
|
+
* @returns 转换后的FormData对象
|
|
223
|
+
*/
|
|
224
|
+
json2form(json) {
|
|
225
|
+
const formData = new FormData();
|
|
226
|
+
if (this.isEmpty(json)) return formData;
|
|
227
|
+
Object.keys(json).forEach((key) => {
|
|
228
|
+
formData.append(key, json[key] instanceof Object ? JSON.stringify(json[key]) : json[key]);
|
|
229
|
+
});
|
|
230
|
+
return formData;
|
|
177
231
|
},
|
|
178
232
|
/**
|
|
179
|
-
*
|
|
233
|
+
* 生成GUID
|
|
180
234
|
*
|
|
181
|
-
* @
|
|
182
|
-
* @param min 最小值
|
|
183
|
-
* @param max 最大值
|
|
184
|
-
* @returns 返回限制后的数值
|
|
235
|
+
* @returns 返回一个由8个16进制数组成的GUID字符串
|
|
185
236
|
*/
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
};
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
antiquewhite: [250, 235, 215],
|
|
193
|
-
aqua: [0, 255, 255],
|
|
194
|
-
aquamarine: [127, 255, 212],
|
|
195
|
-
azure: [240, 255, 255],
|
|
196
|
-
beige: [245, 245, 220],
|
|
197
|
-
bisque: [255, 228, 196],
|
|
198
|
-
black: [0, 0, 0],
|
|
199
|
-
blanchedalmond: [255, 235, 205],
|
|
200
|
-
blue: [0, 0, 255],
|
|
201
|
-
blueviolet: [138, 43, 226],
|
|
202
|
-
brown: [165, 42, 42],
|
|
203
|
-
burlywood: [222, 184, 135],
|
|
204
|
-
cadetblue: [95, 158, 160],
|
|
205
|
-
chartreuse: [127, 255, 0],
|
|
206
|
-
chocolate: [210, 105, 30],
|
|
207
|
-
coral: [255, 127, 80],
|
|
208
|
-
cornflowerblue: [100, 149, 237],
|
|
209
|
-
cornsilk: [255, 248, 220],
|
|
210
|
-
crimson: [220, 20, 60],
|
|
211
|
-
cyan: [0, 255, 255],
|
|
212
|
-
darkblue: [0, 0, 139],
|
|
213
|
-
darkcyan: [0, 139, 139],
|
|
214
|
-
darkgoldenrod: [184, 134, 11],
|
|
215
|
-
darkgray: [169, 169, 169],
|
|
216
|
-
darkgreen: [0, 100, 0],
|
|
217
|
-
darkgrey: [169, 169, 169],
|
|
218
|
-
darkkhaki: [189, 183, 107],
|
|
219
|
-
darkmagenta: [139, 0, 139],
|
|
220
|
-
darkolivegreen: [85, 107, 47],
|
|
221
|
-
darkorange: [255, 140, 0],
|
|
222
|
-
darkorchid: [153, 50, 204],
|
|
223
|
-
darkred: [139, 0, 0],
|
|
224
|
-
darksalmon: [233, 150, 122],
|
|
225
|
-
darkseagreen: [143, 188, 143],
|
|
226
|
-
darkslateblue: [72, 61, 139],
|
|
227
|
-
darkslategray: [47, 79, 79],
|
|
228
|
-
darkslategrey: [47, 79, 79],
|
|
229
|
-
darkturquoise: [0, 206, 209],
|
|
230
|
-
darkviolet: [148, 0, 211],
|
|
231
|
-
deeppink: [255, 20, 147],
|
|
232
|
-
deepskyblue: [0, 191, 255],
|
|
233
|
-
dimgray: [105, 105, 105],
|
|
234
|
-
dimgrey: [105, 105, 105],
|
|
235
|
-
dodgerblue: [30, 144, 255],
|
|
236
|
-
firebrick: [178, 34, 34],
|
|
237
|
-
floralwhite: [255, 250, 240],
|
|
238
|
-
forestgreen: [34, 139, 34],
|
|
239
|
-
fuchsia: [255, 0, 255],
|
|
240
|
-
gainsboro: [220, 220, 220],
|
|
241
|
-
ghostwhite: [248, 248, 255],
|
|
242
|
-
gold: [255, 215, 0],
|
|
243
|
-
goldenrod: [218, 165, 32],
|
|
244
|
-
gray: [128, 128, 128],
|
|
245
|
-
green: [0, 128, 0],
|
|
246
|
-
greenyellow: [173, 255, 47],
|
|
247
|
-
grey: [128, 128, 128],
|
|
248
|
-
honeydew: [240, 255, 240],
|
|
249
|
-
hotpink: [255, 105, 180],
|
|
250
|
-
indianred: [205, 92, 92],
|
|
251
|
-
indigo: [75, 0, 130],
|
|
252
|
-
ivory: [255, 255, 240],
|
|
253
|
-
khaki: [240, 230, 140],
|
|
254
|
-
lavender: [230, 230, 250],
|
|
255
|
-
lavenderblush: [255, 240, 245],
|
|
256
|
-
lawngreen: [124, 252, 0],
|
|
257
|
-
lemonchiffon: [255, 250, 205],
|
|
258
|
-
lightblue: [173, 216, 230],
|
|
259
|
-
lightcoral: [240, 128, 128],
|
|
260
|
-
lightcyan: [224, 255, 255],
|
|
261
|
-
lightgoldenrodyellow: [250, 250, 210],
|
|
262
|
-
lightgray: [211, 211, 211],
|
|
263
|
-
lightgreen: [144, 238, 144],
|
|
264
|
-
lightgrey: [211, 211, 211],
|
|
265
|
-
lightpink: [255, 182, 193],
|
|
266
|
-
lightsalmon: [255, 160, 122],
|
|
267
|
-
lightseagreen: [32, 178, 170],
|
|
268
|
-
lightskyblue: [135, 206, 250],
|
|
269
|
-
lightslategray: [119, 136, 153],
|
|
270
|
-
lightslategrey: [119, 136, 153],
|
|
271
|
-
lightsteelblue: [176, 196, 222],
|
|
272
|
-
lightyellow: [255, 255, 224],
|
|
273
|
-
lime: [0, 255, 0],
|
|
274
|
-
limegreen: [50, 205, 50],
|
|
275
|
-
linen: [250, 240, 230],
|
|
276
|
-
magenta: [255, 0, 255],
|
|
277
|
-
maroon: [128, 0, 0],
|
|
278
|
-
mediumaquamarine: [102, 205, 170],
|
|
279
|
-
mediumblue: [0, 0, 205],
|
|
280
|
-
mediumorchid: [186, 85, 211],
|
|
281
|
-
mediumpurple: [147, 112, 219],
|
|
282
|
-
mediumseagreen: [60, 179, 113],
|
|
283
|
-
mediumslateblue: [123, 104, 238],
|
|
284
|
-
mediumspringgreen: [0, 250, 154],
|
|
285
|
-
mediumturquoise: [72, 209, 204],
|
|
286
|
-
mediumvioletred: [199, 21, 133],
|
|
287
|
-
midnightblue: [25, 25, 112],
|
|
288
|
-
mintcream: [245, 255, 250],
|
|
289
|
-
mistyrose: [255, 228, 225],
|
|
290
|
-
moccasin: [255, 228, 181],
|
|
291
|
-
navajowhite: [255, 222, 173],
|
|
292
|
-
navy: [0, 0, 128],
|
|
293
|
-
oldlace: [253, 245, 230],
|
|
294
|
-
olive: [128, 128, 0],
|
|
295
|
-
olivedrab: [107, 142, 35],
|
|
296
|
-
orange: [255, 165, 0],
|
|
297
|
-
orangered: [255, 69, 0],
|
|
298
|
-
orchid: [218, 112, 214],
|
|
299
|
-
palegoldenrod: [238, 232, 170],
|
|
300
|
-
palegreen: [152, 251, 152],
|
|
301
|
-
paleturquoise: [175, 238, 238],
|
|
302
|
-
palevioletred: [219, 112, 147],
|
|
303
|
-
papayawhip: [255, 239, 213],
|
|
304
|
-
peachpuff: [255, 218, 185],
|
|
305
|
-
peru: [205, 133, 63],
|
|
306
|
-
pink: [255, 192, 203],
|
|
307
|
-
plum: [221, 160, 221],
|
|
308
|
-
powderblue: [176, 224, 230],
|
|
309
|
-
purple: [128, 0, 128],
|
|
310
|
-
rebeccapurple: [102, 51, 153],
|
|
311
|
-
red: [255, 0, 0],
|
|
312
|
-
rosybrown: [188, 143, 143],
|
|
313
|
-
royalblue: [65, 105, 225],
|
|
314
|
-
saddlebrown: [139, 69, 19],
|
|
315
|
-
salmon: [250, 128, 114],
|
|
316
|
-
sandybrown: [244, 164, 96],
|
|
317
|
-
seagreen: [46, 139, 87],
|
|
318
|
-
seashell: [255, 245, 238],
|
|
319
|
-
sienna: [160, 82, 45],
|
|
320
|
-
silver: [192, 192, 192],
|
|
321
|
-
skyblue: [135, 206, 235],
|
|
322
|
-
slateblue: [106, 90, 205],
|
|
323
|
-
slategray: [112, 128, 144],
|
|
324
|
-
slategrey: [112, 128, 144],
|
|
325
|
-
snow: [255, 250, 250],
|
|
326
|
-
springgreen: [0, 255, 127],
|
|
327
|
-
steelblue: [70, 130, 180],
|
|
328
|
-
tan: [210, 180, 140],
|
|
329
|
-
teal: [0, 128, 128],
|
|
330
|
-
thistle: [216, 191, 216],
|
|
331
|
-
tomato: [255, 99, 71],
|
|
332
|
-
turquoise: [64, 224, 208],
|
|
333
|
-
violet: [238, 130, 238],
|
|
334
|
-
wheat: [245, 222, 179],
|
|
335
|
-
white: [255, 255, 255],
|
|
336
|
-
whitesmoke: [245, 245, 245],
|
|
337
|
-
yellow: [255, 255, 0],
|
|
338
|
-
yellowgreen: [154, 205, 50]
|
|
339
|
-
};
|
|
340
|
-
class Color {
|
|
341
|
-
constructor(r, g, b, a) {
|
|
342
|
-
__publicField(this, "_r");
|
|
343
|
-
__publicField(this, "_g");
|
|
344
|
-
__publicField(this, "_b");
|
|
345
|
-
__publicField(this, "_alpha");
|
|
346
|
-
this._validateColorChannel(r);
|
|
347
|
-
this._validateColorChannel(g);
|
|
348
|
-
this._validateColorChannel(b);
|
|
349
|
-
this._r = r;
|
|
350
|
-
this._g = g;
|
|
351
|
-
this._b = b;
|
|
352
|
-
this._alpha = MathUtil.clamp(a || 1, 0, 1);
|
|
353
|
-
}
|
|
354
|
-
_validateColorChannel(channel) {
|
|
355
|
-
if (channel < 0 || channel > 255) {
|
|
356
|
-
throw new Error("Color channel must be between 0 and 255.");
|
|
357
|
-
}
|
|
358
|
-
}
|
|
359
|
-
toString() {
|
|
360
|
-
return `rgba(${this._r}, ${this._g}, ${this._b}, ${this._alpha})`;
|
|
361
|
-
}
|
|
362
|
-
toJson() {
|
|
363
|
-
return { r: this._r, g: this._g, b: this._b, a: this._alpha };
|
|
364
|
-
}
|
|
365
|
-
get rgba() {
|
|
366
|
-
return `rgba(${this._r}, ${this._g}, ${this._b}, ${this._alpha})`;
|
|
367
|
-
}
|
|
368
|
-
get hex() {
|
|
369
|
-
return Color.rgb2hex(this._r, this._g, this._b, this._alpha);
|
|
370
|
-
}
|
|
371
|
-
setAlpha(a) {
|
|
372
|
-
this._alpha = MathUtil.clamp(a, 0, 1);
|
|
373
|
-
return this;
|
|
374
|
-
}
|
|
375
|
-
// 设置颜色的RGB值
|
|
376
|
-
setRgb(r, g, b) {
|
|
377
|
-
this._validateColorChannel(r);
|
|
378
|
-
this._validateColorChannel(g);
|
|
379
|
-
this._validateColorChannel(b);
|
|
380
|
-
this._r = r;
|
|
381
|
-
this._g = g;
|
|
382
|
-
this._b = b;
|
|
383
|
-
return this;
|
|
384
|
-
}
|
|
385
|
-
/**
|
|
386
|
-
* 从RGBA字符串创建Color对象
|
|
387
|
-
*
|
|
388
|
-
* @param rgbaValue RGBA颜色值字符串,格式为"rgba(r,g,b,a)"或"rgb(r,g,b)"
|
|
389
|
-
* @returns 返回Color对象
|
|
390
|
-
* @throws 如果rgbaValue不是有效的RGBA颜色值,则抛出错误
|
|
391
|
-
*/
|
|
392
|
-
static fromRgba(rgbaValue) {
|
|
393
|
-
const rgbaMatch = rgbaValue.match(/^rgba?\s*\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(,\s*([\d.]+))?\s*\)$/);
|
|
394
|
-
if (!rgbaMatch) throw new Error("Invalid RGBA color value");
|
|
395
|
-
const r = parseInt(rgbaMatch[1], 10);
|
|
396
|
-
const g = parseInt(rgbaMatch[2], 10);
|
|
397
|
-
const b = parseInt(rgbaMatch[3], 10);
|
|
398
|
-
const a = rgbaMatch[5] ? parseFloat(rgbaMatch[5]) : 1;
|
|
399
|
-
return new Color(r, g, b, a);
|
|
400
|
-
}
|
|
401
|
-
/**
|
|
402
|
-
* 将十六进制颜色值转换为颜色对象
|
|
403
|
-
*
|
|
404
|
-
* @param hexValue 十六进制颜色值,可带或不带#前缀,支持3位和6位表示
|
|
405
|
-
* @returns 返回颜色对象
|
|
406
|
-
*/
|
|
407
|
-
static fromHex(hexValue, a = 1) {
|
|
408
|
-
const rgxShort = /^#?([a-f\d])([a-f\d])([a-f\d])$/i;
|
|
409
|
-
const hex = hexValue.replace(rgxShort, (m, r2, g2, b2) => r2 + r2 + g2 + g2 + b2 + b2);
|
|
410
|
-
const rgx = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i;
|
|
411
|
-
const rgb = rgx.exec(hex);
|
|
412
|
-
if (!rgb) {
|
|
413
|
-
throw new Error("Invalid HEX color value");
|
|
414
|
-
}
|
|
415
|
-
const r = parseInt(rgb[1], 16);
|
|
416
|
-
const g = parseInt(rgb[2], 16);
|
|
417
|
-
const b = parseInt(rgb[3], 16);
|
|
418
|
-
return new Color(r, g, b, a);
|
|
419
|
-
}
|
|
237
|
+
guid() {
|
|
238
|
+
const S4 = function() {
|
|
239
|
+
return ((1 + Math.random()) * 65536 | 0).toString(16).substring(1);
|
|
240
|
+
};
|
|
241
|
+
return S4() + S4() + S4() + S4() + S4() + S4() + S4() + S4();
|
|
242
|
+
},
|
|
420
243
|
/**
|
|
421
|
-
*
|
|
244
|
+
* 将参数进行解码并返回解码后的字符串
|
|
422
245
|
*
|
|
423
|
-
* @param
|
|
424
|
-
* @returns
|
|
246
|
+
* @param args 参数
|
|
247
|
+
* @returns 解码后的字符串
|
|
425
248
|
*/
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
if (
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
if (
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
if (t < 1 / 2) return q;
|
|
440
|
-
if (t < 2 / 3) return p + (q - p) * (2 / 3 - t) * 6;
|
|
441
|
-
return p;
|
|
442
|
-
}
|
|
443
|
-
let r, g, b;
|
|
444
|
-
if (s === 0) {
|
|
445
|
-
r = g = b = l;
|
|
249
|
+
decodeDict(...args) {
|
|
250
|
+
let res = "";
|
|
251
|
+
if (args.length > 1) {
|
|
252
|
+
const items = args.slice(1, args.length % 2 === 0 ? args.length - 1 : args.length);
|
|
253
|
+
for (let i = 0; i < items.length; i = i + 2) {
|
|
254
|
+
const item = items[i];
|
|
255
|
+
if (args[0] === item) {
|
|
256
|
+
res = items[i + 1];
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
if (!res && args.length % 2 === 0) {
|
|
260
|
+
res = args[args.length - 1];
|
|
261
|
+
}
|
|
446
262
|
} else {
|
|
447
|
-
|
|
448
|
-
const p = 2 * l - q;
|
|
449
|
-
r = hue2rgb(p, q, h + 1 / 3);
|
|
450
|
-
g = hue2rgb(p, q, h);
|
|
451
|
-
b = hue2rgb(p, q, h - 1 / 3);
|
|
452
|
-
}
|
|
453
|
-
return new Color(Math.round(r * 255), Math.round(g * 255), Math.round(b * 255), a);
|
|
454
|
-
}
|
|
455
|
-
static fromName(str) {
|
|
456
|
-
const rgba = ColorName[str];
|
|
457
|
-
if (!rgba) {
|
|
458
|
-
throw new Error(`Invalid color name: ${str}`);
|
|
263
|
+
res = args[0];
|
|
459
264
|
}
|
|
460
|
-
return
|
|
461
|
-
}
|
|
265
|
+
return res;
|
|
266
|
+
},
|
|
462
267
|
/**
|
|
463
|
-
*
|
|
268
|
+
* 将一个或多个对象的所有可枚举属性复制到目标对象。
|
|
464
269
|
*
|
|
465
|
-
* @param
|
|
466
|
-
* @
|
|
467
|
-
* @
|
|
270
|
+
* @param dest 目标对象,用于接收复制的属性。
|
|
271
|
+
* @param args 一个或多个源对象,用于提供要复制的属性。
|
|
272
|
+
* @returns 返回目标对象,包含所有复制的属性。
|
|
468
273
|
*/
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
} else if (Object.keys(ColorName).map((key) => key.toString()).includes(str)) {
|
|
477
|
-
return this.fromName(str);
|
|
478
|
-
} else {
|
|
479
|
-
throw new Error("Invalid color value");
|
|
274
|
+
extend(dest, ...args) {
|
|
275
|
+
let i, j, len, src;
|
|
276
|
+
for (j = 0, len = args.length; j < len; j++) {
|
|
277
|
+
src = args[j];
|
|
278
|
+
for (i in src) {
|
|
279
|
+
dest[i] = src[i];
|
|
280
|
+
}
|
|
480
281
|
}
|
|
481
|
-
|
|
282
|
+
return dest;
|
|
283
|
+
},
|
|
482
284
|
/**
|
|
483
|
-
*
|
|
285
|
+
* 将扁平化数组转换为树形结构数组
|
|
484
286
|
*
|
|
485
|
-
* @param
|
|
486
|
-
* @param
|
|
487
|
-
* @param
|
|
488
|
-
* @param
|
|
489
|
-
* @returns
|
|
287
|
+
* @param data 扁平化数组
|
|
288
|
+
* @param idPropertyName 数据中标识id的字段名,默认为'id'
|
|
289
|
+
* @param parentIdPropertyName 数据中标识父节点id的字段名,默认为'parentId'
|
|
290
|
+
* @param childrenPropertyName 树形结构中标识子节点的字段名,默认为'children'
|
|
291
|
+
* @returns 转换后的树形结构数组
|
|
490
292
|
*/
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
const
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
static isRgb(a) {
|
|
503
|
-
return /^rgba?\s*\(\s*\d+\s*,\s*\d+\s*,\s*\d+\s*(,\s*[\d.]+)?\s*\)$/.test(a);
|
|
504
|
-
}
|
|
505
|
-
static isHsl(a) {
|
|
506
|
-
return /^(hsl|hsla)\(\d+,\s*[\d.]+%,\s*[\d.]+%(,\s*[\d.]+)?\)$/.test(a);
|
|
507
|
-
}
|
|
508
|
-
static isColor(a) {
|
|
509
|
-
return this.isHex(a) || this.isRgb(a) || this.isHsl(a);
|
|
510
|
-
}
|
|
511
|
-
static random() {
|
|
512
|
-
let r = Math.floor(Math.random() * 256);
|
|
513
|
-
let g = Math.floor(Math.random() * 256);
|
|
514
|
-
let b = Math.floor(Math.random() * 256);
|
|
515
|
-
let a = Math.random();
|
|
516
|
-
return new Color(r, g, b, a);
|
|
517
|
-
}
|
|
518
|
-
}
|
|
519
|
-
class CanvasDrawer {
|
|
520
|
-
constructor(el) {
|
|
521
|
-
__publicField(this, "context", null);
|
|
522
|
-
if (typeof el === "string") {
|
|
523
|
-
el = document.querySelector("#" + el);
|
|
524
|
-
if (!el) {
|
|
525
|
-
throw new Error("Element not found");
|
|
293
|
+
convertToTree2(data, idPropertyName = "id", parentIdPropertyName = "parentId", childrenPropertyName = "children") {
|
|
294
|
+
const result = [];
|
|
295
|
+
function buildChildren(item) {
|
|
296
|
+
const children = data.filter((item2) => item2[parentIdPropertyName] === item[idPropertyName]).map((child) => {
|
|
297
|
+
if (!result.some((r) => r[idPropertyName] === child[idPropertyName])) {
|
|
298
|
+
buildChildren(child);
|
|
299
|
+
}
|
|
300
|
+
return child;
|
|
301
|
+
});
|
|
302
|
+
if (children.length > 0) {
|
|
303
|
+
item[childrenPropertyName] = children;
|
|
526
304
|
}
|
|
527
305
|
}
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
} else {
|
|
533
|
-
throw new Error("getContext is not available on this element");
|
|
306
|
+
data.forEach((item) => {
|
|
307
|
+
if (!data.some((other) => other[parentIdPropertyName] === item[idPropertyName])) {
|
|
308
|
+
buildChildren(item);
|
|
309
|
+
result.push(item);
|
|
534
310
|
}
|
|
535
|
-
}
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
}
|
|
311
|
+
});
|
|
312
|
+
return result;
|
|
313
|
+
},
|
|
539
314
|
/**
|
|
540
|
-
*
|
|
315
|
+
* 异步加载script
|
|
541
316
|
*
|
|
542
|
-
* @param
|
|
543
|
-
* @param end 终止坐标点
|
|
544
|
-
* @param options 绘制选项,包括线条宽度和颜色
|
|
545
|
-
* @throws 当画布上下文不存在时抛出错误
|
|
317
|
+
* @param {*} url
|
|
546
318
|
*/
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
* @param startAngle 起始角度(度)
|
|
567
|
-
* @param endAngle 结束角度(度)
|
|
568
|
-
* @param anticlockwise 是否逆时针绘制
|
|
569
|
-
* @param isFill 是否填充
|
|
570
|
-
* @param bgColor 背景颜色
|
|
571
|
-
* @throws 当Canvas context为null或undefined时抛出错误
|
|
572
|
-
*/
|
|
573
|
-
drawArc({ x, y }, radius, startAngle, endAngle, anticlockwise, isFill, bgColor) {
|
|
574
|
-
if (!this.context) {
|
|
575
|
-
throw new Error("Canvas context is null or undefined");
|
|
576
|
-
}
|
|
577
|
-
if (isFill) {
|
|
578
|
-
this.context.fillStyle = bgColor;
|
|
579
|
-
this.context.beginPath();
|
|
580
|
-
this.context.arc(x, y, radius, MathUtil.deg2Rad(startAngle), MathUtil.deg2Rad(endAngle), anticlockwise);
|
|
581
|
-
this.context.fill();
|
|
582
|
-
} else {
|
|
583
|
-
this.context.strokeStyle = bgColor;
|
|
584
|
-
this.context.beginPath();
|
|
585
|
-
this.context.arc(x, y, radius, MathUtil.deg2Rad(startAngle), MathUtil.deg2Rad(endAngle), anticlockwise);
|
|
586
|
-
this.context.stroke();
|
|
587
|
-
}
|
|
588
|
-
}
|
|
589
|
-
drawImage(src, { x, y }) {
|
|
590
|
-
const img = new Image();
|
|
591
|
-
img.src = src;
|
|
592
|
-
img.onload = () => {
|
|
593
|
-
const width = img.width;
|
|
594
|
-
const height = img.height;
|
|
595
|
-
if (!this.context) {
|
|
596
|
-
throw new Error("Canvas context is null");
|
|
597
|
-
}
|
|
598
|
-
this.context.drawImage(img, x, y, -width / 2, -height / 2);
|
|
599
|
-
};
|
|
600
|
-
}
|
|
601
|
-
static createCanvas(width = 1, height = 1) {
|
|
602
|
-
const canvas = document.createElement("canvas");
|
|
603
|
-
if (width) {
|
|
604
|
-
canvas.width = width;
|
|
605
|
-
}
|
|
606
|
-
if (height) {
|
|
607
|
-
canvas.height = height;
|
|
608
|
-
}
|
|
609
|
-
return canvas;
|
|
610
|
-
}
|
|
611
|
-
}
|
|
612
|
-
class EventDispatcher {
|
|
613
|
-
constructor() {
|
|
614
|
-
__publicField(this, "_listeners", {});
|
|
615
|
-
__publicField(this, "_mutex", {});
|
|
616
|
-
__publicField(this, "_context");
|
|
617
|
-
}
|
|
618
|
-
addEventListener(type, listener, context, mutexStatus) {
|
|
619
|
-
this._context = context;
|
|
620
|
-
const mutex = this._mutex;
|
|
621
|
-
const listeners = this._listeners;
|
|
622
|
-
if (listeners[type] === void 0) {
|
|
623
|
-
listeners[type] = [];
|
|
624
|
-
}
|
|
625
|
-
if (listeners[type].indexOf(listener) === -1) {
|
|
626
|
-
if (mutexStatus) {
|
|
627
|
-
mutex[type] = listener;
|
|
628
|
-
}
|
|
629
|
-
listeners[type].push(listener);
|
|
630
|
-
}
|
|
631
|
-
return this;
|
|
632
|
-
}
|
|
633
|
-
hasEventListener(type, listener) {
|
|
634
|
-
if (this._listeners === null || this._listeners === void 0) return false;
|
|
635
|
-
const listeners = this._listeners;
|
|
636
|
-
return listeners[type] !== void 0 && listeners[type].indexOf(listener) !== -1;
|
|
637
|
-
}
|
|
638
|
-
removeEventListener(type, listener) {
|
|
639
|
-
if (this._listeners === void 0) return;
|
|
640
|
-
const listeners = this._listeners;
|
|
641
|
-
const listenerArray = listeners[type];
|
|
642
|
-
if (this._mutex[type] === listener) {
|
|
643
|
-
this._mutex[type] = null;
|
|
644
|
-
}
|
|
645
|
-
if (listenerArray !== void 0) {
|
|
646
|
-
const index = listenerArray.map((d) => d.toString()).indexOf(listener.toString());
|
|
647
|
-
if (index !== -1) {
|
|
648
|
-
listenerArray.splice(index, 1);
|
|
649
|
-
}
|
|
650
|
-
}
|
|
651
|
-
}
|
|
652
|
-
dispatchEvent(event) {
|
|
653
|
-
if (this._listeners === void 0) return;
|
|
654
|
-
const listeners = this._listeners;
|
|
655
|
-
const listenerArray = listeners[event.type];
|
|
656
|
-
if (listenerArray !== void 0) {
|
|
657
|
-
event.target = this;
|
|
658
|
-
const array = listenerArray.slice(0);
|
|
659
|
-
if (this._mutex[event.type] !== void 0) {
|
|
660
|
-
const find = array.find((item) => item === this._mutex[event.type]);
|
|
661
|
-
if (find) {
|
|
662
|
-
find.call(this._context || this, event);
|
|
663
|
-
return;
|
|
664
|
-
}
|
|
665
|
-
}
|
|
666
|
-
for (let i = 0, l = array.length; i < l; i++) {
|
|
667
|
-
const item = array[i];
|
|
668
|
-
if (typeof item === "function") {
|
|
669
|
-
item.call(this._context || this, event);
|
|
319
|
+
asyncLoadScript(url) {
|
|
320
|
+
return new Promise((resolve, reject) => {
|
|
321
|
+
try {
|
|
322
|
+
const oscript = document.createElement("script");
|
|
323
|
+
oscript.type = "text/javascript";
|
|
324
|
+
oscript.src = url;
|
|
325
|
+
if ("readyState" in oscript) {
|
|
326
|
+
oscript.onreadystatechange = function() {
|
|
327
|
+
if (oscript.readyState === "complete" || oscript.readyState === "loaded") {
|
|
328
|
+
resolve(oscript);
|
|
329
|
+
}
|
|
330
|
+
};
|
|
331
|
+
} else {
|
|
332
|
+
oscript.onload = function() {
|
|
333
|
+
resolve(oscript);
|
|
334
|
+
};
|
|
335
|
+
oscript.onerror = function() {
|
|
336
|
+
reject(new Error("Script failed to load for URL: " + url));
|
|
337
|
+
};
|
|
670
338
|
}
|
|
339
|
+
document.body.appendChild(oscript);
|
|
340
|
+
} catch (error) {
|
|
341
|
+
reject(error);
|
|
671
342
|
}
|
|
672
|
-
}
|
|
673
|
-
}
|
|
674
|
-
removeAllListener() {
|
|
675
|
-
this._mutex = {};
|
|
676
|
-
for (const key in this._listeners) {
|
|
677
|
-
this._listeners[key] = [];
|
|
678
|
-
}
|
|
679
|
-
}
|
|
680
|
-
}
|
|
681
|
-
const Util = {
|
|
343
|
+
});
|
|
344
|
+
},
|
|
682
345
|
/**
|
|
683
|
-
*
|
|
346
|
+
* 加载样式文件
|
|
684
347
|
*
|
|
685
|
-
* @param
|
|
686
|
-
* @returns
|
|
348
|
+
* @param urls 样式文件URL数组
|
|
349
|
+
* @returns 无返回值
|
|
687
350
|
*/
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
351
|
+
loadStyle(urls) {
|
|
352
|
+
urls.forEach((url) => {
|
|
353
|
+
const css = document.createElement("link");
|
|
354
|
+
css.href = url;
|
|
355
|
+
css.rel = "stylesheet";
|
|
356
|
+
css.type = "text/css";
|
|
357
|
+
css.onerror = function() {
|
|
358
|
+
console.error(`Style loading failed for URL: ${url}`);
|
|
359
|
+
};
|
|
360
|
+
document.head.appendChild(css);
|
|
361
|
+
});
|
|
696
362
|
},
|
|
697
363
|
/**
|
|
698
|
-
*
|
|
364
|
+
* 将模板字符串中的占位符替换为给定对象中的值
|
|
699
365
|
*
|
|
700
|
-
* @param
|
|
701
|
-
* @
|
|
366
|
+
* @param str 模板字符串
|
|
367
|
+
* @param data 包含替换值的对象
|
|
368
|
+
* @returns 替换后的字符串
|
|
369
|
+
* @throws 当对象中没有找到与占位符对应的值时,抛出错误
|
|
702
370
|
*/
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
371
|
+
template(str, data) {
|
|
372
|
+
const templateRe = /\{ *([\w_-]+) *\}/g;
|
|
373
|
+
return str.replace(templateRe, (match, key) => {
|
|
374
|
+
const value = data[key];
|
|
375
|
+
if (value === void 0) {
|
|
376
|
+
throw new Error(`${ErrorType.JSON_PARSE_ERROR}: ${match}`);
|
|
377
|
+
} else if (typeof value === "function") {
|
|
378
|
+
return value(data);
|
|
379
|
+
} else {
|
|
380
|
+
return value;
|
|
713
381
|
}
|
|
714
|
-
}
|
|
382
|
+
});
|
|
715
383
|
},
|
|
716
384
|
/**
|
|
717
|
-
*
|
|
385
|
+
* 删除对象中所有值为空的属性
|
|
718
386
|
*
|
|
719
|
-
* @param
|
|
720
|
-
* @returns
|
|
387
|
+
* @param data 待处理的对象
|
|
388
|
+
* @returns 返回处理后的对象
|
|
721
389
|
*/
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
390
|
+
deleteEmptyProperty(data) {
|
|
391
|
+
return Object.fromEntries(
|
|
392
|
+
Object.keys(data).filter((d) => !this.isEmpty(data[d])).map((i) => [i, data[i]])
|
|
393
|
+
);
|
|
394
|
+
},
|
|
395
|
+
deepAssign(target, ...sources) {
|
|
396
|
+
if (typeof target !== "object" || target === null) {
|
|
397
|
+
target = {};
|
|
725
398
|
}
|
|
726
|
-
const
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
399
|
+
for (const source of sources) {
|
|
400
|
+
if (typeof source === "object" && source !== null) {
|
|
401
|
+
for (const key in source) {
|
|
402
|
+
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
403
|
+
if (typeof source[key] === "object" && source[key] !== null) {
|
|
404
|
+
if (!target[key]) {
|
|
405
|
+
target[key] = Array.isArray(source[key]) ? [] : {};
|
|
406
|
+
}
|
|
407
|
+
this.deepAssign(target[key], source[key]);
|
|
408
|
+
} else {
|
|
409
|
+
target[key] = source[key];
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
}
|
|
738
414
|
}
|
|
415
|
+
return target;
|
|
739
416
|
},
|
|
740
417
|
/**
|
|
741
|
-
*
|
|
418
|
+
* 复制文本到剪贴板
|
|
742
419
|
*
|
|
743
|
-
* @param
|
|
744
|
-
* @returns
|
|
420
|
+
* @param text 要复制的文本
|
|
421
|
+
* @returns 返回一个Promise,表示复制操作的结果
|
|
745
422
|
*/
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
423
|
+
handleCopyValue(text) {
|
|
424
|
+
if (navigator.clipboard && window.isSecureContext) {
|
|
425
|
+
return navigator.clipboard.writeText(text);
|
|
426
|
+
} else {
|
|
427
|
+
const textArea = document.createElement("textarea");
|
|
428
|
+
textArea.style.position = "fixed";
|
|
429
|
+
textArea.style.top = textArea.style.left = "-100vh";
|
|
430
|
+
textArea.style.opacity = "0";
|
|
431
|
+
textArea.value = text;
|
|
432
|
+
document.body.appendChild(textArea);
|
|
433
|
+
textArea.focus();
|
|
434
|
+
textArea.select();
|
|
435
|
+
return new Promise((resolve, reject) => {
|
|
436
|
+
try {
|
|
437
|
+
document.execCommand("copy");
|
|
438
|
+
resolve();
|
|
439
|
+
} catch (error) {
|
|
440
|
+
reject(new Error("copy failed"));
|
|
441
|
+
} finally {
|
|
442
|
+
textArea.remove();
|
|
443
|
+
}
|
|
444
|
+
});
|
|
445
|
+
}
|
|
446
|
+
},
|
|
447
|
+
isArray(a) {
|
|
448
|
+
return Array.isArray(a);
|
|
449
|
+
},
|
|
450
|
+
isObject(a) {
|
|
451
|
+
return typeof a === "object" && a !== null;
|
|
452
|
+
},
|
|
453
|
+
isNil(a) {
|
|
454
|
+
return a === void 0 || a === "undefined" || a === null || a === "null";
|
|
455
|
+
},
|
|
456
|
+
isNumber(a) {
|
|
457
|
+
return typeof a === "number" && !isNaN(a) || typeof a === "string" && Number.isFinite(+a);
|
|
458
|
+
},
|
|
459
|
+
isInteger(a) {
|
|
460
|
+
return parseInt(a) === a;
|
|
461
|
+
},
|
|
462
|
+
isFunction(obj) {
|
|
463
|
+
if (this.isNil(obj)) {
|
|
464
|
+
return false;
|
|
465
|
+
}
|
|
466
|
+
return typeof obj === "function" || obj.constructor !== null && obj.constructor === Function;
|
|
467
|
+
},
|
|
468
|
+
/**
|
|
469
|
+
* 判断传入参数是否为DOM元素
|
|
470
|
+
*
|
|
471
|
+
* @param a 待判断的参数
|
|
472
|
+
* @returns 返回布尔值,表示是否为DOM元素
|
|
758
473
|
*/
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
return ((1 + Math.random()) * 65536 | 0).toString(16).substring(1);
|
|
762
|
-
};
|
|
763
|
-
return S4() + S4() + S4() + S4() + S4() + S4() + S4() + S4();
|
|
474
|
+
isElement(a) {
|
|
475
|
+
return typeof a === "object" && a.nodeType === 1;
|
|
764
476
|
},
|
|
765
477
|
/**
|
|
766
|
-
*
|
|
478
|
+
* 检查版本
|
|
767
479
|
*
|
|
768
|
-
* @param
|
|
769
|
-
* @
|
|
480
|
+
* @param currentV 当前版本号
|
|
481
|
+
* @param targetV 要求版本号
|
|
482
|
+
* @returns 返回布尔值,表示当前版本是否需要升级到目标版本
|
|
770
483
|
*/
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
res = args[0];
|
|
786
|
-
}
|
|
787
|
-
return res;
|
|
484
|
+
checheVersion(currentV, targetV) {
|
|
485
|
+
var numC = currentV.replace(/[^0-9]/gi, "");
|
|
486
|
+
var numT = targetV.replace(/[^0-9]/gi, "");
|
|
487
|
+
return numC < numT;
|
|
488
|
+
}
|
|
489
|
+
};
|
|
490
|
+
const MathUtil = {
|
|
491
|
+
DEG2RAD: Math.PI / 180,
|
|
492
|
+
RAD2DEG: 180 / Math.PI,
|
|
493
|
+
randInt(low, high) {
|
|
494
|
+
return low + Math.floor(Math.random() * (high - low + 1));
|
|
495
|
+
},
|
|
496
|
+
randFloat(low, high) {
|
|
497
|
+
return low + Math.random() * (high - low);
|
|
788
498
|
},
|
|
789
499
|
/**
|
|
790
|
-
*
|
|
500
|
+
* 角度转弧度
|
|
791
501
|
*
|
|
792
|
-
* @param
|
|
793
|
-
* @
|
|
794
|
-
* @returns 返回目标对象,包含所有复制的属性。
|
|
502
|
+
* @param {*} degrees
|
|
503
|
+
* @returns {*}
|
|
795
504
|
*/
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
for (j = 0, len = args.length; j < len; j++) {
|
|
799
|
-
src = args[j];
|
|
800
|
-
for (i in src) {
|
|
801
|
-
dest[i] = src[i];
|
|
802
|
-
}
|
|
803
|
-
}
|
|
804
|
-
return dest;
|
|
505
|
+
deg2Rad(degrees) {
|
|
506
|
+
return degrees * this.DEG2RAD;
|
|
805
507
|
},
|
|
806
508
|
/**
|
|
807
|
-
*
|
|
509
|
+
* 弧度转角度
|
|
808
510
|
*
|
|
809
|
-
* @param
|
|
810
|
-
* @
|
|
811
|
-
* @param parentIdPropertyName 数据中标识父节点id的字段名,默认为'parentId'
|
|
812
|
-
* @param childrenPropertyName 树形结构中标识子节点的字段名,默认为'children'
|
|
813
|
-
* @returns 转换后的树形结构数组
|
|
511
|
+
* @param {*} radians
|
|
512
|
+
* @returns {*}
|
|
814
513
|
*/
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
buildChildren(child);
|
|
821
|
-
}
|
|
822
|
-
return child;
|
|
823
|
-
});
|
|
824
|
-
if (children.length > 0) {
|
|
825
|
-
item[childrenPropertyName] = children;
|
|
826
|
-
}
|
|
827
|
-
}
|
|
828
|
-
data.forEach((item) => {
|
|
829
|
-
if (!data.some((other) => other[parentIdPropertyName] === item[idPropertyName])) {
|
|
830
|
-
buildChildren(item);
|
|
831
|
-
result.push(item);
|
|
832
|
-
}
|
|
833
|
-
});
|
|
834
|
-
return result;
|
|
514
|
+
rad2Deg(radians) {
|
|
515
|
+
return radians * this.RAD2DEG;
|
|
516
|
+
},
|
|
517
|
+
round(value, n = 2) {
|
|
518
|
+
return Util.isNumber(value) ? Math.round(Number(value) * Math.pow(10, n)) / Math.pow(10, n) : 0;
|
|
835
519
|
},
|
|
836
520
|
/**
|
|
837
|
-
*
|
|
521
|
+
* 将数值限制在指定范围内
|
|
522
|
+
*
|
|
523
|
+
* @param val 需要限制的数值
|
|
524
|
+
* @param min 最小值
|
|
525
|
+
* @param max 最大值
|
|
526
|
+
* @returns 返回限制后的数值
|
|
527
|
+
*/
|
|
528
|
+
clamp(val, min, max) {
|
|
529
|
+
return Math.max(min, Math.min(max, val));
|
|
530
|
+
}
|
|
531
|
+
};
|
|
532
|
+
const ColorName = {
|
|
533
|
+
aliceblue: [240, 248, 255],
|
|
534
|
+
antiquewhite: [250, 235, 215],
|
|
535
|
+
aqua: [0, 255, 255],
|
|
536
|
+
aquamarine: [127, 255, 212],
|
|
537
|
+
azure: [240, 255, 255],
|
|
538
|
+
beige: [245, 245, 220],
|
|
539
|
+
bisque: [255, 228, 196],
|
|
540
|
+
black: [0, 0, 0],
|
|
541
|
+
blanchedalmond: [255, 235, 205],
|
|
542
|
+
blue: [0, 0, 255],
|
|
543
|
+
blueviolet: [138, 43, 226],
|
|
544
|
+
brown: [165, 42, 42],
|
|
545
|
+
burlywood: [222, 184, 135],
|
|
546
|
+
cadetblue: [95, 158, 160],
|
|
547
|
+
chartreuse: [127, 255, 0],
|
|
548
|
+
chocolate: [210, 105, 30],
|
|
549
|
+
coral: [255, 127, 80],
|
|
550
|
+
cornflowerblue: [100, 149, 237],
|
|
551
|
+
cornsilk: [255, 248, 220],
|
|
552
|
+
crimson: [220, 20, 60],
|
|
553
|
+
cyan: [0, 255, 255],
|
|
554
|
+
darkblue: [0, 0, 139],
|
|
555
|
+
darkcyan: [0, 139, 139],
|
|
556
|
+
darkgoldenrod: [184, 134, 11],
|
|
557
|
+
darkgray: [169, 169, 169],
|
|
558
|
+
darkgreen: [0, 100, 0],
|
|
559
|
+
darkgrey: [169, 169, 169],
|
|
560
|
+
darkkhaki: [189, 183, 107],
|
|
561
|
+
darkmagenta: [139, 0, 139],
|
|
562
|
+
darkolivegreen: [85, 107, 47],
|
|
563
|
+
darkorange: [255, 140, 0],
|
|
564
|
+
darkorchid: [153, 50, 204],
|
|
565
|
+
darkred: [139, 0, 0],
|
|
566
|
+
darksalmon: [233, 150, 122],
|
|
567
|
+
darkseagreen: [143, 188, 143],
|
|
568
|
+
darkslateblue: [72, 61, 139],
|
|
569
|
+
darkslategray: [47, 79, 79],
|
|
570
|
+
darkslategrey: [47, 79, 79],
|
|
571
|
+
darkturquoise: [0, 206, 209],
|
|
572
|
+
darkviolet: [148, 0, 211],
|
|
573
|
+
deeppink: [255, 20, 147],
|
|
574
|
+
deepskyblue: [0, 191, 255],
|
|
575
|
+
dimgray: [105, 105, 105],
|
|
576
|
+
dimgrey: [105, 105, 105],
|
|
577
|
+
dodgerblue: [30, 144, 255],
|
|
578
|
+
firebrick: [178, 34, 34],
|
|
579
|
+
floralwhite: [255, 250, 240],
|
|
580
|
+
forestgreen: [34, 139, 34],
|
|
581
|
+
fuchsia: [255, 0, 255],
|
|
582
|
+
gainsboro: [220, 220, 220],
|
|
583
|
+
ghostwhite: [248, 248, 255],
|
|
584
|
+
gold: [255, 215, 0],
|
|
585
|
+
goldenrod: [218, 165, 32],
|
|
586
|
+
gray: [128, 128, 128],
|
|
587
|
+
green: [0, 128, 0],
|
|
588
|
+
greenyellow: [173, 255, 47],
|
|
589
|
+
grey: [128, 128, 128],
|
|
590
|
+
honeydew: [240, 255, 240],
|
|
591
|
+
hotpink: [255, 105, 180],
|
|
592
|
+
indianred: [205, 92, 92],
|
|
593
|
+
indigo: [75, 0, 130],
|
|
594
|
+
ivory: [255, 255, 240],
|
|
595
|
+
khaki: [240, 230, 140],
|
|
596
|
+
lavender: [230, 230, 250],
|
|
597
|
+
lavenderblush: [255, 240, 245],
|
|
598
|
+
lawngreen: [124, 252, 0],
|
|
599
|
+
lemonchiffon: [255, 250, 205],
|
|
600
|
+
lightblue: [173, 216, 230],
|
|
601
|
+
lightcoral: [240, 128, 128],
|
|
602
|
+
lightcyan: [224, 255, 255],
|
|
603
|
+
lightgoldenrodyellow: [250, 250, 210],
|
|
604
|
+
lightgray: [211, 211, 211],
|
|
605
|
+
lightgreen: [144, 238, 144],
|
|
606
|
+
lightgrey: [211, 211, 211],
|
|
607
|
+
lightpink: [255, 182, 193],
|
|
608
|
+
lightsalmon: [255, 160, 122],
|
|
609
|
+
lightseagreen: [32, 178, 170],
|
|
610
|
+
lightskyblue: [135, 206, 250],
|
|
611
|
+
lightslategray: [119, 136, 153],
|
|
612
|
+
lightslategrey: [119, 136, 153],
|
|
613
|
+
lightsteelblue: [176, 196, 222],
|
|
614
|
+
lightyellow: [255, 255, 224],
|
|
615
|
+
lime: [0, 255, 0],
|
|
616
|
+
limegreen: [50, 205, 50],
|
|
617
|
+
linen: [250, 240, 230],
|
|
618
|
+
magenta: [255, 0, 255],
|
|
619
|
+
maroon: [128, 0, 0],
|
|
620
|
+
mediumaquamarine: [102, 205, 170],
|
|
621
|
+
mediumblue: [0, 0, 205],
|
|
622
|
+
mediumorchid: [186, 85, 211],
|
|
623
|
+
mediumpurple: [147, 112, 219],
|
|
624
|
+
mediumseagreen: [60, 179, 113],
|
|
625
|
+
mediumslateblue: [123, 104, 238],
|
|
626
|
+
mediumspringgreen: [0, 250, 154],
|
|
627
|
+
mediumturquoise: [72, 209, 204],
|
|
628
|
+
mediumvioletred: [199, 21, 133],
|
|
629
|
+
midnightblue: [25, 25, 112],
|
|
630
|
+
mintcream: [245, 255, 250],
|
|
631
|
+
mistyrose: [255, 228, 225],
|
|
632
|
+
moccasin: [255, 228, 181],
|
|
633
|
+
navajowhite: [255, 222, 173],
|
|
634
|
+
navy: [0, 0, 128],
|
|
635
|
+
oldlace: [253, 245, 230],
|
|
636
|
+
olive: [128, 128, 0],
|
|
637
|
+
olivedrab: [107, 142, 35],
|
|
638
|
+
orange: [255, 165, 0],
|
|
639
|
+
orangered: [255, 69, 0],
|
|
640
|
+
orchid: [218, 112, 214],
|
|
641
|
+
palegoldenrod: [238, 232, 170],
|
|
642
|
+
palegreen: [152, 251, 152],
|
|
643
|
+
paleturquoise: [175, 238, 238],
|
|
644
|
+
palevioletred: [219, 112, 147],
|
|
645
|
+
papayawhip: [255, 239, 213],
|
|
646
|
+
peachpuff: [255, 218, 185],
|
|
647
|
+
peru: [205, 133, 63],
|
|
648
|
+
pink: [255, 192, 203],
|
|
649
|
+
plum: [221, 160, 221],
|
|
650
|
+
powderblue: [176, 224, 230],
|
|
651
|
+
purple: [128, 0, 128],
|
|
652
|
+
rebeccapurple: [102, 51, 153],
|
|
653
|
+
red: [255, 0, 0],
|
|
654
|
+
rosybrown: [188, 143, 143],
|
|
655
|
+
royalblue: [65, 105, 225],
|
|
656
|
+
saddlebrown: [139, 69, 19],
|
|
657
|
+
salmon: [250, 128, 114],
|
|
658
|
+
sandybrown: [244, 164, 96],
|
|
659
|
+
seagreen: [46, 139, 87],
|
|
660
|
+
seashell: [255, 245, 238],
|
|
661
|
+
sienna: [160, 82, 45],
|
|
662
|
+
silver: [192, 192, 192],
|
|
663
|
+
skyblue: [135, 206, 235],
|
|
664
|
+
slateblue: [106, 90, 205],
|
|
665
|
+
slategray: [112, 128, 144],
|
|
666
|
+
slategrey: [112, 128, 144],
|
|
667
|
+
snow: [255, 250, 250],
|
|
668
|
+
springgreen: [0, 255, 127],
|
|
669
|
+
steelblue: [70, 130, 180],
|
|
670
|
+
tan: [210, 180, 140],
|
|
671
|
+
teal: [0, 128, 128],
|
|
672
|
+
thistle: [216, 191, 216],
|
|
673
|
+
tomato: [255, 99, 71],
|
|
674
|
+
turquoise: [64, 224, 208],
|
|
675
|
+
violet: [238, 130, 238],
|
|
676
|
+
wheat: [245, 222, 179],
|
|
677
|
+
white: [255, 255, 255],
|
|
678
|
+
whitesmoke: [245, 245, 245],
|
|
679
|
+
yellow: [255, 255, 0],
|
|
680
|
+
yellowgreen: [154, 205, 50]
|
|
681
|
+
};
|
|
682
|
+
class Color {
|
|
683
|
+
constructor(r, g, b, a) {
|
|
684
|
+
__publicField(this, "_r");
|
|
685
|
+
__publicField(this, "_g");
|
|
686
|
+
__publicField(this, "_b");
|
|
687
|
+
__publicField(this, "_alpha");
|
|
688
|
+
this._validateColorChannel(r);
|
|
689
|
+
this._validateColorChannel(g);
|
|
690
|
+
this._validateColorChannel(b);
|
|
691
|
+
this._r = r;
|
|
692
|
+
this._g = g;
|
|
693
|
+
this._b = b;
|
|
694
|
+
this._alpha = MathUtil.clamp(a || 1, 0, 1);
|
|
695
|
+
}
|
|
696
|
+
_validateColorChannel(channel) {
|
|
697
|
+
if (channel < 0 || channel > 255) {
|
|
698
|
+
throw new Error("Color channel must be between 0 and 255.");
|
|
699
|
+
}
|
|
700
|
+
}
|
|
701
|
+
toString() {
|
|
702
|
+
return `rgba(${this._r}, ${this._g}, ${this._b}, ${this._alpha})`;
|
|
703
|
+
}
|
|
704
|
+
toJson() {
|
|
705
|
+
return { r: this._r, g: this._g, b: this._b, a: this._alpha };
|
|
706
|
+
}
|
|
707
|
+
get rgba() {
|
|
708
|
+
return `rgba(${this._r}, ${this._g}, ${this._b}, ${this._alpha})`;
|
|
709
|
+
}
|
|
710
|
+
get hex() {
|
|
711
|
+
return Color.rgb2hex(this._r, this._g, this._b, this._alpha);
|
|
712
|
+
}
|
|
713
|
+
setAlpha(a) {
|
|
714
|
+
this._alpha = MathUtil.clamp(a, 0, 1);
|
|
715
|
+
return this;
|
|
716
|
+
}
|
|
717
|
+
// 设置颜色的RGB值
|
|
718
|
+
setRgb(r, g, b) {
|
|
719
|
+
this._validateColorChannel(r);
|
|
720
|
+
this._validateColorChannel(g);
|
|
721
|
+
this._validateColorChannel(b);
|
|
722
|
+
this._r = r;
|
|
723
|
+
this._g = g;
|
|
724
|
+
this._b = b;
|
|
725
|
+
return this;
|
|
726
|
+
}
|
|
727
|
+
/**
|
|
728
|
+
* 从RGBA字符串创建Color对象
|
|
838
729
|
*
|
|
839
|
-
* @param
|
|
730
|
+
* @param rgbaValue RGBA颜色值字符串,格式为"rgba(r,g,b,a)"或"rgb(r,g,b)"
|
|
731
|
+
* @returns 返回Color对象
|
|
732
|
+
* @throws 如果rgbaValue不是有效的RGBA颜色值,则抛出错误
|
|
840
733
|
*/
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
resolve(oscript);
|
|
851
|
-
}
|
|
852
|
-
};
|
|
853
|
-
} else {
|
|
854
|
-
oscript.onload = function() {
|
|
855
|
-
resolve(oscript);
|
|
856
|
-
};
|
|
857
|
-
oscript.onerror = function() {
|
|
858
|
-
reject(new Error("Script failed to load for URL: " + url));
|
|
859
|
-
};
|
|
860
|
-
}
|
|
861
|
-
document.body.appendChild(oscript);
|
|
862
|
-
} catch (error) {
|
|
863
|
-
reject(error);
|
|
864
|
-
}
|
|
865
|
-
});
|
|
866
|
-
},
|
|
734
|
+
static fromRgba(rgbaValue) {
|
|
735
|
+
const rgbaMatch = rgbaValue.match(/^rgba?\s*\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(,\s*([\d.]+))?\s*\)$/);
|
|
736
|
+
if (!rgbaMatch) throw new Error("Invalid RGBA color value");
|
|
737
|
+
const r = parseInt(rgbaMatch[1], 10);
|
|
738
|
+
const g = parseInt(rgbaMatch[2], 10);
|
|
739
|
+
const b = parseInt(rgbaMatch[3], 10);
|
|
740
|
+
const a = rgbaMatch[5] ? parseFloat(rgbaMatch[5]) : 1;
|
|
741
|
+
return new Color(r, g, b, a);
|
|
742
|
+
}
|
|
867
743
|
/**
|
|
868
|
-
*
|
|
744
|
+
* 将十六进制颜色值转换为颜色对象
|
|
869
745
|
*
|
|
870
|
-
* @param
|
|
871
|
-
* @returns
|
|
746
|
+
* @param hexValue 十六进制颜色值,可带或不带#前缀,支持3位和6位表示
|
|
747
|
+
* @returns 返回颜色对象
|
|
872
748
|
*/
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
749
|
+
static fromHex(hexValue, a = 1) {
|
|
750
|
+
const rgxShort = /^#?([a-f\d])([a-f\d])([a-f\d])$/i;
|
|
751
|
+
const hex = hexValue.replace(rgxShort, (m, r2, g2, b2) => r2 + r2 + g2 + g2 + b2 + b2);
|
|
752
|
+
const rgx = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i;
|
|
753
|
+
const rgb = rgx.exec(hex);
|
|
754
|
+
if (!rgb) {
|
|
755
|
+
throw new Error("Invalid HEX color value");
|
|
756
|
+
}
|
|
757
|
+
const r = parseInt(rgb[1], 16);
|
|
758
|
+
const g = parseInt(rgb[2], 16);
|
|
759
|
+
const b = parseInt(rgb[3], 16);
|
|
760
|
+
return new Color(r, g, b, a);
|
|
761
|
+
}
|
|
885
762
|
/**
|
|
886
|
-
*
|
|
763
|
+
* 从 HSL 字符串创建颜色对象
|
|
887
764
|
*
|
|
888
|
-
* @param
|
|
889
|
-
* @
|
|
890
|
-
* @returns 替换后的字符串
|
|
891
|
-
* @throws 当对象中没有找到与占位符对应的值时,抛出错误
|
|
765
|
+
* @param hsl HSL 字符串,格式为 hsl(h, s%, l%) 或 hsla(h, s%, l%, a)
|
|
766
|
+
* @returns 返回颜色对象,如果 hsl 字符串无效则返回 null
|
|
892
767
|
*/
|
|
893
|
-
|
|
894
|
-
const
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
768
|
+
static fromHsl(hslValue) {
|
|
769
|
+
const hsl = /hsl\((\d+),\s*([\d.]+)%,\s*([\d.]+)%\)/g.exec(hslValue) || /hsla\((\d+),\s*([\d.]+)%,\s*([\d.]+)%,\s*([\d.]+)\)/g.exec(hslValue);
|
|
770
|
+
if (!hsl) {
|
|
771
|
+
throw new Error("Invalid HSL color value");
|
|
772
|
+
}
|
|
773
|
+
const h = parseInt(hsl[1], 10) / 360;
|
|
774
|
+
const s = parseInt(hsl[2], 10) / 100;
|
|
775
|
+
const l = parseInt(hsl[3], 10) / 100;
|
|
776
|
+
const a = hsl[4] ? parseFloat(hsl[4]) : 1;
|
|
777
|
+
function hue2rgb(p, q, t) {
|
|
778
|
+
if (t < 0) t += 1;
|
|
779
|
+
if (t > 1) t -= 1;
|
|
780
|
+
if (t < 1 / 6) return p + (q - p) * 6 * t;
|
|
781
|
+
if (t < 1 / 2) return q;
|
|
782
|
+
if (t < 2 / 3) return p + (q - p) * (2 / 3 - t) * 6;
|
|
783
|
+
return p;
|
|
784
|
+
}
|
|
785
|
+
let r, g, b;
|
|
786
|
+
if (s === 0) {
|
|
787
|
+
r = g = b = l;
|
|
788
|
+
} else {
|
|
789
|
+
const q = l < 0.5 ? l * (1 + s) : l + s - l * s;
|
|
790
|
+
const p = 2 * l - q;
|
|
791
|
+
r = hue2rgb(p, q, h + 1 / 3);
|
|
792
|
+
g = hue2rgb(p, q, h);
|
|
793
|
+
b = hue2rgb(p, q, h - 1 / 3);
|
|
794
|
+
}
|
|
795
|
+
return new Color(Math.round(r * 255), Math.round(g * 255), Math.round(b * 255), a);
|
|
796
|
+
}
|
|
797
|
+
static fromName(str) {
|
|
798
|
+
const rgba = ColorName[str];
|
|
799
|
+
if (!rgba) {
|
|
800
|
+
throw new Error(`Invalid color name: ${str}`);
|
|
801
|
+
}
|
|
802
|
+
return new Color(rgba[0], rgba[1], rgba[2], rgba.length > 3 ? rgba[3] : 1);
|
|
803
|
+
}
|
|
906
804
|
/**
|
|
907
|
-
*
|
|
805
|
+
* 从字符串中创建颜色对象
|
|
908
806
|
*
|
|
909
|
-
* @param
|
|
910
|
-
* @returns
|
|
807
|
+
* @param str 字符串类型的颜色值,支持rgba、hex、hsl格式
|
|
808
|
+
* @returns 返回创建的颜色对象
|
|
809
|
+
* @throws 当颜色值无效时,抛出错误
|
|
911
810
|
*/
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
)
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
for (const key in source) {
|
|
924
|
-
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
925
|
-
if (typeof source[key] === "object" && source[key] !== null) {
|
|
926
|
-
if (!target[key]) {
|
|
927
|
-
target[key] = Array.isArray(source[key]) ? [] : {};
|
|
928
|
-
}
|
|
929
|
-
this.deepAssign(target[key], source[key]);
|
|
930
|
-
} else {
|
|
931
|
-
target[key] = source[key];
|
|
932
|
-
}
|
|
933
|
-
}
|
|
934
|
-
}
|
|
935
|
-
}
|
|
811
|
+
static from(str) {
|
|
812
|
+
if (this.isRgb(str)) {
|
|
813
|
+
return this.fromRgba(str);
|
|
814
|
+
} else if (this.isHex(str)) {
|
|
815
|
+
return this.fromHex(str);
|
|
816
|
+
} else if (this.isHsl(str)) {
|
|
817
|
+
return this.fromHsl(str);
|
|
818
|
+
} else if (Object.keys(ColorName).map((key) => key.toString()).includes(str)) {
|
|
819
|
+
return this.fromName(str);
|
|
820
|
+
} else {
|
|
821
|
+
throw new Error("Invalid color value");
|
|
936
822
|
}
|
|
937
|
-
|
|
938
|
-
},
|
|
823
|
+
}
|
|
939
824
|
/**
|
|
940
|
-
*
|
|
825
|
+
* 将RGB颜色值转换为十六进制颜色值
|
|
941
826
|
*
|
|
942
|
-
* @param
|
|
943
|
-
* @
|
|
827
|
+
* @param r 红色分量值,取值范围0-255
|
|
828
|
+
* @param g 绿色分量值,取值范围0-255
|
|
829
|
+
* @param b 蓝色分量值,取值范围0-255
|
|
830
|
+
* @param a 可选参数,透明度分量值,取值范围0-1
|
|
831
|
+
* @returns 十六进制颜色值,格式为#RRGGBB或#RRGGBBAA
|
|
944
832
|
*/
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
textArea.style.position = "fixed";
|
|
951
|
-
textArea.style.top = textArea.style.left = "-100vh";
|
|
952
|
-
textArea.style.opacity = "0";
|
|
953
|
-
textArea.value = text;
|
|
954
|
-
document.body.appendChild(textArea);
|
|
955
|
-
textArea.focus();
|
|
956
|
-
textArea.select();
|
|
957
|
-
return new Promise((resolve, reject) => {
|
|
958
|
-
try {
|
|
959
|
-
document.execCommand("copy");
|
|
960
|
-
resolve();
|
|
961
|
-
} catch (error) {
|
|
962
|
-
reject(new Error("copy failed"));
|
|
963
|
-
} finally {
|
|
964
|
-
textArea.remove();
|
|
965
|
-
}
|
|
966
|
-
});
|
|
833
|
+
static rgb2hex(r, g, b, a) {
|
|
834
|
+
var hex = "#" + ((1 << 24) + (r << 16) + (g << 8) + b).toString(16).slice(1);
|
|
835
|
+
if (a !== void 0) {
|
|
836
|
+
const alpha = Math.round(a * 255).toString(16).padStart(2, "0");
|
|
837
|
+
return hex + alpha;
|
|
967
838
|
}
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
839
|
+
return hex;
|
|
840
|
+
}
|
|
841
|
+
static isHex(a) {
|
|
842
|
+
return /(^#[0-9A-F]{6}$)|(^#[0-9A-F]{3}$)/i.test(a);
|
|
843
|
+
}
|
|
844
|
+
static isRgb(a) {
|
|
845
|
+
return /^rgba?\s*\(\s*\d+\s*,\s*\d+\s*,\s*\d+\s*(,\s*[\d.]+)?\s*\)$/.test(a);
|
|
846
|
+
}
|
|
847
|
+
static isHsl(a) {
|
|
848
|
+
return /^(hsl|hsla)\(\d+,\s*[\d.]+%,\s*[\d.]+%(,\s*[\d.]+)?\)$/.test(a);
|
|
849
|
+
}
|
|
850
|
+
static isColor(a) {
|
|
851
|
+
return this.isHex(a) || this.isRgb(a) || this.isHsl(a);
|
|
852
|
+
}
|
|
853
|
+
static random() {
|
|
854
|
+
let r = Math.floor(Math.random() * 256);
|
|
855
|
+
let g = Math.floor(Math.random() * 256);
|
|
856
|
+
let b = Math.floor(Math.random() * 256);
|
|
857
|
+
let a = Math.random();
|
|
858
|
+
return new Color(r, g, b, a);
|
|
859
|
+
}
|
|
860
|
+
}
|
|
861
|
+
class CanvasDrawer {
|
|
862
|
+
constructor(el) {
|
|
863
|
+
__publicField(this, "context", null);
|
|
864
|
+
if (typeof el === "string") {
|
|
865
|
+
el = document.querySelector("#" + el);
|
|
866
|
+
if (!el) {
|
|
867
|
+
throw new Error("Element not found");
|
|
868
|
+
}
|
|
987
869
|
}
|
|
988
|
-
|
|
989
|
-
|
|
870
|
+
if (el instanceof HTMLElement) {
|
|
871
|
+
const canvas = el;
|
|
872
|
+
if (canvas.getContext) {
|
|
873
|
+
this.context = canvas.getContext("2d");
|
|
874
|
+
} else {
|
|
875
|
+
throw new Error("getContext is not available on this element");
|
|
876
|
+
}
|
|
877
|
+
} else {
|
|
878
|
+
throw new Error("Element is not an HTMLElement");
|
|
879
|
+
}
|
|
880
|
+
}
|
|
990
881
|
/**
|
|
991
|
-
*
|
|
882
|
+
* 绘制线条
|
|
992
883
|
*
|
|
993
|
-
* @param
|
|
994
|
-
* @
|
|
884
|
+
* @param start 起始坐标点
|
|
885
|
+
* @param end 终止坐标点
|
|
886
|
+
* @param options 绘制选项,包括线条宽度和颜色
|
|
887
|
+
* @throws 当画布上下文不存在时抛出错误
|
|
995
888
|
*/
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
889
|
+
drawLine({ x: startX, y: startY }, { x: endX, y: endY }, options = {}) {
|
|
890
|
+
if (!this.context) {
|
|
891
|
+
throw new Error("Canvas context is null or undefined");
|
|
892
|
+
}
|
|
893
|
+
this.context.beginPath();
|
|
894
|
+
const width = options.width || 1;
|
|
895
|
+
const color = options.color || "#000";
|
|
896
|
+
this.context.lineWidth = width;
|
|
897
|
+
this.context.strokeStyle = color;
|
|
898
|
+
this.context.moveTo(startX, startY);
|
|
899
|
+
this.context.lineTo(endX, endY);
|
|
900
|
+
this.context.stroke();
|
|
901
|
+
}
|
|
999
902
|
/**
|
|
1000
|
-
*
|
|
903
|
+
* 绘制圆弧
|
|
1001
904
|
*
|
|
1002
|
-
* @param
|
|
1003
|
-
* @param
|
|
1004
|
-
* @
|
|
905
|
+
* @param x 圆心x坐标
|
|
906
|
+
* @param y 圆心y坐标
|
|
907
|
+
* @param radius 半径
|
|
908
|
+
* @param startAngle 起始角度(度)
|
|
909
|
+
* @param endAngle 结束角度(度)
|
|
910
|
+
* @param anticlockwise 是否逆时针绘制
|
|
911
|
+
* @param isFill 是否填充
|
|
912
|
+
* @param bgColor 背景颜色
|
|
913
|
+
* @throws 当Canvas context为null或undefined时抛出错误
|
|
1005
914
|
*/
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
915
|
+
drawArc({ x, y }, radius, startAngle, endAngle, anticlockwise, isFill, bgColor) {
|
|
916
|
+
if (!this.context) {
|
|
917
|
+
throw new Error("Canvas context is null or undefined");
|
|
918
|
+
}
|
|
919
|
+
if (isFill) {
|
|
920
|
+
this.context.fillStyle = bgColor;
|
|
921
|
+
this.context.beginPath();
|
|
922
|
+
this.context.arc(x, y, radius, MathUtil.deg2Rad(startAngle), MathUtil.deg2Rad(endAngle), anticlockwise);
|
|
923
|
+
this.context.fill();
|
|
924
|
+
} else {
|
|
925
|
+
this.context.strokeStyle = bgColor;
|
|
926
|
+
this.context.beginPath();
|
|
927
|
+
this.context.arc(x, y, radius, MathUtil.deg2Rad(startAngle), MathUtil.deg2Rad(endAngle), anticlockwise);
|
|
928
|
+
this.context.stroke();
|
|
929
|
+
}
|
|
1010
930
|
}
|
|
1011
|
-
}
|
|
931
|
+
drawImage(src, { x, y }) {
|
|
932
|
+
const img = new Image();
|
|
933
|
+
img.src = src;
|
|
934
|
+
img.onload = () => {
|
|
935
|
+
const width = img.width;
|
|
936
|
+
const height = img.height;
|
|
937
|
+
if (!this.context) {
|
|
938
|
+
throw new Error("Canvas context is null");
|
|
939
|
+
}
|
|
940
|
+
this.context.drawImage(img, x, y, -width / 2, -height / 2);
|
|
941
|
+
};
|
|
942
|
+
}
|
|
943
|
+
static createCanvas(width = 1, height = 1) {
|
|
944
|
+
const canvas = document.createElement("canvas");
|
|
945
|
+
if (width) {
|
|
946
|
+
canvas.width = width;
|
|
947
|
+
}
|
|
948
|
+
if (height) {
|
|
949
|
+
canvas.height = height;
|
|
950
|
+
}
|
|
951
|
+
return canvas;
|
|
952
|
+
}
|
|
953
|
+
}
|
|
954
|
+
class EventDispatcher {
|
|
955
|
+
constructor() {
|
|
956
|
+
__publicField(this, "_listeners", {});
|
|
957
|
+
__publicField(this, "_mutex", {});
|
|
958
|
+
__publicField(this, "_context");
|
|
959
|
+
}
|
|
960
|
+
addEventListener(type, listener, context, mutexStatus) {
|
|
961
|
+
this._context = context;
|
|
962
|
+
const mutex = this._mutex;
|
|
963
|
+
const listeners = this._listeners;
|
|
964
|
+
if (listeners[type] === void 0) {
|
|
965
|
+
listeners[type] = [];
|
|
966
|
+
}
|
|
967
|
+
if (listeners[type].indexOf(listener) === -1) {
|
|
968
|
+
if (mutexStatus) {
|
|
969
|
+
mutex[type] = listener;
|
|
970
|
+
}
|
|
971
|
+
listeners[type].push(listener);
|
|
972
|
+
}
|
|
973
|
+
return this;
|
|
974
|
+
}
|
|
975
|
+
hasEventListener(type, listener) {
|
|
976
|
+
if (this._listeners === null || this._listeners === void 0) return false;
|
|
977
|
+
const listeners = this._listeners;
|
|
978
|
+
return listeners[type] !== void 0 && listeners[type].indexOf(listener) !== -1;
|
|
979
|
+
}
|
|
980
|
+
removeEventListener(type, listener) {
|
|
981
|
+
if (this._listeners === void 0) return;
|
|
982
|
+
const listeners = this._listeners;
|
|
983
|
+
const listenerArray = listeners[type];
|
|
984
|
+
if (this._mutex[type] === listener) {
|
|
985
|
+
this._mutex[type] = null;
|
|
986
|
+
}
|
|
987
|
+
if (listenerArray !== void 0) {
|
|
988
|
+
const index = listenerArray.map((d) => d.toString()).indexOf(listener.toString());
|
|
989
|
+
if (index !== -1) {
|
|
990
|
+
listenerArray.splice(index, 1);
|
|
991
|
+
}
|
|
992
|
+
}
|
|
993
|
+
}
|
|
994
|
+
dispatchEvent(event) {
|
|
995
|
+
if (this._listeners === void 0) return;
|
|
996
|
+
const listeners = this._listeners;
|
|
997
|
+
const listenerArray = listeners[event.type];
|
|
998
|
+
if (listenerArray !== void 0) {
|
|
999
|
+
event.target = this;
|
|
1000
|
+
const array = listenerArray.slice(0);
|
|
1001
|
+
if (this._mutex[event.type] !== void 0) {
|
|
1002
|
+
const find = array.find((item) => item === this._mutex[event.type]);
|
|
1003
|
+
if (find) {
|
|
1004
|
+
find.call(this._context || this, event);
|
|
1005
|
+
return;
|
|
1006
|
+
}
|
|
1007
|
+
}
|
|
1008
|
+
for (let i = 0, l = array.length; i < l; i++) {
|
|
1009
|
+
const item = array[i];
|
|
1010
|
+
if (typeof item === "function") {
|
|
1011
|
+
item.call(this._context || this, event);
|
|
1012
|
+
}
|
|
1013
|
+
}
|
|
1014
|
+
}
|
|
1015
|
+
}
|
|
1016
|
+
removeAllListener() {
|
|
1017
|
+
this._mutex = {};
|
|
1018
|
+
for (const key in this._listeners) {
|
|
1019
|
+
this._listeners[key] = [];
|
|
1020
|
+
}
|
|
1021
|
+
}
|
|
1022
|
+
on(type, listener, context, mutexStatus) {
|
|
1023
|
+
return this.addEventListener.call(this, type, listener, context, mutexStatus);
|
|
1024
|
+
}
|
|
1025
|
+
off(type, listener) {
|
|
1026
|
+
return this.removeEventListener.call(this, type, listener);
|
|
1027
|
+
}
|
|
1028
|
+
}
|
|
1012
1029
|
const ObjectUtil = {
|
|
1013
1030
|
deepClone(a) {
|
|
1014
1031
|
return structuredClone(a);
|
|
@@ -1017,9 +1034,13 @@ const ObjectUtil = {
|
|
|
1017
1034
|
return JSON.stringify(a) === JSON.stringify(b);
|
|
1018
1035
|
},
|
|
1019
1036
|
parse(str) {
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1037
|
+
try {
|
|
1038
|
+
if (typeof str === "string" && str.startsWith("{") && str.endsWith("}")) return JSON.parse(str);
|
|
1039
|
+
if (Util.isEmpty(str)) return {};
|
|
1040
|
+
if (Util.isObject(str)) return str;
|
|
1041
|
+
} catch (error) {
|
|
1042
|
+
throw new Error(ErrorType.JSON_PARSE_ERROR + " -> " + str);
|
|
1043
|
+
}
|
|
1023
1044
|
}
|
|
1024
1045
|
};
|
|
1025
1046
|
class HashMap extends Map {
|
|
@@ -1079,10 +1100,10 @@ class WebSocketClient extends EventDispatcher {
|
|
|
1079
1100
|
this.disconnect();
|
|
1080
1101
|
if (this.url) {
|
|
1081
1102
|
try {
|
|
1103
|
+
const self = this;
|
|
1082
1104
|
console.info("创建ws连接>>>" + this.url);
|
|
1083
1105
|
this.client = new WebSocket(this.url);
|
|
1084
1106
|
if (this.client) {
|
|
1085
|
-
const self = this;
|
|
1086
1107
|
this.client.onopen = function(message) {
|
|
1087
1108
|
self.dispatchEvent({
|
|
1088
1109
|
type: EventType.WEB_SOCKET_CONNECT,
|
|
@@ -1131,14 +1152,14 @@ class WebSocketClient extends EventDispatcher {
|
|
|
1131
1152
|
if (this.checkTimes > times) return;
|
|
1132
1153
|
setTimeout(() => {
|
|
1133
1154
|
this.checkTimes++;
|
|
1134
|
-
if (this.
|
|
1155
|
+
if (this.state !== WebSocket.CONNECTING && this.state !== WebSocket.OPEN) {
|
|
1135
1156
|
this.connect();
|
|
1136
1157
|
}
|
|
1137
1158
|
this.connCheckStatus(times);
|
|
1138
1159
|
}, 2e3);
|
|
1139
1160
|
}
|
|
1140
1161
|
send(message) {
|
|
1141
|
-
if (this.client && this.
|
|
1162
|
+
if (this.client && this.state === WebSocket.OPEN) {
|
|
1142
1163
|
this.client.send(message);
|
|
1143
1164
|
return true;
|
|
1144
1165
|
}
|
|
@@ -1147,13 +1168,17 @@ class WebSocketClient extends EventDispatcher {
|
|
|
1147
1168
|
}
|
|
1148
1169
|
heartbeat() {
|
|
1149
1170
|
setTimeout(() => {
|
|
1150
|
-
if (this.
|
|
1171
|
+
if (this.state === WebSocket.OPEN) {
|
|
1151
1172
|
this.send("HeartBeat");
|
|
1152
1173
|
}
|
|
1153
1174
|
console.log("HeartBeat," + this.url);
|
|
1154
1175
|
setTimeout(this.heartbeat, 3e4);
|
|
1155
1176
|
}, 1e3);
|
|
1156
1177
|
}
|
|
1178
|
+
get state() {
|
|
1179
|
+
var _a2;
|
|
1180
|
+
return (_a2 = this.client) == null ? void 0 : _a2.readyState;
|
|
1181
|
+
}
|
|
1157
1182
|
}
|
|
1158
1183
|
const ImageUtil = {
|
|
1159
1184
|
emptyImageUrl: "data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7",
|
|
@@ -1745,205 +1770,23 @@ class GeoUtil {
|
|
|
1745
1770
|
const x = lng * Math.PI / 180 * earthRad;
|
|
1746
1771
|
var a = lat * Math.PI / 180;
|
|
1747
1772
|
const y = earthRad / 2 * Math.log((1 + Math.sin(a)) / (1 - Math.sin(a)));
|
|
1748
|
-
return { x, y };
|
|
1749
|
-
}
|
|
1750
|
-
/**
|
|
1751
|
-
* 根据百分比获取坐标
|
|
1752
|
-
*
|
|
1753
|
-
* @param start 起点坐标
|
|
1754
|
-
* @param end 终点坐标
|
|
1755
|
-
* @param percent 百分比,取值范围0-1
|
|
1756
|
-
* @returns 返回插值后的坐标
|
|
1757
|
-
*/
|
|
1758
|
-
static interpolate({ x: x1, y: y1, z: z1 = 0 }, { x: x2, y: y2, z: z2 = 0 }, percent) {
|
|
1759
|
-
const dx = x2 - x1, dy = y2 - y1, dz = z2 - z1;
|
|
1760
|
-
return { x: x1 + dx * percent, y: y1 + dy * percent, z: z1 + dz * percent };
|
|
1761
|
-
}
|
|
1762
|
-
}
|
|
1763
|
-
__publicField(GeoUtil, "toRadian", Math.PI / 180);
|
|
1764
|
-
__publicField(GeoUtil, "R", 6371393);
|
|
1765
|
-
const StringUtil = {
|
|
1766
|
-
/**
|
|
1767
|
-
* 校验字符串是否符合指定类型
|
|
1768
|
-
*
|
|
1769
|
-
* @param str 待校验字符串
|
|
1770
|
-
* @param type 校验类型,可选值包括:
|
|
1771
|
-
* - 'phone': 手机号码
|
|
1772
|
-
* - 'tel': 座机
|
|
1773
|
-
* - 'card': 身份证
|
|
1774
|
-
* - 'pwd': 密码(以字母开头,长度在6~18之间,只能包含字母、数字和下划线)
|
|
1775
|
-
* - 'postal': 邮政编码
|
|
1776
|
-
* - 'QQ': QQ号
|
|
1777
|
-
* - 'email': 邮箱
|
|
1778
|
-
* - 'money': 金额(小数点2位)
|
|
1779
|
-
* - 'URL': 网址
|
|
1780
|
-
* - 'IP': IP地址
|
|
1781
|
-
* - 'date': 日期时间
|
|
1782
|
-
* - 'number': 数字
|
|
1783
|
-
* - 'english': 英文
|
|
1784
|
-
* - 'chinese': 中文
|
|
1785
|
-
* - 'lower': 小写字母
|
|
1786
|
-
* - 'upper': 大写字母
|
|
1787
|
-
* - 'HTML': HTML标记
|
|
1788
|
-
* @returns 校验结果,符合返回true,否则返回false
|
|
1789
|
-
*/
|
|
1790
|
-
checkStr(str, type) {
|
|
1791
|
-
switch (type) {
|
|
1792
|
-
case "phone":
|
|
1793
|
-
return /^1[3|4|5|6|7|8|9][0-9]{9}$/.test(str);
|
|
1794
|
-
case "tel":
|
|
1795
|
-
return /^(0\d{2,3}-\d{7,8})(-\d{1,4})?$/.test(str);
|
|
1796
|
-
case "card":
|
|
1797
|
-
return /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/.test(str);
|
|
1798
|
-
case "pwd":
|
|
1799
|
-
return /^[a-zA-Z]\w{5,17}$/.test(str);
|
|
1800
|
-
case "postal":
|
|
1801
|
-
return /[1-9]\d{5}(?!\d)/.test(str);
|
|
1802
|
-
case "QQ":
|
|
1803
|
-
return /^[1-9][0-9]{4,9}$/.test(str);
|
|
1804
|
-
case "email":
|
|
1805
|
-
return /^[\w-]+(\.[\w-]+)*@[\w-]+(\.[\w-]+)+$/.test(str);
|
|
1806
|
-
case "money":
|
|
1807
|
-
return /^\d*(?:\.\d{0,2})?$/.test(str);
|
|
1808
|
-
case "URL":
|
|
1809
|
-
return /(http|ftp|https):\/\/[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^=%&:/~\+#]*[\w\-\@?^=%&/~\+#])?/.test(str);
|
|
1810
|
-
case "IP":
|
|
1811
|
-
return /((?:(?:25[0-5]|2[0-4]\\d|[01]?\\d?\\d)\\.){3}(?:25[0-5]|2[0-4]\\d|[01]?\\d?\\d))/.test(str);
|
|
1812
|
-
case "date":
|
|
1813
|
-
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);
|
|
1814
|
-
case "number":
|
|
1815
|
-
return /^[0-9]$/.test(str);
|
|
1816
|
-
case "english":
|
|
1817
|
-
return /^[a-zA-Z]+$/.test(str);
|
|
1818
|
-
case "chinese":
|
|
1819
|
-
return /^[\u4E00-\u9FA5]+$/.test(str);
|
|
1820
|
-
case "lower":
|
|
1821
|
-
return /^[a-z]+$/.test(str);
|
|
1822
|
-
case "upper":
|
|
1823
|
-
return /^[A-Z]+$/.test(str);
|
|
1824
|
-
case "HTML":
|
|
1825
|
-
return /<("[^"]*"|'[^']*'|[^'">])*>/.test(str);
|
|
1826
|
-
default:
|
|
1827
|
-
return true;
|
|
1828
|
-
}
|
|
1829
|
-
},
|
|
1830
|
-
/**
|
|
1831
|
-
* 转换字符串大小写
|
|
1832
|
-
*
|
|
1833
|
-
* @param str 待转换的字符串
|
|
1834
|
-
* @param type 转换类型,可选值为 1-5,默认为 4
|
|
1835
|
-
* 1:首字母大写,其余小写
|
|
1836
|
-
* 2:首字母小写,其余大写
|
|
1837
|
-
* 3:字母大小写反转
|
|
1838
|
-
* 4:全部大写
|
|
1839
|
-
* 5:全部小写
|
|
1840
|
-
* @returns 转换后的字符串
|
|
1841
|
-
*/
|
|
1842
|
-
changeCase(str, type) {
|
|
1843
|
-
type = type || 4;
|
|
1844
|
-
switch (type) {
|
|
1845
|
-
case 1:
|
|
1846
|
-
return str.replace(/\b\w+\b/g, function(word) {
|
|
1847
|
-
return word.substring(0, 1).toUpperCase() + word.substring(1).toLowerCase();
|
|
1848
|
-
});
|
|
1849
|
-
case 2:
|
|
1850
|
-
return str.replace(/\b\w+\b/g, function(word) {
|
|
1851
|
-
return word.substring(0, 1).toLowerCase() + word.substring(1).toUpperCase();
|
|
1852
|
-
});
|
|
1853
|
-
case 3:
|
|
1854
|
-
return str.split("").map(function(word) {
|
|
1855
|
-
if (/[a-z]/.test(word)) {
|
|
1856
|
-
return word.toUpperCase();
|
|
1857
|
-
} else {
|
|
1858
|
-
return word.toLowerCase();
|
|
1859
|
-
}
|
|
1860
|
-
}).join("");
|
|
1861
|
-
case 4:
|
|
1862
|
-
return str.toUpperCase();
|
|
1863
|
-
case 5:
|
|
1864
|
-
return str.toLowerCase();
|
|
1865
|
-
default:
|
|
1866
|
-
return str;
|
|
1867
|
-
}
|
|
1868
|
-
},
|
|
1869
|
-
/**
|
|
1870
|
-
* 计算字符串的字节长度
|
|
1871
|
-
*
|
|
1872
|
-
* @param str 需要计算字节长度的字符串
|
|
1873
|
-
* @returns 返回字符串的字节长度
|
|
1874
|
-
*/
|
|
1875
|
-
getByteLength(str) {
|
|
1876
|
-
return str.replace(/[\u0391-\uFFE5]/g, "aa").length;
|
|
1877
|
-
},
|
|
1773
|
+
return { x, y };
|
|
1774
|
+
}
|
|
1878
1775
|
/**
|
|
1879
|
-
*
|
|
1776
|
+
* 根据百分比获取坐标
|
|
1880
1777
|
*
|
|
1881
|
-
* @param
|
|
1882
|
-
* @param
|
|
1883
|
-
* @param
|
|
1884
|
-
* @returns
|
|
1778
|
+
* @param start 起点坐标
|
|
1779
|
+
* @param end 终点坐标
|
|
1780
|
+
* @param percent 百分比,取值范围0-1
|
|
1781
|
+
* @returns 返回插值后的坐标
|
|
1885
1782
|
*/
|
|
1886
|
-
|
|
1887
|
-
|
|
1888
|
-
|
|
1889
|
-
return str;
|
|
1890
|
-
}
|
|
1891
|
-
var m = Math.floor(n / 2);
|
|
1892
|
-
for (var i = m; i < str.length; i++) {
|
|
1893
|
-
let sub = str.substring(start, i);
|
|
1894
|
-
if (sub.replace(r, "mm").length >= n) {
|
|
1895
|
-
return sub;
|
|
1896
|
-
}
|
|
1897
|
-
}
|
|
1898
|
-
return str;
|
|
1899
|
-
},
|
|
1900
|
-
string2Bytes(str) {
|
|
1901
|
-
const bytes = [];
|
|
1902
|
-
let c;
|
|
1903
|
-
const len = str.length;
|
|
1904
|
-
for (let i = 0; i < len; i++) {
|
|
1905
|
-
c = str.charCodeAt(i);
|
|
1906
|
-
if (c >= 65536 && c <= 1114111) {
|
|
1907
|
-
bytes.push(c >> 18 & 7 | 240);
|
|
1908
|
-
bytes.push(c >> 12 & 63 | 128);
|
|
1909
|
-
bytes.push(c >> 6 & 63 | 128);
|
|
1910
|
-
bytes.push(c & 63 | 128);
|
|
1911
|
-
} else if (c >= 2048 && c <= 65535) {
|
|
1912
|
-
bytes.push(c >> 12 & 15 | 224);
|
|
1913
|
-
bytes.push(c >> 6 & 63 | 128);
|
|
1914
|
-
bytes.push(c & 63 | 128);
|
|
1915
|
-
} else if (c >= 128 && c <= 2047) {
|
|
1916
|
-
bytes.push(c >> 6 & 31 | 192);
|
|
1917
|
-
bytes.push(c & 63 | 128);
|
|
1918
|
-
} else {
|
|
1919
|
-
bytes.push(c & 255);
|
|
1920
|
-
}
|
|
1921
|
-
}
|
|
1922
|
-
return new Uint8Array(bytes);
|
|
1923
|
-
},
|
|
1924
|
-
bytes2String(uint8arr) {
|
|
1925
|
-
if (typeof uint8arr === "string") {
|
|
1926
|
-
return uint8arr;
|
|
1927
|
-
}
|
|
1928
|
-
let str = "";
|
|
1929
|
-
const _arr = uint8arr;
|
|
1930
|
-
for (let i = 0; i < _arr.length; i++) {
|
|
1931
|
-
const one = _arr[i].toString(2), v = one.match(/^1+?(?=0)/);
|
|
1932
|
-
if (v && one.length == 8) {
|
|
1933
|
-
const bytesLength = v[0].length;
|
|
1934
|
-
let store = _arr[i].toString(2).slice(7 - bytesLength);
|
|
1935
|
-
for (let st = 1; st < bytesLength; st++) {
|
|
1936
|
-
store += _arr[st + i].toString(2).slice(2);
|
|
1937
|
-
}
|
|
1938
|
-
str += String.fromCharCode(parseInt(store, 2));
|
|
1939
|
-
i += bytesLength - 1;
|
|
1940
|
-
} else {
|
|
1941
|
-
str += String.fromCharCode(_arr[i]);
|
|
1942
|
-
}
|
|
1943
|
-
}
|
|
1944
|
-
return str;
|
|
1783
|
+
static interpolate({ x: x1, y: y1, z: z1 = 0 }, { x: x2, y: y2, z: z2 = 0 }, percent) {
|
|
1784
|
+
const dx = x2 - x1, dy = y2 - y1, dz = z2 - z1;
|
|
1785
|
+
return { x: x1 + dx * percent, y: y1 + dy * percent, z: z1 + dz * percent };
|
|
1945
1786
|
}
|
|
1946
|
-
}
|
|
1787
|
+
}
|
|
1788
|
+
__publicField(GeoUtil, "toRadian", Math.PI / 180);
|
|
1789
|
+
__publicField(GeoUtil, "R", 6371393);
|
|
1947
1790
|
const TYPES = ["Point", "MultiPoint", "LineString", "MultiLineString", "Polygon", "MultiPolygon"];
|
|
1948
1791
|
const GeoJsonUtil = {
|
|
1949
1792
|
/**
|
|
@@ -2185,67 +2028,118 @@ const GeoJsonUtil = {
|
|
|
2185
2028
|
};
|
|
2186
2029
|
}
|
|
2187
2030
|
};
|
|
2031
|
+
const ExceptionUtil = {
|
|
2032
|
+
getException(type, message) {
|
|
2033
|
+
const _Exception = function() {
|
|
2034
|
+
Error.call(this, message);
|
|
2035
|
+
this.name = type;
|
|
2036
|
+
this.message = message;
|
|
2037
|
+
this.stack = new Error().stack;
|
|
2038
|
+
};
|
|
2039
|
+
if (Error) _Exception.__proto__ = Error;
|
|
2040
|
+
_Exception.prototype = Object.create(Error && Error.prototype);
|
|
2041
|
+
_Exception.prototype.constructor = _Exception;
|
|
2042
|
+
return _Exception;
|
|
2043
|
+
},
|
|
2044
|
+
throwException(msg) {
|
|
2045
|
+
const _Exception = this.getException("Exception", msg);
|
|
2046
|
+
throw new _Exception(msg);
|
|
2047
|
+
},
|
|
2048
|
+
throwColorException(msg) {
|
|
2049
|
+
const _Exception = this.getException("ColorException", ErrorType.DATA_ERROR_COLOR + " -> " + msg);
|
|
2050
|
+
throw new _Exception(msg);
|
|
2051
|
+
},
|
|
2052
|
+
throwCoordinateException(msg) {
|
|
2053
|
+
const _Exception = this.getException("CoordinateException", ErrorType.DATA_ERROR_COORDINATE + " -> " + msg);
|
|
2054
|
+
throw new _Exception(msg);
|
|
2055
|
+
},
|
|
2056
|
+
throwGeoJsonException(msg) {
|
|
2057
|
+
const _Exception = this.getException("GeoJsonException", ErrorType.DATA_ERROR_GEOJSON + " -> " + msg);
|
|
2058
|
+
throw new _Exception(msg);
|
|
2059
|
+
},
|
|
2060
|
+
throwEmptyException(msg) {
|
|
2061
|
+
const _Exception = this.getException("EmptyException", ErrorType.PARAMETER_ERROR_LACK + " -> " + msg);
|
|
2062
|
+
throw new _Exception(msg);
|
|
2063
|
+
},
|
|
2064
|
+
throwIntegerException(msg) {
|
|
2065
|
+
const _Exception = this.getException("IntegerException", ErrorType.PARAMETER_ERROR_INTEGER + " -> " + msg);
|
|
2066
|
+
throw new _Exception(msg);
|
|
2067
|
+
},
|
|
2068
|
+
throwNumberException(msg) {
|
|
2069
|
+
const _Exception = this.getException("NumberException", ErrorType.PARAMETER_ERROR_NUMBER + " -> " + msg);
|
|
2070
|
+
throw new _Exception(msg);
|
|
2071
|
+
},
|
|
2072
|
+
throwArrayException(msg) {
|
|
2073
|
+
const _Exception = this.getException("ArrayException", ErrorType.PARAMETER_ERROR_ARRAY + " -> " + msg);
|
|
2074
|
+
throw new _Exception(msg);
|
|
2075
|
+
},
|
|
2076
|
+
throwFunctionException(msg) {
|
|
2077
|
+
const _Exception = this.getException("FunctionException", ErrorType.PARAMETER_ERROR_FUNCTION + " -> " + msg);
|
|
2078
|
+
throw new _Exception(msg);
|
|
2079
|
+
},
|
|
2080
|
+
throwProcessException(msg) {
|
|
2081
|
+
const _Exception = this.getException("ProcessException", ErrorType.PROCESS_FAIL + " -> " + msg);
|
|
2082
|
+
throw new _Exception(msg);
|
|
2083
|
+
},
|
|
2084
|
+
throwNetworkException(msg) {
|
|
2085
|
+
const _Exception = this.getException("NetworkException", ErrorType.REQUEST_ERROR_TIMEOUT + " -> " + msg);
|
|
2086
|
+
throw new _Exception(msg);
|
|
2087
|
+
}
|
|
2088
|
+
};
|
|
2188
2089
|
const AssertUtil = {
|
|
2189
2090
|
assertEmpty(...arg) {
|
|
2190
2091
|
arg.forEach((a) => {
|
|
2191
2092
|
if (Util.isEmpty(a)) {
|
|
2192
|
-
|
|
2093
|
+
ExceptionUtil.throwEmptyException(a);
|
|
2193
2094
|
}
|
|
2194
2095
|
});
|
|
2195
2096
|
},
|
|
2196
2097
|
assertInteger(...arg) {
|
|
2197
2098
|
arg.forEach((a) => {
|
|
2198
2099
|
if (!Util.isInteger(a)) {
|
|
2199
|
-
|
|
2100
|
+
ExceptionUtil.throwIntegerException(a);
|
|
2200
2101
|
}
|
|
2201
2102
|
});
|
|
2202
2103
|
},
|
|
2203
2104
|
assertNumber(...arg) {
|
|
2204
2105
|
arg.forEach((a) => {
|
|
2205
2106
|
if (!Util.isNumber(a)) {
|
|
2206
|
-
|
|
2107
|
+
ExceptionUtil.throwNumberException(a);
|
|
2207
2108
|
}
|
|
2208
2109
|
});
|
|
2209
2110
|
},
|
|
2210
2111
|
assertArray(...arg) {
|
|
2211
2112
|
arg.forEach((a) => {
|
|
2212
2113
|
if (!Util.isArray(a)) {
|
|
2213
|
-
|
|
2114
|
+
ExceptionUtil.throwArrayException(a);
|
|
2214
2115
|
}
|
|
2215
2116
|
});
|
|
2216
2117
|
},
|
|
2217
2118
|
assertFunction(...arg) {
|
|
2218
2119
|
arg.forEach((a) => {
|
|
2219
2120
|
if (!Util.isFunction(a)) {
|
|
2220
|
-
|
|
2221
|
-
}
|
|
2222
|
-
});
|
|
2223
|
-
},
|
|
2224
|
-
assertObject(...arg) {
|
|
2225
|
-
arg.forEach((a) => {
|
|
2226
|
-
if (!Util.isObject(a)) {
|
|
2227
|
-
throw Error(ErrorType.PARAMETER_ERROR_OBJECT + " -> " + a);
|
|
2121
|
+
ExceptionUtil.throwFunctionException(a);
|
|
2228
2122
|
}
|
|
2229
2123
|
});
|
|
2230
2124
|
},
|
|
2231
2125
|
assertColor(...arg) {
|
|
2232
2126
|
arg.forEach((a) => {
|
|
2233
2127
|
if (!Color.isColor(a)) {
|
|
2234
|
-
|
|
2128
|
+
ExceptionUtil.throwColorException(a);
|
|
2235
2129
|
}
|
|
2236
2130
|
});
|
|
2237
2131
|
},
|
|
2238
2132
|
assertLnglat(...arg) {
|
|
2239
2133
|
arg.forEach((a) => {
|
|
2240
2134
|
if (!GeoUtil.isLnglat(a.lng, a.lat)) {
|
|
2241
|
-
|
|
2135
|
+
ExceptionUtil.throwCoordinateException(a);
|
|
2242
2136
|
}
|
|
2243
2137
|
});
|
|
2244
2138
|
},
|
|
2245
2139
|
assertGeoJson(...arg) {
|
|
2246
2140
|
arg.forEach((a) => {
|
|
2247
2141
|
if (!GeoJsonUtil.isGeoJson(a)) {
|
|
2248
|
-
|
|
2142
|
+
ExceptionUtil.throwGeoJsonException(a);
|
|
2249
2143
|
}
|
|
2250
2144
|
});
|
|
2251
2145
|
},
|
|
@@ -2268,73 +2162,6 @@ const AssertUtil = {
|
|
|
2268
2162
|
if (!value.endsWith(prefix)) {
|
|
2269
2163
|
throw Error("字符串" + value + "结尾不是 -> " + prefix);
|
|
2270
2164
|
}
|
|
2271
|
-
},
|
|
2272
|
-
/**
|
|
2273
|
-
* 判断字符串是否合法
|
|
2274
|
-
*
|
|
2275
|
-
* @param value 待判断的字符串
|
|
2276
|
-
* @param type 字符串类型
|
|
2277
|
-
* @throws 当字符串不合法时,抛出错误,错误信息为“参数错误 -> 不是{typename}”
|
|
2278
|
-
*/
|
|
2279
|
-
assertLegal(value, type) {
|
|
2280
|
-
const bool = StringUtil.checkStr(value, type);
|
|
2281
|
-
let typename = "";
|
|
2282
|
-
switch (type) {
|
|
2283
|
-
case "phone":
|
|
2284
|
-
typename = "电话";
|
|
2285
|
-
break;
|
|
2286
|
-
case "tel":
|
|
2287
|
-
typename = "座机";
|
|
2288
|
-
break;
|
|
2289
|
-
case "card":
|
|
2290
|
-
typename = "身份证";
|
|
2291
|
-
break;
|
|
2292
|
-
case "pwd":
|
|
2293
|
-
typename = "密码";
|
|
2294
|
-
break;
|
|
2295
|
-
case "postal":
|
|
2296
|
-
typename = "邮政编码";
|
|
2297
|
-
break;
|
|
2298
|
-
case "QQ":
|
|
2299
|
-
typename = "QQ";
|
|
2300
|
-
break;
|
|
2301
|
-
case "email":
|
|
2302
|
-
typename = "邮箱";
|
|
2303
|
-
break;
|
|
2304
|
-
case "money":
|
|
2305
|
-
typename = "金额";
|
|
2306
|
-
break;
|
|
2307
|
-
case "URL":
|
|
2308
|
-
typename = "网址";
|
|
2309
|
-
break;
|
|
2310
|
-
case "IP":
|
|
2311
|
-
typename = "IP";
|
|
2312
|
-
break;
|
|
2313
|
-
case "date":
|
|
2314
|
-
typename = "日期时间";
|
|
2315
|
-
break;
|
|
2316
|
-
case "number":
|
|
2317
|
-
typename = "数字";
|
|
2318
|
-
break;
|
|
2319
|
-
case "english":
|
|
2320
|
-
typename = "英文";
|
|
2321
|
-
break;
|
|
2322
|
-
case "chinese":
|
|
2323
|
-
typename = "中文";
|
|
2324
|
-
break;
|
|
2325
|
-
case "lower":
|
|
2326
|
-
typename = "小写";
|
|
2327
|
-
break;
|
|
2328
|
-
case "upper":
|
|
2329
|
-
typename = "大写";
|
|
2330
|
-
break;
|
|
2331
|
-
case "HTML":
|
|
2332
|
-
typename = "HTML标记";
|
|
2333
|
-
break;
|
|
2334
|
-
}
|
|
2335
|
-
if (!bool) {
|
|
2336
|
-
throw Error(ErrorType.DATA_ERROR + " -> 不是" + typename);
|
|
2337
|
-
}
|
|
2338
2165
|
}
|
|
2339
2166
|
};
|
|
2340
2167
|
const myArray = Object.create(Array);
|
|
@@ -3548,6 +3375,124 @@ const OptimizeUtil = {
|
|
|
3548
3375
|
};
|
|
3549
3376
|
}
|
|
3550
3377
|
};
|
|
3378
|
+
const StringUtil = {
|
|
3379
|
+
/**
|
|
3380
|
+
* 转换字符串大小写
|
|
3381
|
+
*
|
|
3382
|
+
* @param str 待转换的字符串
|
|
3383
|
+
* @param type 转换类型,可选值为 1-5,默认为 4
|
|
3384
|
+
* 1:首字母大写,其余小写
|
|
3385
|
+
* 2:首字母小写,其余大写
|
|
3386
|
+
* 3:字母大小写反转
|
|
3387
|
+
* 4:全部大写
|
|
3388
|
+
* 5:全部小写
|
|
3389
|
+
* @returns 转换后的字符串
|
|
3390
|
+
*/
|
|
3391
|
+
changeCase(str, type) {
|
|
3392
|
+
type = type || 4;
|
|
3393
|
+
switch (type) {
|
|
3394
|
+
case 1:
|
|
3395
|
+
return str.replace(/\b\w+\b/g, function(word) {
|
|
3396
|
+
return word.substring(0, 1).toUpperCase() + word.substring(1).toLowerCase();
|
|
3397
|
+
});
|
|
3398
|
+
case 2:
|
|
3399
|
+
return str.replace(/\b\w+\b/g, function(word) {
|
|
3400
|
+
return word.substring(0, 1).toLowerCase() + word.substring(1).toUpperCase();
|
|
3401
|
+
});
|
|
3402
|
+
case 3:
|
|
3403
|
+
return str.split("").map(function(word) {
|
|
3404
|
+
if (/[a-z]/.test(word)) {
|
|
3405
|
+
return word.toUpperCase();
|
|
3406
|
+
} else {
|
|
3407
|
+
return word.toLowerCase();
|
|
3408
|
+
}
|
|
3409
|
+
}).join("");
|
|
3410
|
+
case 4:
|
|
3411
|
+
return str.toUpperCase();
|
|
3412
|
+
case 5:
|
|
3413
|
+
return str.toLowerCase();
|
|
3414
|
+
default:
|
|
3415
|
+
return str;
|
|
3416
|
+
}
|
|
3417
|
+
},
|
|
3418
|
+
/**
|
|
3419
|
+
* 计算字符串的字节长度
|
|
3420
|
+
*
|
|
3421
|
+
* @param str 需要计算字节长度的字符串
|
|
3422
|
+
* @returns 返回字符串的字节长度
|
|
3423
|
+
*/
|
|
3424
|
+
getByteLength(str) {
|
|
3425
|
+
return str.replace(/[\u0391-\uFFE5]/g, "aa").length;
|
|
3426
|
+
},
|
|
3427
|
+
/**
|
|
3428
|
+
* 截取字符串中指定字节长度的子串
|
|
3429
|
+
*
|
|
3430
|
+
* @param str 字符串对象,包含replace、length和substring方法
|
|
3431
|
+
* @param start 截取起始位置
|
|
3432
|
+
* @param n 截取字节长度
|
|
3433
|
+
* @returns 返回截取后的子串
|
|
3434
|
+
*/
|
|
3435
|
+
subStringByte(str, start, n) {
|
|
3436
|
+
var r = /[^\x00-\xff]/g;
|
|
3437
|
+
if (str.replace(r, "mm").length <= n) {
|
|
3438
|
+
return str;
|
|
3439
|
+
}
|
|
3440
|
+
var m = Math.floor(n / 2);
|
|
3441
|
+
for (var i = m; i < str.length; i++) {
|
|
3442
|
+
let sub = str.substring(start, i);
|
|
3443
|
+
if (sub.replace(r, "mm").length >= n) {
|
|
3444
|
+
return sub;
|
|
3445
|
+
}
|
|
3446
|
+
}
|
|
3447
|
+
return str;
|
|
3448
|
+
},
|
|
3449
|
+
string2Bytes(str) {
|
|
3450
|
+
const bytes = [];
|
|
3451
|
+
let c;
|
|
3452
|
+
const len = str.length;
|
|
3453
|
+
for (let i = 0; i < len; i++) {
|
|
3454
|
+
c = str.charCodeAt(i);
|
|
3455
|
+
if (c >= 65536 && c <= 1114111) {
|
|
3456
|
+
bytes.push(c >> 18 & 7 | 240);
|
|
3457
|
+
bytes.push(c >> 12 & 63 | 128);
|
|
3458
|
+
bytes.push(c >> 6 & 63 | 128);
|
|
3459
|
+
bytes.push(c & 63 | 128);
|
|
3460
|
+
} else if (c >= 2048 && c <= 65535) {
|
|
3461
|
+
bytes.push(c >> 12 & 15 | 224);
|
|
3462
|
+
bytes.push(c >> 6 & 63 | 128);
|
|
3463
|
+
bytes.push(c & 63 | 128);
|
|
3464
|
+
} else if (c >= 128 && c <= 2047) {
|
|
3465
|
+
bytes.push(c >> 6 & 31 | 192);
|
|
3466
|
+
bytes.push(c & 63 | 128);
|
|
3467
|
+
} else {
|
|
3468
|
+
bytes.push(c & 255);
|
|
3469
|
+
}
|
|
3470
|
+
}
|
|
3471
|
+
return new Uint8Array(bytes);
|
|
3472
|
+
},
|
|
3473
|
+
bytes2String(uint8arr) {
|
|
3474
|
+
if (typeof uint8arr === "string") {
|
|
3475
|
+
return uint8arr;
|
|
3476
|
+
}
|
|
3477
|
+
let str = "";
|
|
3478
|
+
const _arr = uint8arr;
|
|
3479
|
+
for (let i = 0; i < _arr.length; i++) {
|
|
3480
|
+
const one = _arr[i].toString(2), v = one.match(/^1+?(?=0)/);
|
|
3481
|
+
if (v && one.length == 8) {
|
|
3482
|
+
const bytesLength = v[0].length;
|
|
3483
|
+
let store = _arr[i].toString(2).slice(7 - bytesLength);
|
|
3484
|
+
for (let st = 1; st < bytesLength; st++) {
|
|
3485
|
+
store += _arr[st + i].toString(2).slice(2);
|
|
3486
|
+
}
|
|
3487
|
+
str += String.fromCharCode(parseInt(store, 2));
|
|
3488
|
+
i += bytesLength - 1;
|
|
3489
|
+
} else {
|
|
3490
|
+
str += String.fromCharCode(_arr[i]);
|
|
3491
|
+
}
|
|
3492
|
+
}
|
|
3493
|
+
return str;
|
|
3494
|
+
}
|
|
3495
|
+
};
|
|
3551
3496
|
const UrlUtil = {
|
|
3552
3497
|
/**
|
|
3553
3498
|
* 将json对象转换为查询字符串
|
|
@@ -3597,6 +3542,53 @@ const UrlUtil = {
|
|
|
3597
3542
|
return obj;
|
|
3598
3543
|
}
|
|
3599
3544
|
};
|
|
3545
|
+
const ValidateUtil = {
|
|
3546
|
+
isUrl(v) {
|
|
3547
|
+
return /^(https?|ftp):\/\/([a-zA-Z0-9.-]+(:[a-zA-Z0-9.&%$-]+)*@)*((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9][0-9]?)(\.(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])){3}|([a-zA-Z0-9-]+\.)*[a-zA-Z0-9-]+\.(com|edu|gov|int|mil|net|org|biz|arpa|info|name|pro|aero|coop|museum|[a-zA-Z]{2}))(:[0-9]+)*(\/($|[a-zA-Z0-9.,?'\\+&%$#=~_-]+))*$/.test(
|
|
3548
|
+
v
|
|
3549
|
+
);
|
|
3550
|
+
},
|
|
3551
|
+
isPhone(v) {
|
|
3552
|
+
return /^1[3|4|5|6|7|8|9][0-9]{9}$/.test(v);
|
|
3553
|
+
},
|
|
3554
|
+
isTel(v) {
|
|
3555
|
+
return /^(0\d{2,3}-\d{7,8})(-\d{1,4})?$/.test(v);
|
|
3556
|
+
},
|
|
3557
|
+
/**
|
|
3558
|
+
* 判断是否是强密码,至少包含一个大写字母、一个小写字母、一个数字的组合、长度8-20位
|
|
3559
|
+
*
|
|
3560
|
+
* @param v 待检测的密码字符串
|
|
3561
|
+
* @returns 如果是是强密码,则返回 true;否则返回 false
|
|
3562
|
+
*/
|
|
3563
|
+
isStrongPwd(v) {
|
|
3564
|
+
return /^(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{8,20}$/.test(v);
|
|
3565
|
+
},
|
|
3566
|
+
isEmail(v) {
|
|
3567
|
+
return /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/.test(
|
|
3568
|
+
v
|
|
3569
|
+
);
|
|
3570
|
+
},
|
|
3571
|
+
isIP(v) {
|
|
3572
|
+
return /^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])$/.test(
|
|
3573
|
+
v
|
|
3574
|
+
);
|
|
3575
|
+
},
|
|
3576
|
+
isEnglish(v) {
|
|
3577
|
+
return /^[a-zA-Z]+$/.test(v);
|
|
3578
|
+
},
|
|
3579
|
+
isChinese(v) {
|
|
3580
|
+
return /^[\u4E00-\u9FA5]+$/.test(v);
|
|
3581
|
+
},
|
|
3582
|
+
isHTML(v) {
|
|
3583
|
+
return /<("[^"]*"|'[^']*'|[^'">])*>/.test(v);
|
|
3584
|
+
},
|
|
3585
|
+
isXML(v) {
|
|
3586
|
+
return /^([a-zA-Z]+-?)+[a-zA-Z0-9]+\\.[x|X][m|M][l|L]$/.test(v);
|
|
3587
|
+
},
|
|
3588
|
+
isIDCard(v) {
|
|
3589
|
+
return /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/.test(v);
|
|
3590
|
+
}
|
|
3591
|
+
};
|
|
3600
3592
|
const _MqttClient = class _MqttClient extends EventDispatcher {
|
|
3601
3593
|
constructor(url = `ws://${window.document.domain}:20007/mqtt`, config = {}) {
|
|
3602
3594
|
super();
|
|
@@ -3618,18 +3610,18 @@ const _MqttClient = class _MqttClient extends EventDispatcher {
|
|
|
3618
3610
|
this.client = connect(this.url, this.options);
|
|
3619
3611
|
this._onConnect();
|
|
3620
3612
|
this._onMessage();
|
|
3621
|
-
this.state =
|
|
3613
|
+
this.state = 1;
|
|
3622
3614
|
this.topics = [];
|
|
3623
3615
|
}
|
|
3624
3616
|
_onConnect() {
|
|
3625
3617
|
this.client.on("connect", () => {
|
|
3626
|
-
this.state =
|
|
3618
|
+
this.state = 2;
|
|
3627
3619
|
console.log("链接mqtt成功==>" + this.url);
|
|
3628
3620
|
this.dispatchEvent({ type: EventType.MQTT_CONNECT, message: this });
|
|
3629
3621
|
});
|
|
3630
3622
|
this.client.on("error", (err) => {
|
|
3631
3623
|
console.log("链接mqtt报错", err);
|
|
3632
|
-
this.state =
|
|
3624
|
+
this.state = 0;
|
|
3633
3625
|
this.dispatchEvent({ type: EventType.MQTT_ERROR, message: this });
|
|
3634
3626
|
this.client.end();
|
|
3635
3627
|
this.client.reconnect();
|
|
@@ -3662,7 +3654,7 @@ const _MqttClient = class _MqttClient extends EventDispatcher {
|
|
|
3662
3654
|
return this;
|
|
3663
3655
|
}
|
|
3664
3656
|
subscribe(topic) {
|
|
3665
|
-
this.state ===
|
|
3657
|
+
this.state === 2 ? this.client.subscribe(topic, { qos: 1 }, (error, e) => {
|
|
3666
3658
|
error instanceof Error ? console.error("订阅失败==>" + topic, error) : (this.topics = ArrayUtil.union(this.topics, topic), console.log("订阅成功==>" + topic));
|
|
3667
3659
|
}) : this.addEventListener(EventType.MQTT_CONNECT, (res) => {
|
|
3668
3660
|
this.client.subscribe(topic, { qos: 1 }, (error, e) => {
|
|
@@ -3828,7 +3820,9 @@ export {
|
|
|
3828
3820
|
ErrorType,
|
|
3829
3821
|
EventDispatcher,
|
|
3830
3822
|
EventType,
|
|
3823
|
+
ExceptionUtil,
|
|
3831
3824
|
FileUtil,
|
|
3825
|
+
FormType,
|
|
3832
3826
|
GeoJsonUtil,
|
|
3833
3827
|
GeoUtil,
|
|
3834
3828
|
GraphicType,
|
|
@@ -3846,5 +3840,6 @@ export {
|
|
|
3846
3840
|
StringUtil,
|
|
3847
3841
|
UrlUtil,
|
|
3848
3842
|
Util,
|
|
3843
|
+
ValidateUtil,
|
|
3849
3844
|
WebSocketClient
|
|
3850
3845
|
};
|