@fast-china/utils 1.0.3 → 1.0.5
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.global.js +197 -142
- package/dist/index.global.js.map +1 -1
- package/dist/index.global.min.js +5 -5
- package/dist/index.global.min.js.map +1 -1
- package/es/array/index.d.ts +19 -0
- package/es/array/index.mjs +33 -0
- package/es/array/index.mjs.map +1 -0
- package/es/base64/index.d.ts +9 -0
- package/es/base64/index.mjs +6 -0
- package/es/base64/index.mjs.map +1 -1
- package/es/click/index.d.ts +3 -0
- package/es/click/index.mjs.map +1 -1
- package/es/color/index.d.ts +3 -0
- package/es/color/index.mjs +5 -4
- package/es/color/index.mjs.map +1 -1
- package/es/date/index.d.ts +17 -0
- package/es/date/index.mjs +17 -0
- package/es/date/index.mjs.map +1 -1
- package/es/env/index.d.ts +25 -0
- package/es/env/index.mjs +38 -0
- package/es/env/index.mjs.map +1 -0
- package/es/identity/index.d.ts +8 -0
- package/es/identity/index.mjs +33 -0
- package/es/identity/index.mjs.map +1 -0
- package/es/index.d.ts +3 -0
- package/es/index.mjs +6 -0
- package/es/index.mjs.map +1 -1
- package/es/object/index.d.ts +0 -12
- package/es/object/index.mjs +0 -97
- package/es/object/index.mjs.map +1 -1
- package/es/storage/index.mjs +3 -2
- package/es/storage/index.mjs.map +1 -1
- package/es/string/index.d.ts +21 -0
- package/es/string/index.mjs +37 -0
- package/es/string/index.mjs.map +1 -1
- package/es/vue/useRender.mjs +2 -1
- package/es/vue/useRender.mjs.map +1 -1
- package/lib/array/index.d.ts +19 -0
- package/lib/array/index.js +2 -0
- package/lib/array/index.js.map +1 -0
- package/lib/base64/index.d.ts +9 -0
- package/lib/base64/index.js.map +1 -1
- package/lib/click/index.d.ts +3 -0
- package/lib/click/index.js.map +1 -1
- package/lib/color/index.d.ts +3 -0
- package/lib/color/index.js +1 -1
- package/lib/color/index.js.map +1 -1
- package/lib/date/index.d.ts +17 -0
- package/lib/date/index.js.map +1 -1
- package/lib/env/index.d.ts +25 -0
- package/lib/env/index.js +2 -0
- package/lib/env/index.js.map +1 -0
- package/lib/identity/index.d.ts +8 -0
- package/lib/identity/index.js +2 -0
- package/lib/identity/index.js.map +1 -0
- package/lib/index.d.ts +3 -0
- package/lib/index.js +1 -1
- package/lib/object/index.d.ts +0 -12
- package/lib/object/index.js +1 -1
- package/lib/object/index.js.map +1 -1
- package/lib/storage/index.js +1 -1
- package/lib/storage/index.js.map +1 -1
- package/lib/string/index.d.ts +21 -0
- package/lib/string/index.js +1 -1
- package/lib/string/index.js.map +1 -1
- package/lib/vue/useRender.js +1 -1
- package/lib/vue/useRender.js.map +1 -1
- package/package.json +8 -8
package/dist/index.global.js
CHANGED
|
@@ -1,5 +1,34 @@
|
|
|
1
1
|
var FastUtils = function(exports, vue) {
|
|
2
2
|
"use strict";
|
|
3
|
+
const arrayUtil = {
|
|
4
|
+
/**
|
|
5
|
+
* 是否存在重复值
|
|
6
|
+
* @param arr 数组
|
|
7
|
+
* @param prop 属性
|
|
8
|
+
* @returns
|
|
9
|
+
*/
|
|
10
|
+
hasDuplicateProperty(arr, prop) {
|
|
11
|
+
const values2 = arr.map((obj) => obj[prop]);
|
|
12
|
+
const uniqueValues = new Set(values2);
|
|
13
|
+
return values2.length !== uniqueValues.size;
|
|
14
|
+
},
|
|
15
|
+
/**
|
|
16
|
+
* 是否存在非重复值
|
|
17
|
+
* @param arr 数组
|
|
18
|
+
* @param prop 属性
|
|
19
|
+
* @returns
|
|
20
|
+
*/
|
|
21
|
+
hasDifferentProperty(arr, prop) {
|
|
22
|
+
const valueSet = /* @__PURE__ */ new Set();
|
|
23
|
+
for (const obj of arr) {
|
|
24
|
+
valueSet.add(obj[prop]);
|
|
25
|
+
if (valueSet.size > 1) {
|
|
26
|
+
return true;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
};
|
|
3
32
|
const b64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
|
|
4
33
|
const b64re = /^(?:[A-Za-z\d+/]{4})*?(?:[A-Za-z\d+/]{2}(?:==)?|[A-Za-z\d+/]{3}=?)?$/;
|
|
5
34
|
const base64PwdDic = [
|
|
@@ -74,6 +103,9 @@ var FastUtils = function(exports, vue) {
|
|
|
74
103
|
return result2;
|
|
75
104
|
}
|
|
76
105
|
const base64Util = {
|
|
106
|
+
/**
|
|
107
|
+
* 将字符串编码为Base64格式
|
|
108
|
+
*/
|
|
77
109
|
bota(string2) {
|
|
78
110
|
string2 = String(string2);
|
|
79
111
|
let bitmap, a, b, c, result2 = "", i = 0, rest2 = string2.length % 3;
|
|
@@ -87,6 +119,9 @@ var FastUtils = function(exports, vue) {
|
|
|
87
119
|
}
|
|
88
120
|
return rest2 ? result2.slice(0, rest2 - 3) + "===".substring(rest2) : result2;
|
|
89
121
|
},
|
|
122
|
+
/**
|
|
123
|
+
* 将Base64编码的字符串解码回其原始格式。
|
|
124
|
+
*/
|
|
90
125
|
atob(string2) {
|
|
91
126
|
string2 = String(string2).replace(/[\t\n\f\r ]+/g, "");
|
|
92
127
|
if (!b64re.test(string2)) throw new TypeError("Failed to execute 'atob' on 'Window': The string to be decoded is not correctly encoded.");
|
|
@@ -206,6 +241,12 @@ var FastUtils = function(exports, vue) {
|
|
|
206
241
|
});
|
|
207
242
|
}
|
|
208
243
|
};
|
|
244
|
+
class FastError extends Error {
|
|
245
|
+
constructor(m) {
|
|
246
|
+
super(m);
|
|
247
|
+
this.name = "FastError";
|
|
248
|
+
}
|
|
249
|
+
}
|
|
209
250
|
const colorUtil = {
|
|
210
251
|
/**
|
|
211
252
|
* hex颜色转rgb颜色
|
|
@@ -215,7 +256,7 @@ var FastUtils = function(exports, vue) {
|
|
|
215
256
|
hexToRgb(str) {
|
|
216
257
|
let hex = "";
|
|
217
258
|
const reg = /^#?[0-9A-Fa-f]{6}$/;
|
|
218
|
-
if (!reg.test(str)) throw new
|
|
259
|
+
if (!reg.test(str)) throw new FastError("输入错误的hex");
|
|
219
260
|
str = str.replace("#", "");
|
|
220
261
|
hex = str.match(/../g);
|
|
221
262
|
for (let i = 0; i < 3; i++) hex[i] = parseInt(hex[i], 16);
|
|
@@ -230,7 +271,7 @@ var FastUtils = function(exports, vue) {
|
|
|
230
271
|
*/
|
|
231
272
|
rgbToHex(r, g, b) {
|
|
232
273
|
const reg = /^\d{1,3}$/;
|
|
233
|
-
if (!reg.test(r) || !reg.test(g) || !reg.test(b)) throw new
|
|
274
|
+
if (!reg.test(r) || !reg.test(g) || !reg.test(b)) throw new FastError("输入错误的rgb颜色值");
|
|
234
275
|
const hex = [r.toString(16), g.toString(16), b.toString(16)];
|
|
235
276
|
for (let i = 0; i < 3; i++) if (hex[i].length === 1) hex[i] = `0${hex[i]}`;
|
|
236
277
|
return `#${hex.join("")}`;
|
|
@@ -243,7 +284,7 @@ var FastUtils = function(exports, vue) {
|
|
|
243
284
|
*/
|
|
244
285
|
getDarkColor(color, level) {
|
|
245
286
|
const reg = /^#?[0-9A-Fa-f]{6}$/;
|
|
246
|
-
if (!reg.test(color)) throw new
|
|
287
|
+
if (!reg.test(color)) throw new FastError("输入错误的hex颜色值");
|
|
247
288
|
const rgb = this.hexToRgb(color);
|
|
248
289
|
for (let i = 0; i < 3; i++) rgb[i] = Math.round(20.5 * level + rgb[i] * (1 - level));
|
|
249
290
|
return this.rgbToHex(rgb[0], rgb[1], rgb[2]);
|
|
@@ -256,7 +297,7 @@ var FastUtils = function(exports, vue) {
|
|
|
256
297
|
*/
|
|
257
298
|
getLightColor(color, level) {
|
|
258
299
|
const reg = /^#?[0-9A-Fa-f]{6}$/;
|
|
259
|
-
if (!reg.test(color)) throw new
|
|
300
|
+
if (!reg.test(color)) throw new FastError("输入错误的hex颜色值");
|
|
260
301
|
const rgb = this.hexToRgb(color);
|
|
261
302
|
for (let i = 0; i < 3; i++) rgb[i] = Math.round(255 * level + rgb[i] * (1 - level));
|
|
262
303
|
return this.rgbToHex(rgb[0], rgb[1], rgb[2]);
|
|
@@ -6287,12 +6328,6 @@ var FastUtils = function(exports, vue) {
|
|
|
6287
6328
|
* Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
|
|
6288
6329
|
* Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
|
|
6289
6330
|
*/
|
|
6290
|
-
class FastError extends Error {
|
|
6291
|
-
constructor(m) {
|
|
6292
|
-
super(m);
|
|
6293
|
-
this.name = "FastError";
|
|
6294
|
-
}
|
|
6295
|
-
}
|
|
6296
6331
|
const consoleLog = (name, message, error) => {
|
|
6297
6332
|
if (error) {
|
|
6298
6333
|
console.log(`[Fast-Log-${name}]${message ? ` ${message}` : ""}`, error);
|
|
@@ -13319,6 +13354,10 @@ var FastUtils = function(exports, vue) {
|
|
|
13319
13354
|
return "";
|
|
13320
13355
|
}
|
|
13321
13356
|
},
|
|
13357
|
+
/**
|
|
13358
|
+
* 获取默认时间
|
|
13359
|
+
* @returns [00:00:00, 23:59:59]
|
|
13360
|
+
*/
|
|
13322
13361
|
getDefaultTime() {
|
|
13323
13362
|
const end = /* @__PURE__ */ new Date();
|
|
13324
13363
|
const start = /* @__PURE__ */ new Date();
|
|
@@ -13327,11 +13366,18 @@ var FastUtils = function(exports, vue) {
|
|
|
13327
13366
|
end.setHours(23, 59, 59);
|
|
13328
13367
|
return [start, end];
|
|
13329
13368
|
},
|
|
13369
|
+
/**
|
|
13370
|
+
* 获取简单的日期时间
|
|
13371
|
+
* @returns xxxx-xx-xx 00:00:00
|
|
13372
|
+
*/
|
|
13330
13373
|
getSimpleTime() {
|
|
13331
13374
|
const start = /* @__PURE__ */ new Date();
|
|
13332
13375
|
start.setHours(0, 0, 0);
|
|
13333
13376
|
return start;
|
|
13334
13377
|
},
|
|
13378
|
+
/**
|
|
13379
|
+
* 获取简单的日期时间范围
|
|
13380
|
+
*/
|
|
13335
13381
|
getSimpleShortcuts() {
|
|
13336
13382
|
return [
|
|
13337
13383
|
{
|
|
@@ -13380,6 +13426,9 @@ var FastUtils = function(exports, vue) {
|
|
|
13380
13426
|
}
|
|
13381
13427
|
];
|
|
13382
13428
|
},
|
|
13429
|
+
/**
|
|
13430
|
+
* 获取日期范围
|
|
13431
|
+
*/
|
|
13383
13432
|
getShortcuts() {
|
|
13384
13433
|
return [
|
|
13385
13434
|
{
|
|
@@ -13461,6 +13510,9 @@ var FastUtils = function(exports, vue) {
|
|
|
13461
13510
|
}
|
|
13462
13511
|
];
|
|
13463
13512
|
},
|
|
13513
|
+
/**
|
|
13514
|
+
* 判断传入的时间是否大于当前时间
|
|
13515
|
+
*/
|
|
13464
13516
|
getDisabledDate(time) {
|
|
13465
13517
|
return time.getTime() > Date.now();
|
|
13466
13518
|
}
|
|
@@ -13480,127 +13532,47 @@ var FastUtils = function(exports, vue) {
|
|
|
13480
13532
|
}
|
|
13481
13533
|
consoleWarn("document", "binding value must be a string or number");
|
|
13482
13534
|
};
|
|
13483
|
-
const
|
|
13535
|
+
const envUtil = {
|
|
13484
13536
|
/**
|
|
13485
|
-
*
|
|
13537
|
+
* 是否为 Uni 环境
|
|
13538
|
+
* @returns
|
|
13486
13539
|
*/
|
|
13487
|
-
|
|
13488
|
-
|
|
13489
|
-
for (const key in obj) {
|
|
13490
|
-
if (Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
13491
|
-
if (params !== "") {
|
|
13492
|
-
params += "&";
|
|
13493
|
-
}
|
|
13494
|
-
params += `${encodeURIComponent(key)}=${encodeURIComponent(obj[key])}`;
|
|
13495
|
-
}
|
|
13496
|
-
}
|
|
13497
|
-
return params;
|
|
13540
|
+
isUni() {
|
|
13541
|
+
return typeof uni !== "undefined";
|
|
13498
13542
|
},
|
|
13499
13543
|
/**
|
|
13500
|
-
*
|
|
13544
|
+
* 是否为 Web 环境(浏览器环境)
|
|
13545
|
+
* @returns
|
|
13501
13546
|
*/
|
|
13502
|
-
|
|
13503
|
-
|
|
13504
|
-
const uniqueValues = new Set(values2);
|
|
13505
|
-
return values2.length !== uniqueValues.size;
|
|
13547
|
+
isWeb() {
|
|
13548
|
+
return typeof window !== "undefined" && typeof window.document !== "undefined";
|
|
13506
13549
|
},
|
|
13507
13550
|
/**
|
|
13508
|
-
*
|
|
13551
|
+
* 是否为手机设备
|
|
13552
|
+
* @returns
|
|
13509
13553
|
*/
|
|
13510
|
-
|
|
13511
|
-
|
|
13512
|
-
|
|
13513
|
-
|
|
13514
|
-
if (valueSet.size > 1) {
|
|
13515
|
-
return true;
|
|
13516
|
-
}
|
|
13517
|
-
}
|
|
13518
|
-
return false;
|
|
13554
|
+
isMobile() {
|
|
13555
|
+
if (!this.isWeb()) return false;
|
|
13556
|
+
const ua = navigator.userAgent || "";
|
|
13557
|
+
return /Mobile|iPhone|Android.*Mobile|Windows Phone/i.test(ua);
|
|
13519
13558
|
},
|
|
13520
13559
|
/**
|
|
13521
|
-
*
|
|
13560
|
+
* 是否为平板设备
|
|
13561
|
+
* @returns
|
|
13522
13562
|
*/
|
|
13523
|
-
|
|
13524
|
-
if (
|
|
13525
|
-
|
|
13526
|
-
|
|
13527
|
-
}
|
|
13528
|
-
let timestamp = date2.getTime();
|
|
13529
|
-
if (timestamp.toString().length < 13) {
|
|
13530
|
-
const arrTimestamp = timestamp.toString().split("");
|
|
13531
|
-
for (let start = 0; start < 13; start++) {
|
|
13532
|
-
if (!arrTimestamp[start]) {
|
|
13533
|
-
arrTimestamp[start] = "0";
|
|
13534
|
-
}
|
|
13535
|
-
}
|
|
13536
|
-
timestamp = parseInt(arrTimestamp.join(""));
|
|
13537
|
-
}
|
|
13538
|
-
const minute = 1e3 * 60;
|
|
13539
|
-
const hour = minute * 60;
|
|
13540
|
-
const day = hour * 24;
|
|
13541
|
-
const month = day * 30;
|
|
13542
|
-
const curTime = (/* @__PURE__ */ new Date()).getTime();
|
|
13543
|
-
const diffValue = curTime - timestamp;
|
|
13544
|
-
const monthC = diffValue / month;
|
|
13545
|
-
const weekC = diffValue / (7 * day);
|
|
13546
|
-
const dayC = diffValue / day;
|
|
13547
|
-
const hourC = diffValue / hour;
|
|
13548
|
-
const minC = diffValue / minute;
|
|
13549
|
-
if (diffValue < 0) {
|
|
13550
|
-
const monthC1 = Math.abs(monthC);
|
|
13551
|
-
const weekC1 = Math.abs(weekC);
|
|
13552
|
-
const dayC1 = Math.abs(dayC);
|
|
13553
|
-
const hourC1 = Math.abs(hourC);
|
|
13554
|
-
const minC1 = Math.abs(minC);
|
|
13555
|
-
if (monthC1 > 12) {
|
|
13556
|
-
return `${parseInt(`${monthC1 / 12}`)}年后`;
|
|
13557
|
-
} else if (monthC1 >= 6) {
|
|
13558
|
-
return "半年后";
|
|
13559
|
-
} else if (monthC1 >= 1) {
|
|
13560
|
-
return `${parseInt(`${monthC1}`)}月后`;
|
|
13561
|
-
} else if (weekC1 > 2) {
|
|
13562
|
-
return "半月后";
|
|
13563
|
-
} else if (weekC1 >= 1) {
|
|
13564
|
-
return `${parseInt(`${weekC1}`)}周后`;
|
|
13565
|
-
} else if (dayC1 >= 1) {
|
|
13566
|
-
return `${parseInt(`${dayC1}`)}天后`;
|
|
13567
|
-
} else if (hourC1 >= 1) {
|
|
13568
|
-
return `${parseInt(`${hourC1}`)}小时后`;
|
|
13569
|
-
} else if (minC1 >= 1) {
|
|
13570
|
-
return `${parseInt(`${minC1}`)}分钟后`;
|
|
13571
|
-
}
|
|
13572
|
-
return "刚刚";
|
|
13573
|
-
}
|
|
13574
|
-
if (monthC > 12) {
|
|
13575
|
-
return `${parseInt(`${monthC / 12}`)}年前`;
|
|
13576
|
-
} else if (monthC >= 6) {
|
|
13577
|
-
return "半年前";
|
|
13578
|
-
} else if (monthC >= 1) {
|
|
13579
|
-
return `${parseInt(`${monthC}`)}月前`;
|
|
13580
|
-
} else if (weekC > 2) {
|
|
13581
|
-
return "半月前";
|
|
13582
|
-
} else if (weekC >= 1) {
|
|
13583
|
-
return `${parseInt(`${weekC}`)}周前`;
|
|
13584
|
-
} else if (dayC >= 1) {
|
|
13585
|
-
return `${parseInt(`${dayC}`)}天前`;
|
|
13586
|
-
} else if (hourC >= 1) {
|
|
13587
|
-
return `${parseInt(`${hourC}`)}小时前`;
|
|
13588
|
-
} else if (minC >= 1) {
|
|
13589
|
-
return `${parseInt(`${minC}`)}分钟前`;
|
|
13590
|
-
}
|
|
13591
|
-
return "刚刚";
|
|
13592
|
-
} else {
|
|
13593
|
-
return "";
|
|
13594
|
-
}
|
|
13563
|
+
isIpad() {
|
|
13564
|
+
if (!this.isWeb()) return false;
|
|
13565
|
+
const ua = navigator.userAgent || "";
|
|
13566
|
+
return /iPad|Android(?!.*Mobile)|Tablet/i.test(ua);
|
|
13595
13567
|
}
|
|
13596
13568
|
};
|
|
13597
|
-
const state = vue.reactive({
|
|
13569
|
+
const state$1 = vue.reactive({
|
|
13598
13570
|
prefix: "fast__",
|
|
13599
13571
|
expireSuffix: "__Expire",
|
|
13600
13572
|
crypto: false
|
|
13601
13573
|
});
|
|
13602
|
-
const CACHE_PREFIX = vue.computed(() => state.prefix);
|
|
13603
|
-
const CACHE_EXPIRE_SUFFIX = vue.computed(() => state.expireSuffix);
|
|
13574
|
+
const CACHE_PREFIX = vue.computed(() => state$1.prefix);
|
|
13575
|
+
const CACHE_EXPIRE_SUFFIX = vue.computed(() => state$1.expireSuffix);
|
|
13604
13576
|
const useStorage = () => {
|
|
13605
13577
|
return {
|
|
13606
13578
|
/**
|
|
@@ -13608,21 +13580,21 @@ var FastUtils = function(exports, vue) {
|
|
|
13608
13580
|
* @param key
|
|
13609
13581
|
*/
|
|
13610
13582
|
prefix(key) {
|
|
13611
|
-
state.prefix = key;
|
|
13583
|
+
state$1.prefix = key;
|
|
13612
13584
|
},
|
|
13613
13585
|
/**
|
|
13614
13586
|
* 缓存过期值后缀 Key
|
|
13615
13587
|
* @param key
|
|
13616
13588
|
*/
|
|
13617
13589
|
expireSuffix(key) {
|
|
13618
|
-
state.expireSuffix = key;
|
|
13590
|
+
state$1.expireSuffix = key;
|
|
13619
13591
|
},
|
|
13620
13592
|
/**
|
|
13621
13593
|
* 设置缓存是否加密
|
|
13622
13594
|
* @param crypto
|
|
13623
13595
|
*/
|
|
13624
13596
|
crypto(crypto) {
|
|
13625
|
-
state.crypto = crypto;
|
|
13597
|
+
state$1.crypto = crypto;
|
|
13626
13598
|
}
|
|
13627
13599
|
};
|
|
13628
13600
|
};
|
|
@@ -13673,23 +13645,23 @@ var FastUtils = function(exports, vue) {
|
|
|
13673
13645
|
*/
|
|
13674
13646
|
set(key, val, expire, encrypt) {
|
|
13675
13647
|
try {
|
|
13676
|
-
encrypt ?? (encrypt = state.crypto);
|
|
13648
|
+
encrypt ?? (encrypt = state$1.crypto);
|
|
13677
13649
|
if (expire) {
|
|
13678
13650
|
if (isNaN(expire) || expire < 1) {
|
|
13679
|
-
throw new
|
|
13651
|
+
throw new FastError("有效期应为一个有效数值");
|
|
13680
13652
|
}
|
|
13681
13653
|
const expireData = {
|
|
13682
13654
|
time: Date.now(),
|
|
13683
13655
|
expire
|
|
13684
13656
|
};
|
|
13685
13657
|
const expireJson = JSON.stringify(expireData);
|
|
13686
|
-
storage.set(`${state.prefix}${key}${state.expireSuffix}`, expireJson);
|
|
13658
|
+
storage.set(`${state$1.prefix}${key}${state$1.expireSuffix}`, expireJson);
|
|
13687
13659
|
}
|
|
13688
13660
|
let valJson = JSON.stringify(val);
|
|
13689
13661
|
if (encrypt) {
|
|
13690
13662
|
valJson = base64Util.toBase64(valJson);
|
|
13691
13663
|
}
|
|
13692
|
-
storage.set(`${state.prefix}${key}`, valJson);
|
|
13664
|
+
storage.set(`${state$1.prefix}${key}`, valJson);
|
|
13693
13665
|
} catch (error) {
|
|
13694
13666
|
consoleError("Local", error);
|
|
13695
13667
|
}
|
|
@@ -13702,18 +13674,18 @@ var FastUtils = function(exports, vue) {
|
|
|
13702
13674
|
*/
|
|
13703
13675
|
get(key, decrypt) {
|
|
13704
13676
|
try {
|
|
13705
|
-
decrypt ?? (decrypt = state.crypto);
|
|
13706
|
-
let valJson = storage.get(`${state.prefix}${key}`);
|
|
13677
|
+
decrypt ?? (decrypt = state$1.crypto);
|
|
13678
|
+
let valJson = storage.get(`${state$1.prefix}${key}`);
|
|
13707
13679
|
if (valJson) {
|
|
13708
13680
|
if (decrypt) {
|
|
13709
13681
|
valJson = base64Util.base64ToStr(valJson);
|
|
13710
13682
|
}
|
|
13711
|
-
const expireJson = storage.get(`${state.prefix}${key}${state.expireSuffix}`);
|
|
13683
|
+
const expireJson = storage.get(`${state$1.prefix}${key}${state$1.expireSuffix}`);
|
|
13712
13684
|
if (expireJson) {
|
|
13713
13685
|
const expireData = JSON.parse(expireJson);
|
|
13714
13686
|
if (Date.now() > expireData.time + expireData.expire * 60 * 1e3) {
|
|
13715
|
-
storage.remove(`${state.prefix}${key}`);
|
|
13716
|
-
storage.remove(`${state.prefix}${key}${state.expireSuffix}`);
|
|
13687
|
+
storage.remove(`${state$1.prefix}${key}`);
|
|
13688
|
+
storage.remove(`${state$1.prefix}${key}${state$1.expireSuffix}`);
|
|
13717
13689
|
return null;
|
|
13718
13690
|
}
|
|
13719
13691
|
}
|
|
@@ -13734,8 +13706,8 @@ var FastUtils = function(exports, vue) {
|
|
|
13734
13706
|
*/
|
|
13735
13707
|
remove(key) {
|
|
13736
13708
|
try {
|
|
13737
|
-
storage.remove(`${state.prefix}${key}`);
|
|
13738
|
-
storage.remove(`${state.prefix}${key}${state.expireSuffix}`);
|
|
13709
|
+
storage.remove(`${state$1.prefix}${key}`);
|
|
13710
|
+
storage.remove(`${state$1.prefix}${key}${state$1.expireSuffix}`);
|
|
13739
13711
|
} catch (error) {
|
|
13740
13712
|
consoleError("Local", error);
|
|
13741
13713
|
}
|
|
@@ -13747,7 +13719,7 @@ var FastUtils = function(exports, vue) {
|
|
|
13747
13719
|
removeByPrefix(key) {
|
|
13748
13720
|
try {
|
|
13749
13721
|
for (const itemKey in storage.keys) {
|
|
13750
|
-
if (itemKey.indexOf(`${state.prefix}${key}`) !== -1) {
|
|
13722
|
+
if (itemKey.indexOf(`${state$1.prefix}${key}`) !== -1) {
|
|
13751
13723
|
storage.remove(itemKey);
|
|
13752
13724
|
}
|
|
13753
13725
|
}
|
|
@@ -13780,23 +13752,23 @@ var FastUtils = function(exports, vue) {
|
|
|
13780
13752
|
return;
|
|
13781
13753
|
}
|
|
13782
13754
|
try {
|
|
13783
|
-
encrypt ?? (encrypt = state.crypto);
|
|
13755
|
+
encrypt ?? (encrypt = state$1.crypto);
|
|
13784
13756
|
if (expire) {
|
|
13785
13757
|
if (isNaN(expire) || expire < 1) {
|
|
13786
|
-
throw new
|
|
13758
|
+
throw new FastError("有效期应为一个有效数值");
|
|
13787
13759
|
}
|
|
13788
13760
|
const expireData = {
|
|
13789
13761
|
time: Date.now(),
|
|
13790
13762
|
expire
|
|
13791
13763
|
};
|
|
13792
13764
|
const expireJson = JSON.stringify(expireData);
|
|
13793
|
-
window.sessionStorage.setItem(`${state.prefix}${key}${state.expireSuffix}`, expireJson);
|
|
13765
|
+
window.sessionStorage.setItem(`${state$1.prefix}${key}${state$1.expireSuffix}`, expireJson);
|
|
13794
13766
|
}
|
|
13795
13767
|
let valJson = JSON.stringify(val);
|
|
13796
13768
|
if (encrypt) {
|
|
13797
13769
|
valJson = base64Util.toBase64(valJson);
|
|
13798
13770
|
}
|
|
13799
|
-
window.sessionStorage.setItem(`${state.prefix}${key}`, valJson);
|
|
13771
|
+
window.sessionStorage.setItem(`${state$1.prefix}${key}`, valJson);
|
|
13800
13772
|
} catch (error) {
|
|
13801
13773
|
consoleError("Session", error);
|
|
13802
13774
|
}
|
|
@@ -13813,18 +13785,18 @@ var FastUtils = function(exports, vue) {
|
|
|
13813
13785
|
return;
|
|
13814
13786
|
}
|
|
13815
13787
|
try {
|
|
13816
|
-
decrypt ?? (decrypt = state.crypto);
|
|
13817
|
-
let valJson = window.sessionStorage.getItem(`${state.prefix}${key}`);
|
|
13788
|
+
decrypt ?? (decrypt = state$1.crypto);
|
|
13789
|
+
let valJson = window.sessionStorage.getItem(`${state$1.prefix}${key}`);
|
|
13818
13790
|
if (valJson) {
|
|
13819
13791
|
if (decrypt) {
|
|
13820
13792
|
valJson = base64Util.base64ToStr(valJson);
|
|
13821
13793
|
}
|
|
13822
|
-
const expireJson = window.sessionStorage.getItem(`${state.prefix}${key}${state.expireSuffix}`);
|
|
13794
|
+
const expireJson = window.sessionStorage.getItem(`${state$1.prefix}${key}${state$1.expireSuffix}`);
|
|
13823
13795
|
if (expireJson) {
|
|
13824
13796
|
const expireData = JSON.parse(expireJson);
|
|
13825
13797
|
if (Date.now() > expireData.time + expireData.expire * 60 * 1e3) {
|
|
13826
|
-
window.sessionStorage.removeItem(`${state.prefix}${key}`);
|
|
13827
|
-
window.sessionStorage.removeItem(`${state.prefix}${key}${state.expireSuffix}`);
|
|
13798
|
+
window.sessionStorage.removeItem(`${state$1.prefix}${key}`);
|
|
13799
|
+
window.sessionStorage.removeItem(`${state$1.prefix}${key}${state$1.expireSuffix}`);
|
|
13828
13800
|
return null;
|
|
13829
13801
|
}
|
|
13830
13802
|
}
|
|
@@ -13849,8 +13821,8 @@ var FastUtils = function(exports, vue) {
|
|
|
13849
13821
|
return;
|
|
13850
13822
|
}
|
|
13851
13823
|
try {
|
|
13852
|
-
window.sessionStorage.removeItem(`${state.prefix}${key}`);
|
|
13853
|
-
window.sessionStorage.removeItem(`${state.prefix}${key}${state.expireSuffix}`);
|
|
13824
|
+
window.sessionStorage.removeItem(`${state$1.prefix}${key}`);
|
|
13825
|
+
window.sessionStorage.removeItem(`${state$1.prefix}${key}${state$1.expireSuffix}`);
|
|
13854
13826
|
} catch (error) {
|
|
13855
13827
|
consoleError("Session", error);
|
|
13856
13828
|
}
|
|
@@ -13866,7 +13838,7 @@ var FastUtils = function(exports, vue) {
|
|
|
13866
13838
|
}
|
|
13867
13839
|
try {
|
|
13868
13840
|
for (const itemKey in window.sessionStorage) {
|
|
13869
|
-
if (itemKey.indexOf(`${state.prefix}${key}`) !== -1) {
|
|
13841
|
+
if (itemKey.indexOf(`${state$1.prefix}${key}`) !== -1) {
|
|
13870
13842
|
window.sessionStorage.removeItem(itemKey);
|
|
13871
13843
|
}
|
|
13872
13844
|
}
|
|
@@ -13919,6 +13891,43 @@ var FastUtils = function(exports, vue) {
|
|
|
13919
13891
|
}
|
|
13920
13892
|
return false;
|
|
13921
13893
|
},
|
|
13894
|
+
/**
|
|
13895
|
+
* 切割骆驼命名式字符串
|
|
13896
|
+
*/
|
|
13897
|
+
splitCamelCase(value) {
|
|
13898
|
+
if (!value) return [];
|
|
13899
|
+
if (value.length === 1) return [value];
|
|
13900
|
+
return value.split(new RegExp("(?=\\p{Lu}\\p{Ll})|(?<=\\p{Ll})(?=\\p{Lu})", "u")).filter((token) => token.length > 0);
|
|
13901
|
+
},
|
|
13902
|
+
/**
|
|
13903
|
+
* 将字符串转为 camelCase 格式,支持 - 或 _ 分隔的字符串
|
|
13904
|
+
* 例如:'hello-world' 或 'hello_world' => 'helloWorld'
|
|
13905
|
+
*/
|
|
13906
|
+
toCamelCase(value) {
|
|
13907
|
+
if (!value) return "";
|
|
13908
|
+
return value.replace(/[-_](\w)/g, (_, c) => c ? c.toUpperCase() : "");
|
|
13909
|
+
},
|
|
13910
|
+
/**
|
|
13911
|
+
* 字符串首字母大写
|
|
13912
|
+
*/
|
|
13913
|
+
firstCharToUpper(value) {
|
|
13914
|
+
if (!value) return "";
|
|
13915
|
+
return value.charAt(0).toUpperCase() + value.slice(1);
|
|
13916
|
+
},
|
|
13917
|
+
/**
|
|
13918
|
+
* 字符串首字母小写
|
|
13919
|
+
*/
|
|
13920
|
+
firstCharToLower(value) {
|
|
13921
|
+
if (!value) return "";
|
|
13922
|
+
return value.charAt(0).toLowerCase() + value.slice(1);
|
|
13923
|
+
},
|
|
13924
|
+
/**
|
|
13925
|
+
* 截取指定长度的字符串
|
|
13926
|
+
*/
|
|
13927
|
+
subStringWithEllipsis(value, length, suffix = "...") {
|
|
13928
|
+
if (!value) return "";
|
|
13929
|
+
return value.length > length ? value.substring(0, length) + suffix : value;
|
|
13930
|
+
},
|
|
13922
13931
|
/**
|
|
13923
13932
|
* 生成随机字符串
|
|
13924
13933
|
*/
|
|
@@ -13978,6 +13987,49 @@ var FastUtils = function(exports, vue) {
|
|
|
13978
13987
|
}
|
|
13979
13988
|
}
|
|
13980
13989
|
};
|
|
13990
|
+
const state = vue.reactive({
|
|
13991
|
+
cacheKey: "__DEVICE_ID",
|
|
13992
|
+
deviceId: ""
|
|
13993
|
+
});
|
|
13994
|
+
const uuidRegExp = /^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$/;
|
|
13995
|
+
const makeIdentity = () => {
|
|
13996
|
+
if (state.deviceId && uuidRegExp.test(state.deviceId)) {
|
|
13997
|
+
Local.set(state.cacheKey, state.deviceId);
|
|
13998
|
+
return state.deviceId;
|
|
13999
|
+
}
|
|
14000
|
+
let deviceID = Local.get(state.cacheKey);
|
|
14001
|
+
if (deviceID && uuidRegExp.test(deviceID)) {
|
|
14002
|
+
state.deviceId = deviceID;
|
|
14003
|
+
return deviceID;
|
|
14004
|
+
}
|
|
14005
|
+
deviceID = stringUtil.generateUUID();
|
|
14006
|
+
Local.set(state.cacheKey, deviceID);
|
|
14007
|
+
state.deviceId = deviceID;
|
|
14008
|
+
return deviceID;
|
|
14009
|
+
};
|
|
14010
|
+
const useIdentity = () => {
|
|
14011
|
+
return {
|
|
14012
|
+
...state,
|
|
14013
|
+
makeIdentity
|
|
14014
|
+
};
|
|
14015
|
+
};
|
|
14016
|
+
const objectUtil = {
|
|
14017
|
+
/**
|
|
14018
|
+
* 对象URL参数化
|
|
14019
|
+
*/
|
|
14020
|
+
objectToQueryString(obj) {
|
|
14021
|
+
let params = "";
|
|
14022
|
+
for (const key in obj) {
|
|
14023
|
+
if (Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
14024
|
+
if (params !== "") {
|
|
14025
|
+
params += "&";
|
|
14026
|
+
}
|
|
14027
|
+
params += `${encodeURIComponent(key)}=${encodeURIComponent(obj[key])}`;
|
|
14028
|
+
}
|
|
14029
|
+
}
|
|
14030
|
+
return params;
|
|
14031
|
+
}
|
|
14032
|
+
};
|
|
13981
14033
|
const useExpose = (expose, exposed) => {
|
|
13982
14034
|
expose(exposed);
|
|
13983
14035
|
return exposed;
|
|
@@ -14042,7 +14094,7 @@ var FastUtils = function(exports, vue) {
|
|
|
14042
14094
|
const useRender = (render) => {
|
|
14043
14095
|
const vm = vue.getCurrentInstance();
|
|
14044
14096
|
if (!vm) {
|
|
14045
|
-
throw new
|
|
14097
|
+
throw new FastError("useRender must be called from inside a setup function");
|
|
14046
14098
|
}
|
|
14047
14099
|
vm.render = render;
|
|
14048
14100
|
};
|
|
@@ -14055,6 +14107,7 @@ var FastUtils = function(exports, vue) {
|
|
|
14055
14107
|
exports.Local = Local;
|
|
14056
14108
|
exports.Session = Session;
|
|
14057
14109
|
exports.addUnit = addUnit;
|
|
14110
|
+
exports.arrayUtil = arrayUtil;
|
|
14058
14111
|
exports.base64Util = base64Util;
|
|
14059
14112
|
exports.clickUtil = clickUtil;
|
|
14060
14113
|
exports.colorUtil = colorUtil;
|
|
@@ -14065,12 +14118,14 @@ var FastUtils = function(exports, vue) {
|
|
|
14065
14118
|
exports.cryptoUtil = cryptoUtil;
|
|
14066
14119
|
exports.dateUtil = dateUtil;
|
|
14067
14120
|
exports.definePropType = definePropType;
|
|
14121
|
+
exports.envUtil = envUtil;
|
|
14068
14122
|
exports.execFunction = execFunction;
|
|
14069
14123
|
exports.makeSlots = makeSlots;
|
|
14070
14124
|
exports.objectUtil = objectUtil;
|
|
14071
14125
|
exports.stringUtil = stringUtil;
|
|
14072
14126
|
exports.throwError = throwError;
|
|
14073
14127
|
exports.useExpose = useExpose;
|
|
14128
|
+
exports.useIdentity = useIdentity;
|
|
14074
14129
|
exports.useProps = useProps;
|
|
14075
14130
|
exports.useRender = useRender;
|
|
14076
14131
|
exports.useStorage = useStorage;
|