@lightsoft/js-sdk 1.1.1 → 1.2.1
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/index.d.ts +36 -6
- package/dist/index.js +173 -6
- package/dist/index.umd.js +187 -10
- package/dist/types/reg-exp/index.d.ts +15 -3
- package/dist/types/utils/array.d.ts +1 -0
- package/dist/types/utils/download.d.ts +1 -0
- package/dist/types/utils/index.d.ts +4 -0
- package/dist/types/utils/number.d.ts +1 -0
- package/dist/types/utils/url.d.ts +8 -0
- package/dist/types/utils/vue.d.ts +4 -0
- package/dist/types/utils/ws.d.ts +2 -2
- package/dist/{ws-EehpMWgu.js → ws-DGDUMiR9.js} +3 -3
- package/dist/ws.d.ts +3 -3
- package/dist/ws.js +1 -1
- package/dist/ws.umd.js +4 -4
- package/package.json +1 -1
- package/dist/ws-0exRUlFu.js +0 -144
- package/dist/ws-BPCzgHy0.js +0 -168
- package/dist/ws-CIMFnzix.js +0 -169
- package/dist/ws-DIZYbi31.js +0 -144
- package/dist/ws-D_5GJokP.js +0 -167
- package/dist/ws-DjIqS-Gi.js +0 -169
- package/dist/ws-mqcHwlvx.js +0 -166
package/dist/index.d.ts
CHANGED
|
@@ -58,6 +58,10 @@ interface CountDown {
|
|
|
58
58
|
* @description 发送验证码倒计时
|
|
59
59
|
*/
|
|
60
60
|
declare function useCountDown(num: number, text?: string): CountDown;
|
|
61
|
+
declare function useDownload(): {
|
|
62
|
+
loading: Ref<boolean, boolean>;
|
|
63
|
+
downloadFile: (url: string, filename?: string, success?: (blob: Blob) => void) => void;
|
|
64
|
+
};
|
|
61
65
|
|
|
62
66
|
declare enum RecordType {
|
|
63
67
|
AUDIO = "audio",
|
|
@@ -261,21 +265,47 @@ interface WebSocketConfig {
|
|
|
261
265
|
declare function createWebSocket(url: string, config: WebSocketConfig | null, onOpen?: Function | null): WebSocket;
|
|
262
266
|
declare function getState(ws: WebSocket, type: WebSocketState): boolean;
|
|
263
267
|
declare function useSendMessage(ws: WebSocket, data: any): void;
|
|
264
|
-
declare function
|
|
265
|
-
declare function
|
|
268
|
+
declare function useOnMessage(ws: WebSocket, callback: Function): void;
|
|
269
|
+
declare function useClose(ws: WebSocket, code?: number, message?: string): void;
|
|
270
|
+
|
|
271
|
+
declare function download(url: string, filename: string, success?: (blob: Blob) => void): Promise<void>;
|
|
272
|
+
|
|
273
|
+
declare const countUp: (start: number, end: number, callback: (current: number) => void) => void;
|
|
274
|
+
|
|
275
|
+
declare function hasRepeatArray(arr: any[], keys?: string[]): any[];
|
|
276
|
+
|
|
277
|
+
type TAddURLParamsReturn = {
|
|
278
|
+
url: string;
|
|
279
|
+
queryString: string;
|
|
280
|
+
};
|
|
281
|
+
declare function addURLParams(params: Record<string, any>, url?: string): TAddURLParamsReturn;
|
|
282
|
+
declare function getURLParams(url?: string): Record<string, any>;
|
|
283
|
+
declare function deleteURLParams(keys: string[], url?: string): URL;
|
|
266
284
|
|
|
267
285
|
/**
|
|
268
286
|
* 匹配中文字母数字
|
|
269
287
|
*/
|
|
270
|
-
declare const
|
|
288
|
+
declare const zhLetterNumber: RegExp;
|
|
271
289
|
/**
|
|
272
290
|
* 匹配 IP
|
|
273
291
|
*/
|
|
274
|
-
declare const
|
|
292
|
+
declare const ip: RegExp;
|
|
275
293
|
/**
|
|
276
294
|
* 匹配手机号
|
|
277
295
|
*/
|
|
278
|
-
declare const
|
|
296
|
+
declare const phone: RegExp;
|
|
297
|
+
/**
|
|
298
|
+
* 匹配身份证号
|
|
299
|
+
*/
|
|
300
|
+
declare const idCard: RegExp;
|
|
301
|
+
/**
|
|
302
|
+
* 匹配邮箱
|
|
303
|
+
*/
|
|
304
|
+
declare const email: RegExp;
|
|
305
|
+
/**
|
|
306
|
+
* 匹配 URL
|
|
307
|
+
*/
|
|
308
|
+
declare const url: RegExp;
|
|
279
309
|
|
|
280
|
-
export { HAS_FEILD,
|
|
310
|
+
export { HAS_FEILD, InputLegalityValidate, InputLengthValidate, LENGTH_LIMIT, LOGIN_TYPE, Mask, RecordType, Request, RequestChain, Tour, addURLParams, countUp, createWebSocket, dataHandler, debounce, deepMerge, deleteURLParams, download, email, findTreeDataNode, findTreeDataNodeName, getState, getURLParams, hasRepeatArray, idCard, ip, isMobileDevice, isNull, objectArrayToString, phone, throttle, url, useClose, useCountDown, useDownload, useOnMessage, useSendMessage, zhLetterNumber };
|
|
281
311
|
export type { ISectoralTable, Tag, typeIsNull };
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { _ as __assign, a as __awaiter, b as __generator } from './ws-
|
|
2
|
-
export { c as createWebSocket, g as getState,
|
|
1
|
+
import { _ as __assign, a as __awaiter, b as __generator } from './ws-DGDUMiR9.js';
|
|
2
|
+
export { c as createWebSocket, g as getState, e as useClose, d as useOnMessage, u as useSendMessage } from './ws-DGDUMiR9.js';
|
|
3
3
|
|
|
4
4
|
var READY_STATE;
|
|
5
5
|
(function (READY_STATE) {
|
|
@@ -2243,6 +2243,52 @@ if (!!(process.env.NODE_ENV !== "production")) {
|
|
|
2243
2243
|
initDev();
|
|
2244
2244
|
}
|
|
2245
2245
|
|
|
2246
|
+
function download(url, filename, success) {
|
|
2247
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
2248
|
+
var blob;
|
|
2249
|
+
return __generator(this, function (_a) {
|
|
2250
|
+
switch (_a.label) {
|
|
2251
|
+
case 0: return [4 /*yield*/, getBlob(url)];
|
|
2252
|
+
case 1:
|
|
2253
|
+
blob = _a.sent();
|
|
2254
|
+
save(blob, filename);
|
|
2255
|
+
success === null || success === void 0 ? void 0 : success(blob);
|
|
2256
|
+
return [2 /*return*/];
|
|
2257
|
+
}
|
|
2258
|
+
});
|
|
2259
|
+
});
|
|
2260
|
+
}
|
|
2261
|
+
function getBlob(url) {
|
|
2262
|
+
return new Promise(function (resolve, reject) {
|
|
2263
|
+
var xhr = new XMLHttpRequest();
|
|
2264
|
+
xhr.open('GET', url, true);
|
|
2265
|
+
xhr.responseType = 'blob';
|
|
2266
|
+
xhr.onload = function () {
|
|
2267
|
+
if (xhr.status === 200) {
|
|
2268
|
+
resolve(xhr.response);
|
|
2269
|
+
}
|
|
2270
|
+
else {
|
|
2271
|
+
reject(new Error("Request failed with status ".concat(xhr.status)));
|
|
2272
|
+
}
|
|
2273
|
+
};
|
|
2274
|
+
xhr.onerror = function () {
|
|
2275
|
+
reject(new Error('Request failed'));
|
|
2276
|
+
};
|
|
2277
|
+
xhr.send();
|
|
2278
|
+
});
|
|
2279
|
+
}
|
|
2280
|
+
function save(blob, filename) {
|
|
2281
|
+
var link = document.createElement('a');
|
|
2282
|
+
var body = document.body;
|
|
2283
|
+
link.href = window.URL.createObjectURL(blob);
|
|
2284
|
+
link.download = filename;
|
|
2285
|
+
link.style.display = 'none';
|
|
2286
|
+
body.appendChild(link);
|
|
2287
|
+
link.click();
|
|
2288
|
+
body.removeChild(link);
|
|
2289
|
+
window.URL.revokeObjectURL(link.href);
|
|
2290
|
+
}
|
|
2291
|
+
|
|
2246
2292
|
/**
|
|
2247
2293
|
*
|
|
2248
2294
|
* @param {number} num 倒计时时间
|
|
@@ -2271,6 +2317,21 @@ function useCountDown(num, text) {
|
|
|
2271
2317
|
};
|
|
2272
2318
|
return { countdownText: countdownText, disabled: disabled, send: send };
|
|
2273
2319
|
}
|
|
2320
|
+
function useDownload() {
|
|
2321
|
+
var loading = ref(false);
|
|
2322
|
+
var downloadFile = function (url, filename, success) {
|
|
2323
|
+
var _filename = filename || 'download_' + new Date().getTime();
|
|
2324
|
+
loading.value = true;
|
|
2325
|
+
download(url, _filename, function (blob) {
|
|
2326
|
+
loading.value = false;
|
|
2327
|
+
success === null || success === void 0 ? void 0 : success(blob);
|
|
2328
|
+
});
|
|
2329
|
+
};
|
|
2330
|
+
return {
|
|
2331
|
+
loading: loading,
|
|
2332
|
+
downloadFile: downloadFile
|
|
2333
|
+
};
|
|
2334
|
+
}
|
|
2274
2335
|
|
|
2275
2336
|
var RecordType;
|
|
2276
2337
|
(function (RecordType) {
|
|
@@ -2735,17 +2796,123 @@ var Tour = /** @class */ (function () {
|
|
|
2735
2796
|
return Tour;
|
|
2736
2797
|
}());
|
|
2737
2798
|
|
|
2799
|
+
var countUp = function (start, end, callback) {
|
|
2800
|
+
var current = start;
|
|
2801
|
+
var run = function () {
|
|
2802
|
+
if (current >= end) {
|
|
2803
|
+
clearInterval(timer);
|
|
2804
|
+
}
|
|
2805
|
+
else if (current >= end - 16 && current < end - 6) {
|
|
2806
|
+
clearInterval(timer);
|
|
2807
|
+
timer = setInterval(run, 90);
|
|
2808
|
+
}
|
|
2809
|
+
else if (current >= end - 6) {
|
|
2810
|
+
clearInterval(timer);
|
|
2811
|
+
timer = setInterval(run, 200);
|
|
2812
|
+
}
|
|
2813
|
+
callback(current++);
|
|
2814
|
+
};
|
|
2815
|
+
var timer = setInterval(run, 16);
|
|
2816
|
+
};
|
|
2817
|
+
// if (!Date.now){
|
|
2818
|
+
// Date.now = function () {
|
|
2819
|
+
// return new Date().getTime();
|
|
2820
|
+
// };
|
|
2821
|
+
// }
|
|
2822
|
+
// (function () {
|
|
2823
|
+
// 'use strict';
|
|
2824
|
+
// var vendors = ['webkit', 'moz'];
|
|
2825
|
+
// for (var i = 0; i < vendors.length && !window.requestAnimationFrame; ++i) {
|
|
2826
|
+
// var vp = vendors[i];
|
|
2827
|
+
// (window as any)[vp + 'RequestAnimationFrame'];
|
|
2828
|
+
// window.cancelAnimationFrame = (
|
|
2829
|
+
// (window as any)[vp + 'CancelAnimationFrame'] ||
|
|
2830
|
+
// (window as any)[vp + 'CancelRequestAnimationFrame']
|
|
2831
|
+
// )
|
|
2832
|
+
// }
|
|
2833
|
+
// if (
|
|
2834
|
+
// /iP(ad|hone|od).*OS 6/.test(window.navigator.userAgent) ||
|
|
2835
|
+
// !window.requestAnimationFrame ||
|
|
2836
|
+
// !window.cancelAnimationFrame
|
|
2837
|
+
// ) {
|
|
2838
|
+
// var lastTime = 0;
|
|
2839
|
+
// window.requestAnimationFrame = function (callback: FrameRequestCallback): any {
|
|
2840
|
+
// var now = Date.now();
|
|
2841
|
+
// var nextTime = Math.max(lastTime + 16, now);
|
|
2842
|
+
// return setTimeout( function () {
|
|
2843
|
+
// callback(lastTime = nextTime);
|
|
2844
|
+
// },nextTime - now);
|
|
2845
|
+
// }
|
|
2846
|
+
// window.cancelAnimationFrame = clearTimeout;
|
|
2847
|
+
// }
|
|
2848
|
+
// }())
|
|
2849
|
+
|
|
2850
|
+
function hasRepeatArray(arr, keys) {
|
|
2851
|
+
var map = new Map();
|
|
2852
|
+
var _loop_1 = function (item) {
|
|
2853
|
+
var val = (keys === null || keys === void 0 ? void 0 : keys.map(function (key) { return item[key]; }).join(',')) || item;
|
|
2854
|
+
if (map.has(val)) {
|
|
2855
|
+
return { value: [true, val.split(',')] };
|
|
2856
|
+
}
|
|
2857
|
+
map.set(val, item);
|
|
2858
|
+
};
|
|
2859
|
+
for (var _i = 0, arr_1 = arr; _i < arr_1.length; _i++) {
|
|
2860
|
+
var item = arr_1[_i];
|
|
2861
|
+
var state_1 = _loop_1(item);
|
|
2862
|
+
if (typeof state_1 === "object")
|
|
2863
|
+
return state_1.value;
|
|
2864
|
+
}
|
|
2865
|
+
return [false];
|
|
2866
|
+
}
|
|
2867
|
+
|
|
2868
|
+
function addURLParams(params, url) {
|
|
2869
|
+
url = url || window.location.href;
|
|
2870
|
+
var urlParams = getURLParams(url);
|
|
2871
|
+
var queryString = new URLSearchParams(Object.entries(__assign(__assign({}, urlParams), params))).toString();
|
|
2872
|
+
return {
|
|
2873
|
+
url: "".concat(url, "?").concat(queryString),
|
|
2874
|
+
queryString: queryString,
|
|
2875
|
+
};
|
|
2876
|
+
}
|
|
2877
|
+
function getURLParams(url) {
|
|
2878
|
+
url = url || window.location.href;
|
|
2879
|
+
var urlString = url.split('?')[1];
|
|
2880
|
+
var urlSearchParams = new URLSearchParams(urlString);
|
|
2881
|
+
var result = Object.fromEntries(urlSearchParams.entries());
|
|
2882
|
+
return result;
|
|
2883
|
+
}
|
|
2884
|
+
function deleteURLParams(keys, url) {
|
|
2885
|
+
url = url || window.location.href;
|
|
2886
|
+
var newUrl = new URL(url);
|
|
2887
|
+
var params = new URLSearchParams(newUrl.search);
|
|
2888
|
+
keys.forEach(function (key) { return params.delete(key); });
|
|
2889
|
+
newUrl.search = params.toString();
|
|
2890
|
+
return newUrl;
|
|
2891
|
+
}
|
|
2892
|
+
|
|
2738
2893
|
/**
|
|
2739
2894
|
* 匹配中文字母数字
|
|
2740
2895
|
*/
|
|
2741
|
-
var
|
|
2896
|
+
var zhLetterNumber = /^[\u4E00-\u9FA5\w]+$/;
|
|
2742
2897
|
/**
|
|
2743
2898
|
* 匹配 IP
|
|
2744
2899
|
*/
|
|
2745
|
-
var
|
|
2900
|
+
var ip = /^(?:(?:25[0-5]|2[0-4]\d|[01]?\d{1,2})\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d{1,2})$/;
|
|
2746
2901
|
/**
|
|
2747
2902
|
* 匹配手机号
|
|
2748
2903
|
*/
|
|
2749
|
-
var
|
|
2904
|
+
var phone = /^1[3-9]\d{9}$/;
|
|
2905
|
+
/**
|
|
2906
|
+
* 匹配身份证号
|
|
2907
|
+
*/
|
|
2908
|
+
var idCard = /^\d{17}[\dXx]|\d{15}$/;
|
|
2909
|
+
/**
|
|
2910
|
+
* 匹配邮箱
|
|
2911
|
+
*/
|
|
2912
|
+
var email = /^[a-zA-Z0-9_.-]+@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*\.[a-zA-Z0-9]{2,6}$/;
|
|
2913
|
+
/**
|
|
2914
|
+
* 匹配 URL
|
|
2915
|
+
*/
|
|
2916
|
+
var url = /^https?:\/\/[^\s/$.?#].[^\s]*$/;
|
|
2750
2917
|
|
|
2751
|
-
export { HAS_FEILD,
|
|
2918
|
+
export { HAS_FEILD, InputLegalityValidate, InputLengthValidate, LENGTH_LIMIT, LOGIN_TYPE, Mask, RecordType, Request, RequestChain, Tour, addURLParams, countUp, dataHandler, debounce, deepMerge, deleteURLParams, download, email, findTreeDataNode, findTreeDataNodeName, getURLParams, hasRepeatArray, idCard, ip, isMobileDevice, isNull, objectArrayToString, phone, throttle, url, useCountDown, useDownload, zhLetterNumber };
|
package/dist/index.umd.js
CHANGED
|
@@ -341,6 +341,52 @@
|
|
|
341
341
|
return RequestChain;
|
|
342
342
|
}());
|
|
343
343
|
|
|
344
|
+
function download(url, filename, success) {
|
|
345
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
346
|
+
var blob;
|
|
347
|
+
return __generator(this, function (_a) {
|
|
348
|
+
switch (_a.label) {
|
|
349
|
+
case 0: return [4 /*yield*/, getBlob(url)];
|
|
350
|
+
case 1:
|
|
351
|
+
blob = _a.sent();
|
|
352
|
+
save(blob, filename);
|
|
353
|
+
success === null || success === void 0 ? void 0 : success(blob);
|
|
354
|
+
return [2 /*return*/];
|
|
355
|
+
}
|
|
356
|
+
});
|
|
357
|
+
});
|
|
358
|
+
}
|
|
359
|
+
function getBlob(url) {
|
|
360
|
+
return new Promise(function (resolve, reject) {
|
|
361
|
+
var xhr = new XMLHttpRequest();
|
|
362
|
+
xhr.open('GET', url, true);
|
|
363
|
+
xhr.responseType = 'blob';
|
|
364
|
+
xhr.onload = function () {
|
|
365
|
+
if (xhr.status === 200) {
|
|
366
|
+
resolve(xhr.response);
|
|
367
|
+
}
|
|
368
|
+
else {
|
|
369
|
+
reject(new Error("Request failed with status ".concat(xhr.status)));
|
|
370
|
+
}
|
|
371
|
+
};
|
|
372
|
+
xhr.onerror = function () {
|
|
373
|
+
reject(new Error('Request failed'));
|
|
374
|
+
};
|
|
375
|
+
xhr.send();
|
|
376
|
+
});
|
|
377
|
+
}
|
|
378
|
+
function save(blob, filename) {
|
|
379
|
+
var link = document.createElement('a');
|
|
380
|
+
var body = document.body;
|
|
381
|
+
link.href = window.URL.createObjectURL(blob);
|
|
382
|
+
link.download = filename;
|
|
383
|
+
link.style.display = 'none';
|
|
384
|
+
body.appendChild(link);
|
|
385
|
+
link.click();
|
|
386
|
+
body.removeChild(link);
|
|
387
|
+
window.URL.revokeObjectURL(link.href);
|
|
388
|
+
}
|
|
389
|
+
|
|
344
390
|
/**
|
|
345
391
|
*
|
|
346
392
|
* @param {number} num 倒计时时间
|
|
@@ -369,6 +415,21 @@
|
|
|
369
415
|
};
|
|
370
416
|
return { countdownText: countdownText, disabled: disabled, send: send };
|
|
371
417
|
}
|
|
418
|
+
function useDownload() {
|
|
419
|
+
var loading = vue.ref(false);
|
|
420
|
+
var downloadFile = function (url, filename, success) {
|
|
421
|
+
var _filename = filename || 'download_' + new Date().getTime();
|
|
422
|
+
loading.value = true;
|
|
423
|
+
download(url, _filename, function (blob) {
|
|
424
|
+
loading.value = false;
|
|
425
|
+
success === null || success === void 0 ? void 0 : success(blob);
|
|
426
|
+
});
|
|
427
|
+
};
|
|
428
|
+
return {
|
|
429
|
+
loading: loading,
|
|
430
|
+
downloadFile: downloadFile
|
|
431
|
+
};
|
|
432
|
+
}
|
|
372
433
|
|
|
373
434
|
exports.RecordType = void 0;
|
|
374
435
|
(function (RecordType) {
|
|
@@ -912,7 +973,7 @@
|
|
|
912
973
|
if (isOpen)
|
|
913
974
|
ws.send(JSON.stringify(data));
|
|
914
975
|
}
|
|
915
|
-
function
|
|
976
|
+
function useOnMessage(ws, callback) {
|
|
916
977
|
try {
|
|
917
978
|
ws.onmessage = function (e) {
|
|
918
979
|
var data = JSON.parse(e.data);
|
|
@@ -923,48 +984,164 @@
|
|
|
923
984
|
console.error(error);
|
|
924
985
|
}
|
|
925
986
|
}
|
|
926
|
-
function
|
|
987
|
+
function useClose(ws, code, message) {
|
|
927
988
|
code = code || 1000;
|
|
928
989
|
message = message || 'connection closed by client';
|
|
929
990
|
ws.close(code, message);
|
|
930
991
|
}
|
|
931
992
|
|
|
993
|
+
var countUp = function (start, end, callback) {
|
|
994
|
+
var current = start;
|
|
995
|
+
var run = function () {
|
|
996
|
+
if (current >= end) {
|
|
997
|
+
clearInterval(timer);
|
|
998
|
+
}
|
|
999
|
+
else if (current >= end - 16 && current < end - 6) {
|
|
1000
|
+
clearInterval(timer);
|
|
1001
|
+
timer = setInterval(run, 90);
|
|
1002
|
+
}
|
|
1003
|
+
else if (current >= end - 6) {
|
|
1004
|
+
clearInterval(timer);
|
|
1005
|
+
timer = setInterval(run, 200);
|
|
1006
|
+
}
|
|
1007
|
+
callback(current++);
|
|
1008
|
+
};
|
|
1009
|
+
var timer = setInterval(run, 16);
|
|
1010
|
+
};
|
|
1011
|
+
// if (!Date.now){
|
|
1012
|
+
// Date.now = function () {
|
|
1013
|
+
// return new Date().getTime();
|
|
1014
|
+
// };
|
|
1015
|
+
// }
|
|
1016
|
+
// (function () {
|
|
1017
|
+
// 'use strict';
|
|
1018
|
+
// var vendors = ['webkit', 'moz'];
|
|
1019
|
+
// for (var i = 0; i < vendors.length && !window.requestAnimationFrame; ++i) {
|
|
1020
|
+
// var vp = vendors[i];
|
|
1021
|
+
// (window as any)[vp + 'RequestAnimationFrame'];
|
|
1022
|
+
// window.cancelAnimationFrame = (
|
|
1023
|
+
// (window as any)[vp + 'CancelAnimationFrame'] ||
|
|
1024
|
+
// (window as any)[vp + 'CancelRequestAnimationFrame']
|
|
1025
|
+
// )
|
|
1026
|
+
// }
|
|
1027
|
+
// if (
|
|
1028
|
+
// /iP(ad|hone|od).*OS 6/.test(window.navigator.userAgent) ||
|
|
1029
|
+
// !window.requestAnimationFrame ||
|
|
1030
|
+
// !window.cancelAnimationFrame
|
|
1031
|
+
// ) {
|
|
1032
|
+
// var lastTime = 0;
|
|
1033
|
+
// window.requestAnimationFrame = function (callback: FrameRequestCallback): any {
|
|
1034
|
+
// var now = Date.now();
|
|
1035
|
+
// var nextTime = Math.max(lastTime + 16, now);
|
|
1036
|
+
// return setTimeout( function () {
|
|
1037
|
+
// callback(lastTime = nextTime);
|
|
1038
|
+
// },nextTime - now);
|
|
1039
|
+
// }
|
|
1040
|
+
// window.cancelAnimationFrame = clearTimeout;
|
|
1041
|
+
// }
|
|
1042
|
+
// }())
|
|
1043
|
+
|
|
1044
|
+
function hasRepeatArray(arr, keys) {
|
|
1045
|
+
var map = new Map();
|
|
1046
|
+
var _loop_1 = function (item) {
|
|
1047
|
+
var val = (keys === null || keys === void 0 ? void 0 : keys.map(function (key) { return item[key]; }).join(',')) || item;
|
|
1048
|
+
if (map.has(val)) {
|
|
1049
|
+
return { value: [true, val.split(',')] };
|
|
1050
|
+
}
|
|
1051
|
+
map.set(val, item);
|
|
1052
|
+
};
|
|
1053
|
+
for (var _i = 0, arr_1 = arr; _i < arr_1.length; _i++) {
|
|
1054
|
+
var item = arr_1[_i];
|
|
1055
|
+
var state_1 = _loop_1(item);
|
|
1056
|
+
if (typeof state_1 === "object")
|
|
1057
|
+
return state_1.value;
|
|
1058
|
+
}
|
|
1059
|
+
return [false];
|
|
1060
|
+
}
|
|
1061
|
+
|
|
1062
|
+
function addURLParams(params, url) {
|
|
1063
|
+
url = url || window.location.href;
|
|
1064
|
+
var urlParams = getURLParams(url);
|
|
1065
|
+
var queryString = new URLSearchParams(Object.entries(__assign(__assign({}, urlParams), params))).toString();
|
|
1066
|
+
return {
|
|
1067
|
+
url: "".concat(url, "?").concat(queryString),
|
|
1068
|
+
queryString: queryString,
|
|
1069
|
+
};
|
|
1070
|
+
}
|
|
1071
|
+
function getURLParams(url) {
|
|
1072
|
+
url = url || window.location.href;
|
|
1073
|
+
var urlString = url.split('?')[1];
|
|
1074
|
+
var urlSearchParams = new URLSearchParams(urlString);
|
|
1075
|
+
var result = Object.fromEntries(urlSearchParams.entries());
|
|
1076
|
+
return result;
|
|
1077
|
+
}
|
|
1078
|
+
function deleteURLParams(keys, url) {
|
|
1079
|
+
url = url || window.location.href;
|
|
1080
|
+
var newUrl = new URL(url);
|
|
1081
|
+
var params = new URLSearchParams(newUrl.search);
|
|
1082
|
+
keys.forEach(function (key) { return params.delete(key); });
|
|
1083
|
+
newUrl.search = params.toString();
|
|
1084
|
+
return newUrl;
|
|
1085
|
+
}
|
|
1086
|
+
|
|
932
1087
|
/**
|
|
933
1088
|
* 匹配中文字母数字
|
|
934
1089
|
*/
|
|
935
|
-
var
|
|
1090
|
+
var zhLetterNumber = /^[\u4E00-\u9FA5\w]+$/;
|
|
936
1091
|
/**
|
|
937
1092
|
* 匹配 IP
|
|
938
1093
|
*/
|
|
939
|
-
var
|
|
1094
|
+
var ip = /^(?:(?:25[0-5]|2[0-4]\d|[01]?\d{1,2})\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d{1,2})$/;
|
|
940
1095
|
/**
|
|
941
1096
|
* 匹配手机号
|
|
942
1097
|
*/
|
|
943
|
-
var
|
|
1098
|
+
var phone = /^1[3-9]\d{9}$/;
|
|
1099
|
+
/**
|
|
1100
|
+
* 匹配身份证号
|
|
1101
|
+
*/
|
|
1102
|
+
var idCard = /^\d{17}[\dXx]|\d{15}$/;
|
|
1103
|
+
/**
|
|
1104
|
+
* 匹配邮箱
|
|
1105
|
+
*/
|
|
1106
|
+
var email = /^[a-zA-Z0-9_.-]+@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*\.[a-zA-Z0-9]{2,6}$/;
|
|
1107
|
+
/**
|
|
1108
|
+
* 匹配 URL
|
|
1109
|
+
*/
|
|
1110
|
+
var url = /^https?:\/\/[^\s/$.?#].[^\s]*$/;
|
|
944
1111
|
|
|
945
|
-
exports.IP = IP;
|
|
946
1112
|
exports.InputLegalityValidate = InputLegalityValidate;
|
|
947
1113
|
exports.InputLengthValidate = InputLengthValidate;
|
|
948
1114
|
exports.Mask = Mask;
|
|
949
|
-
exports.PHONE = PHONE;
|
|
950
1115
|
exports.Request = Request;
|
|
951
1116
|
exports.RequestChain = RequestChain;
|
|
952
1117
|
exports.Tour = Tour;
|
|
953
|
-
exports.
|
|
1118
|
+
exports.addURLParams = addURLParams;
|
|
1119
|
+
exports.countUp = countUp;
|
|
954
1120
|
exports.createWebSocket = createWebSocket;
|
|
955
1121
|
exports.dataHandler = dataHandler;
|
|
956
1122
|
exports.debounce = debounce;
|
|
957
1123
|
exports.deepMerge = deepMerge;
|
|
1124
|
+
exports.deleteURLParams = deleteURLParams;
|
|
1125
|
+
exports.download = download;
|
|
1126
|
+
exports.email = email;
|
|
958
1127
|
exports.findTreeDataNode = findTreeDataNode;
|
|
959
1128
|
exports.findTreeDataNodeName = findTreeDataNodeName;
|
|
960
1129
|
exports.getState = getState;
|
|
1130
|
+
exports.getURLParams = getURLParams;
|
|
1131
|
+
exports.hasRepeatArray = hasRepeatArray;
|
|
1132
|
+
exports.idCard = idCard;
|
|
1133
|
+
exports.ip = ip;
|
|
961
1134
|
exports.isMobileDevice = isMobileDevice;
|
|
962
1135
|
exports.isNull = isNull;
|
|
963
1136
|
exports.objectArrayToString = objectArrayToString;
|
|
1137
|
+
exports.phone = phone;
|
|
964
1138
|
exports.throttle = throttle;
|
|
1139
|
+
exports.url = url;
|
|
1140
|
+
exports.useClose = useClose;
|
|
965
1141
|
exports.useCountDown = useCountDown;
|
|
1142
|
+
exports.useDownload = useDownload;
|
|
1143
|
+
exports.useOnMessage = useOnMessage;
|
|
966
1144
|
exports.useSendMessage = useSendMessage;
|
|
967
|
-
exports.
|
|
968
|
-
exports.useWebSocketMessage = useWebSocketMessage;
|
|
1145
|
+
exports.zhLetterNumber = zhLetterNumber;
|
|
969
1146
|
|
|
970
1147
|
}));
|
|
@@ -1,12 +1,24 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* 匹配中文字母数字
|
|
3
3
|
*/
|
|
4
|
-
export declare const
|
|
4
|
+
export declare const zhLetterNumber: RegExp;
|
|
5
5
|
/**
|
|
6
6
|
* 匹配 IP
|
|
7
7
|
*/
|
|
8
|
-
export declare const
|
|
8
|
+
export declare const ip: RegExp;
|
|
9
9
|
/**
|
|
10
10
|
* 匹配手机号
|
|
11
11
|
*/
|
|
12
|
-
export declare const
|
|
12
|
+
export declare const phone: RegExp;
|
|
13
|
+
/**
|
|
14
|
+
* 匹配身份证号
|
|
15
|
+
*/
|
|
16
|
+
export declare const idCard: RegExp;
|
|
17
|
+
/**
|
|
18
|
+
* 匹配邮箱
|
|
19
|
+
*/
|
|
20
|
+
export declare const email: RegExp;
|
|
21
|
+
/**
|
|
22
|
+
* 匹配 URL
|
|
23
|
+
*/
|
|
24
|
+
export declare const url: RegExp;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function hasRepeatArray(arr: any[], keys?: string[]): any[];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function download(url: string, filename: string, success?: (blob: Blob) => void): Promise<void>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const countUp: (start: number, end: number, callback: (current: number) => void) => void;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
type TAddURLParamsReturn = {
|
|
2
|
+
url: string;
|
|
3
|
+
queryString: string;
|
|
4
|
+
};
|
|
5
|
+
export declare function addURLParams(params: Record<string, any>, url?: string): TAddURLParamsReturn;
|
|
6
|
+
export declare function getURLParams(url?: string): Record<string, any>;
|
|
7
|
+
export declare function deleteURLParams(keys: string[], url?: string): URL;
|
|
8
|
+
export {};
|
|
@@ -12,4 +12,8 @@ interface CountDown {
|
|
|
12
12
|
* @description 发送验证码倒计时
|
|
13
13
|
*/
|
|
14
14
|
export declare function useCountDown(num: number, text?: string): CountDown;
|
|
15
|
+
export declare function useDownload(): {
|
|
16
|
+
loading: Ref<boolean, boolean>;
|
|
17
|
+
downloadFile: (url: string, filename?: string, success?: (blob: Blob) => void) => void;
|
|
18
|
+
};
|
|
15
19
|
export {};
|
package/dist/types/utils/ws.d.ts
CHANGED
|
@@ -9,6 +9,6 @@ interface WebSocketConfig {
|
|
|
9
9
|
export declare function createWebSocket(url: string, config: WebSocketConfig | null, onOpen?: Function | null): WebSocket;
|
|
10
10
|
export declare function getState(ws: WebSocket, type: WebSocketState): boolean;
|
|
11
11
|
export declare function useSendMessage(ws: WebSocket, data: any): void;
|
|
12
|
-
export declare function
|
|
13
|
-
export declare function
|
|
12
|
+
export declare function useOnMessage(ws: WebSocket, callback: Function): void;
|
|
13
|
+
export declare function useClose(ws: WebSocket, code?: number, message?: string): void;
|
|
14
14
|
export {};
|
|
@@ -148,7 +148,7 @@ function useSendMessage(ws, data) {
|
|
|
148
148
|
if (isOpen)
|
|
149
149
|
ws.send(JSON.stringify(data));
|
|
150
150
|
}
|
|
151
|
-
function
|
|
151
|
+
function useOnMessage(ws, callback) {
|
|
152
152
|
try {
|
|
153
153
|
ws.onmessage = function (e) {
|
|
154
154
|
var data = JSON.parse(e.data);
|
|
@@ -159,10 +159,10 @@ function useWebSocketMessage(ws, callback) {
|
|
|
159
159
|
console.error(error);
|
|
160
160
|
}
|
|
161
161
|
}
|
|
162
|
-
function
|
|
162
|
+
function useClose(ws, code, message) {
|
|
163
163
|
code = code || 1000;
|
|
164
164
|
message = message || 'connection closed by client';
|
|
165
165
|
ws.close(code, message);
|
|
166
166
|
}
|
|
167
167
|
|
|
168
|
-
export { __assign as _, __awaiter as a, __generator as b, createWebSocket as c,
|
|
168
|
+
export { __assign as _, __awaiter as a, __generator as b, createWebSocket as c, useOnMessage as d, useClose as e, getState as g, useSendMessage as u };
|
package/dist/ws.d.ts
CHANGED
|
@@ -9,7 +9,7 @@ interface WebSocketConfig {
|
|
|
9
9
|
declare function createWebSocket(url: string, config: WebSocketConfig | null, onOpen?: Function | null): WebSocket;
|
|
10
10
|
declare function getState(ws: WebSocket, type: WebSocketState): boolean;
|
|
11
11
|
declare function useSendMessage(ws: WebSocket, data: any): void;
|
|
12
|
-
declare function
|
|
13
|
-
declare function
|
|
12
|
+
declare function useOnMessage(ws: WebSocket, callback: Function): void;
|
|
13
|
+
declare function useClose(ws: WebSocket, code?: number, message?: string): void;
|
|
14
14
|
|
|
15
|
-
export { createWebSocket, getState,
|
|
15
|
+
export { createWebSocket, getState, useClose, useOnMessage, useSendMessage };
|
package/dist/ws.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { c as createWebSocket, g as getState,
|
|
1
|
+
export { c as createWebSocket, g as getState, e as useClose, d as useOnMessage, u as useSendMessage } from './ws-DGDUMiR9.js';
|
package/dist/ws.umd.js
CHANGED
|
@@ -116,7 +116,7 @@
|
|
|
116
116
|
if (isOpen)
|
|
117
117
|
ws.send(JSON.stringify(data));
|
|
118
118
|
}
|
|
119
|
-
function
|
|
119
|
+
function useOnMessage(ws, callback) {
|
|
120
120
|
try {
|
|
121
121
|
ws.onmessage = function (e) {
|
|
122
122
|
var data = JSON.parse(e.data);
|
|
@@ -127,7 +127,7 @@
|
|
|
127
127
|
console.error(error);
|
|
128
128
|
}
|
|
129
129
|
}
|
|
130
|
-
function
|
|
130
|
+
function useClose(ws, code, message) {
|
|
131
131
|
code = code || 1000;
|
|
132
132
|
message = message || 'connection closed by client';
|
|
133
133
|
ws.close(code, message);
|
|
@@ -135,8 +135,8 @@
|
|
|
135
135
|
|
|
136
136
|
exports.createWebSocket = createWebSocket;
|
|
137
137
|
exports.getState = getState;
|
|
138
|
+
exports.useClose = useClose;
|
|
139
|
+
exports.useOnMessage = useOnMessage;
|
|
138
140
|
exports.useSendMessage = useSendMessage;
|
|
139
|
-
exports.useWebSocketClose = useWebSocketClose;
|
|
140
|
-
exports.useWebSocketMessage = useWebSocketMessage;
|
|
141
141
|
|
|
142
142
|
}));
|