@fast-china/utils 1.0.0
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/Fast.png +0 -0
- package/LICENSE +201 -0
- package/README.md +77 -0
- package/README.zh.md +77 -0
- package/dist/index.cjs +1294 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +380 -0
- package/dist/index.d.ts +380 -0
- package/dist/index.js +1264 -0
- package/dist/index.js.map +1 -0
- package/dist/index.min.cjs +3 -0
- package/dist/index.min.cjs.map +1 -0
- package/dist/index.min.js +3 -0
- package/dist/index.min.js.map +1 -0
- package/package.json +84 -0
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,1294 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var lodashUnified = require('lodash-unified');
|
|
4
|
+
var cryptoJs = require('crypto-js');
|
|
5
|
+
var vue = require('vue');
|
|
6
|
+
|
|
7
|
+
// src/base64/index.ts
|
|
8
|
+
var b64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
|
|
9
|
+
var b64re = /^(?:[A-Za-z\d+/]{4})*?(?:[A-Za-z\d+/]{2}(?:==)?|[A-Za-z\d+/]{3}=?)?$/;
|
|
10
|
+
var base64PwdDic = [
|
|
11
|
+
{ index: 977, randomIndex: 188 },
|
|
12
|
+
{ index: 926, randomIndex: 201 },
|
|
13
|
+
{ index: 851, randomIndex: 225 },
|
|
14
|
+
{ index: 700, randomIndex: 255 },
|
|
15
|
+
{ index: 600, randomIndex: 268 },
|
|
16
|
+
{ index: 500, randomIndex: 277 },
|
|
17
|
+
{ index: 400, randomIndex: 288 },
|
|
18
|
+
{ index: 330, randomIndex: 327 },
|
|
19
|
+
{ index: 300, randomIndex: 180 },
|
|
20
|
+
{ index: 200, randomIndex: 178 },
|
|
21
|
+
{ index: 100, randomIndex: 124 },
|
|
22
|
+
// 100 以内字典
|
|
23
|
+
{ index: 98, randomIndex: 95 },
|
|
24
|
+
{ index: 92, randomIndex: 90 },
|
|
25
|
+
{ index: 91, randomIndex: 87 },
|
|
26
|
+
{ index: 88, randomIndex: 84 },
|
|
27
|
+
{ index: 82, randomIndex: 79 },
|
|
28
|
+
{ index: 78, randomIndex: 71 },
|
|
29
|
+
{ index: 72, randomIndex: 69 },
|
|
30
|
+
{ index: 68, randomIndex: 66 },
|
|
31
|
+
{ index: 59, randomIndex: 55 },
|
|
32
|
+
{ index: 48, randomIndex: 43 },
|
|
33
|
+
{ index: 42, randomIndex: 37 },
|
|
34
|
+
{ index: 36, randomIndex: 30 },
|
|
35
|
+
{ index: 33, randomIndex: 27 },
|
|
36
|
+
{ index: 24, randomIndex: 20 },
|
|
37
|
+
{ index: 23, randomIndex: 18 },
|
|
38
|
+
{ index: 21, randomIndex: 16 },
|
|
39
|
+
{ index: 17, randomIndex: 14 },
|
|
40
|
+
{ index: 13, randomIndex: 9 },
|
|
41
|
+
{ index: 7, randomIndex: 4 },
|
|
42
|
+
{ index: 5, randomIndex: 3 },
|
|
43
|
+
{ index: 2, randomIndex: 1 }
|
|
44
|
+
];
|
|
45
|
+
var randomPrefixStrLength = 6;
|
|
46
|
+
var randomStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
|
|
47
|
+
function insertRandomStrToBase64Str(base64Str) {
|
|
48
|
+
let strResult = base64Str;
|
|
49
|
+
const items = base64PwdDic.sort((a, b) => {
|
|
50
|
+
return b.index - a.index;
|
|
51
|
+
});
|
|
52
|
+
items.forEach((item) => {
|
|
53
|
+
if (item.index < base64Str.length) {
|
|
54
|
+
const randomChar = base64Str[item.randomIndex];
|
|
55
|
+
strResult = strResult.slice(0, item.index) + randomChar + strResult.slice(item.index);
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
return strResult;
|
|
59
|
+
}
|
|
60
|
+
function removeBase64StrRandomStr(base64Str) {
|
|
61
|
+
const items = base64PwdDic.sort((a, b) => {
|
|
62
|
+
return a.index - b.index;
|
|
63
|
+
});
|
|
64
|
+
let strResult = base64Str;
|
|
65
|
+
items.forEach((item) => {
|
|
66
|
+
if (item.index < base64Str.length) {
|
|
67
|
+
strResult = strResult.slice(0, item.index) + strResult.slice(item.index + 1);
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
return strResult;
|
|
71
|
+
}
|
|
72
|
+
function getRandomStr(str = randomStr, prefixStrLength = randomPrefixStrLength) {
|
|
73
|
+
let result = "";
|
|
74
|
+
for (let i = 0; i < prefixStrLength; i++) {
|
|
75
|
+
const randomInt = Math.ceil(Math.random() * (str.length - 1));
|
|
76
|
+
const randomChar = str[randomInt];
|
|
77
|
+
result += randomChar;
|
|
78
|
+
}
|
|
79
|
+
return result;
|
|
80
|
+
}
|
|
81
|
+
var base64Util = {
|
|
82
|
+
bota(string) {
|
|
83
|
+
string = String(string);
|
|
84
|
+
let bitmap, a, b, c, result = "", i = 0, rest = string.length % 3;
|
|
85
|
+
for (; i < string.length; ) {
|
|
86
|
+
if ((a = string.charCodeAt(i++)) > 255 || (b = string.charCodeAt(i++)) > 255 || (c = string.charCodeAt(i++)) > 255)
|
|
87
|
+
throw new TypeError(
|
|
88
|
+
"Failed to execute 'btoa' on 'Window': The string to be encoded contains characters outside of the Latin1 range."
|
|
89
|
+
);
|
|
90
|
+
bitmap = a << 16 | b << 8 | c;
|
|
91
|
+
result += b64.charAt(bitmap >> 18 & 63) + b64.charAt(bitmap >> 12 & 63) + b64.charAt(bitmap >> 6 & 63) + b64.charAt(bitmap & 63);
|
|
92
|
+
}
|
|
93
|
+
return rest ? result.slice(0, rest - 3) + "===".substring(rest) : result;
|
|
94
|
+
},
|
|
95
|
+
atob(string) {
|
|
96
|
+
string = String(string).replace(/[\t\n\f\r ]+/g, "");
|
|
97
|
+
if (!b64re.test(string)) throw new TypeError("Failed to execute 'atob' on 'Window': The string to be decoded is not correctly encoded.");
|
|
98
|
+
string += "==".slice(2 - (string.length & 3));
|
|
99
|
+
let bitmap, result = "", r1, r2, i = 0;
|
|
100
|
+
for (; i < string.length; ) {
|
|
101
|
+
bitmap = b64.indexOf(string.charAt(i++)) << 18 | b64.indexOf(string.charAt(i++)) << 12 | (r1 = b64.indexOf(string.charAt(i++))) << 6 | (r2 = b64.indexOf(string.charAt(i++)));
|
|
102
|
+
result += r1 === 64 ? String.fromCharCode(bitmap >> 16 & 255) : r2 === 64 ? String.fromCharCode(bitmap >> 16 & 255, bitmap >> 8 & 255) : String.fromCharCode(bitmap >> 16 & 255, bitmap >> 8 & 255, bitmap & 255);
|
|
103
|
+
}
|
|
104
|
+
return result;
|
|
105
|
+
},
|
|
106
|
+
/**
|
|
107
|
+
* 字符串ToBase64
|
|
108
|
+
*/
|
|
109
|
+
toBase64(str, prefixStrLength = randomPrefixStrLength) {
|
|
110
|
+
if (str.length === 0) {
|
|
111
|
+
return "";
|
|
112
|
+
}
|
|
113
|
+
const randomPrefixStr = getRandomStr();
|
|
114
|
+
let base64 = base64Util.bota(encodeURIComponent(str));
|
|
115
|
+
if (prefixStrLength !== 0) {
|
|
116
|
+
base64 = insertRandomStrToBase64Str(base64);
|
|
117
|
+
}
|
|
118
|
+
return randomPrefixStr + base64;
|
|
119
|
+
},
|
|
120
|
+
/**
|
|
121
|
+
* Base64转字符串
|
|
122
|
+
*/
|
|
123
|
+
base64ToStr(str, prefixStrLength = randomPrefixStrLength) {
|
|
124
|
+
let result = str;
|
|
125
|
+
if (str.length === 0) {
|
|
126
|
+
return "";
|
|
127
|
+
}
|
|
128
|
+
let input = str.slice(prefixStrLength);
|
|
129
|
+
if (prefixStrLength !== 0) {
|
|
130
|
+
input = removeBase64StrRandomStr(input);
|
|
131
|
+
}
|
|
132
|
+
result = base64Util.atob(input);
|
|
133
|
+
return decodeURIComponent(result);
|
|
134
|
+
}
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
// src/click/index.ts
|
|
138
|
+
var _debounceTimeout = null;
|
|
139
|
+
var _throttleRunning = false;
|
|
140
|
+
var clickUtil = {
|
|
141
|
+
/**
|
|
142
|
+
* 防抖
|
|
143
|
+
* @param fn - 执行函数
|
|
144
|
+
* @param delay - 延时毫秒
|
|
145
|
+
* @returns 返回一个新的防抖函数
|
|
146
|
+
*/
|
|
147
|
+
debounce(fn, delay = 500) {
|
|
148
|
+
if (_debounceTimeout) {
|
|
149
|
+
clearTimeout(_debounceTimeout);
|
|
150
|
+
}
|
|
151
|
+
_debounceTimeout = setTimeout(() => {
|
|
152
|
+
fn();
|
|
153
|
+
}, delay);
|
|
154
|
+
},
|
|
155
|
+
/**
|
|
156
|
+
* 异步防抖
|
|
157
|
+
* @param fn - 执行函数
|
|
158
|
+
* @param delay - 延时毫秒
|
|
159
|
+
* @returns 返回一个新的防抖函数
|
|
160
|
+
*/
|
|
161
|
+
async debounceAsync(fn, delay = 500) {
|
|
162
|
+
return new Promise((resolve, reject) => {
|
|
163
|
+
if (_debounceTimeout) {
|
|
164
|
+
clearTimeout(_debounceTimeout);
|
|
165
|
+
}
|
|
166
|
+
_debounceTimeout = setTimeout(async () => {
|
|
167
|
+
try {
|
|
168
|
+
await fn();
|
|
169
|
+
resolve();
|
|
170
|
+
} catch (error) {
|
|
171
|
+
reject(error);
|
|
172
|
+
}
|
|
173
|
+
}, delay);
|
|
174
|
+
});
|
|
175
|
+
},
|
|
176
|
+
/**
|
|
177
|
+
* 节流
|
|
178
|
+
* @param fn - 执行函数
|
|
179
|
+
* @param delay - 延时毫秒
|
|
180
|
+
* @returns 返回一个新的节流函数
|
|
181
|
+
*/
|
|
182
|
+
throttle(fn, delay = 500) {
|
|
183
|
+
if (_throttleRunning) {
|
|
184
|
+
return;
|
|
185
|
+
}
|
|
186
|
+
_throttleRunning = true;
|
|
187
|
+
fn();
|
|
188
|
+
setTimeout(() => {
|
|
189
|
+
_throttleRunning = false;
|
|
190
|
+
}, delay);
|
|
191
|
+
},
|
|
192
|
+
/**
|
|
193
|
+
* 异步节流
|
|
194
|
+
* @param fn - 执行函数
|
|
195
|
+
* @param delay - 延时毫秒
|
|
196
|
+
* @returns 返回一个新的节流函数
|
|
197
|
+
*/
|
|
198
|
+
async throttleAsync(fn, delay = 500) {
|
|
199
|
+
return new Promise((resolve, reject) => {
|
|
200
|
+
if (_throttleRunning) {
|
|
201
|
+
return;
|
|
202
|
+
}
|
|
203
|
+
_throttleRunning = true;
|
|
204
|
+
fn().then(() => {
|
|
205
|
+
resolve();
|
|
206
|
+
}).catch((error) => {
|
|
207
|
+
reject(error);
|
|
208
|
+
}).finally(() => {
|
|
209
|
+
setTimeout(() => {
|
|
210
|
+
_throttleRunning = false;
|
|
211
|
+
}, delay);
|
|
212
|
+
});
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
};
|
|
216
|
+
|
|
217
|
+
// src/color/index.ts
|
|
218
|
+
var colorUtil = {
|
|
219
|
+
/**
|
|
220
|
+
* hex颜色转rgb颜色
|
|
221
|
+
* @param str 颜色值字符串
|
|
222
|
+
* @returns 返回处理后的颜色值
|
|
223
|
+
*/
|
|
224
|
+
hexToRgb(str) {
|
|
225
|
+
let hex = "";
|
|
226
|
+
const reg = /^#?[0-9A-Fa-f]{6}$/;
|
|
227
|
+
if (!reg.test(str)) throw new Error("\u8F93\u5165\u9519\u8BEF\u7684hex");
|
|
228
|
+
str = str.replace("#", "");
|
|
229
|
+
hex = str.match(/../g);
|
|
230
|
+
for (let i = 0; i < 3; i++) hex[i] = parseInt(hex[i], 16);
|
|
231
|
+
return hex;
|
|
232
|
+
},
|
|
233
|
+
/**
|
|
234
|
+
* rgb颜色转Hex颜色
|
|
235
|
+
* @param r 代表红色
|
|
236
|
+
* @param g 代表绿色
|
|
237
|
+
* @param b 代表蓝色
|
|
238
|
+
* @returns 返回处理后的颜色值
|
|
239
|
+
*/
|
|
240
|
+
rgbToHex(r, g, b) {
|
|
241
|
+
const reg = /^\d{1,3}$/;
|
|
242
|
+
if (!reg.test(r) || !reg.test(g) || !reg.test(b)) throw new Error("\u8F93\u5165\u9519\u8BEF\u7684rgb\u989C\u8272\u503C");
|
|
243
|
+
const hex = [r.toString(16), g.toString(16), b.toString(16)];
|
|
244
|
+
for (let i = 0; i < 3; i++) if (hex[i].length === 1) hex[i] = `0${hex[i]}`;
|
|
245
|
+
return `#${hex.join("")}`;
|
|
246
|
+
},
|
|
247
|
+
/**
|
|
248
|
+
* 加深颜色值
|
|
249
|
+
* @param color 颜色值字符串
|
|
250
|
+
* @param level 加深的程度,限0-1之间
|
|
251
|
+
* @returns 返回处理后的颜色值
|
|
252
|
+
*/
|
|
253
|
+
getDarkColor(color, level) {
|
|
254
|
+
const reg = /^#?[0-9A-Fa-f]{6}$/;
|
|
255
|
+
if (!reg.test(color)) throw new Error("\u8F93\u5165\u9519\u8BEF\u7684hex\u989C\u8272\u503C");
|
|
256
|
+
const rgb = this.hexToRgb(color);
|
|
257
|
+
for (let i = 0; i < 3; i++) rgb[i] = Math.round(20.5 * level + rgb[i] * (1 - level));
|
|
258
|
+
return this.rgbToHex(rgb[0], rgb[1], rgb[2]);
|
|
259
|
+
},
|
|
260
|
+
/**
|
|
261
|
+
* 变浅颜色值
|
|
262
|
+
* @param color 颜色值字符串
|
|
263
|
+
* @param level 加深的程度,限0-1之间
|
|
264
|
+
* @returns 返回处理后的颜色值
|
|
265
|
+
*/
|
|
266
|
+
getLightColor(color, level) {
|
|
267
|
+
const reg = /^#?[0-9A-Fa-f]{6}$/;
|
|
268
|
+
if (!reg.test(color)) throw new Error("\u8F93\u5165\u9519\u8BEF\u7684hex\u989C\u8272\u503C");
|
|
269
|
+
const rgb = this.hexToRgb(color);
|
|
270
|
+
for (let i = 0; i < 3; i++) rgb[i] = Math.round(255 * level + rgb[i] * (1 - level));
|
|
271
|
+
return this.rgbToHex(rgb[0], rgb[1], rgb[2]);
|
|
272
|
+
}
|
|
273
|
+
};
|
|
274
|
+
|
|
275
|
+
// src/error/index.ts
|
|
276
|
+
var FastError = class extends Error {
|
|
277
|
+
constructor(m) {
|
|
278
|
+
super(m);
|
|
279
|
+
this.name = "FastError";
|
|
280
|
+
}
|
|
281
|
+
};
|
|
282
|
+
|
|
283
|
+
// src/console/index.ts
|
|
284
|
+
var consoleLog = (name, message, error) => {
|
|
285
|
+
if (error) {
|
|
286
|
+
console.log(`[Fast-Log-${name}]${message ? ` ${message}` : ""}`, error);
|
|
287
|
+
} else {
|
|
288
|
+
console.log(`[Fast-Log-${name}]${message ? ` ${message}` : ""}`);
|
|
289
|
+
}
|
|
290
|
+
};
|
|
291
|
+
var consoleWarn = (name, message, error) => {
|
|
292
|
+
if (error) {
|
|
293
|
+
console.warn(`[Fast-Log-${name}]${message ? ` ${message}` : ""}`, error);
|
|
294
|
+
} else {
|
|
295
|
+
console.warn(`[Fast-Log-${name}]${message ? ` ${message}` : ""}`);
|
|
296
|
+
}
|
|
297
|
+
};
|
|
298
|
+
var consoleDebug = (name, message, error) => {
|
|
299
|
+
if (error) {
|
|
300
|
+
console.debug(`[Fast-Log-${name}]${message ? ` ${message}` : ""}`, error);
|
|
301
|
+
} else {
|
|
302
|
+
console.debug(`[Fast-Log-${name}]${message ? ` ${message}` : ""}`);
|
|
303
|
+
}
|
|
304
|
+
};
|
|
305
|
+
var consoleError = (name, message) => {
|
|
306
|
+
if (lodashUnified.isNil(message)) {
|
|
307
|
+
return;
|
|
308
|
+
}
|
|
309
|
+
if (lodashUnified.isString(message)) {
|
|
310
|
+
console.error(new FastError(`[Fast-${name}] ${message}`));
|
|
311
|
+
} else {
|
|
312
|
+
console.error(`[Fast-Error-${name}]`, message);
|
|
313
|
+
}
|
|
314
|
+
};
|
|
315
|
+
var throwError = (name, message) => {
|
|
316
|
+
throw new FastError(`[Fast-${name}] ${message}`);
|
|
317
|
+
};
|
|
318
|
+
var cryptoUtil = {
|
|
319
|
+
/**
|
|
320
|
+
* AES
|
|
321
|
+
*/
|
|
322
|
+
aes: {
|
|
323
|
+
/**
|
|
324
|
+
* AES加密
|
|
325
|
+
* @param dataStr 要加密的字符串
|
|
326
|
+
* @param key 用于加密的密钥
|
|
327
|
+
* @param vector 用于加密的向量(IV)
|
|
328
|
+
* @param cipherMode 加密模式,默认为CBC模式
|
|
329
|
+
*/
|
|
330
|
+
encrypt(dataStr, key, vector, cipherMode = cryptoJs.mode.CBC) {
|
|
331
|
+
if (!dataStr) {
|
|
332
|
+
return dataStr;
|
|
333
|
+
}
|
|
334
|
+
if (key.length < 32) {
|
|
335
|
+
key = key.padEnd(32, "f");
|
|
336
|
+
}
|
|
337
|
+
if (key.length > 32) {
|
|
338
|
+
key = key.substring(0, 32);
|
|
339
|
+
}
|
|
340
|
+
if (vector.length < 16) {
|
|
341
|
+
vector = vector.padEnd(16, "f");
|
|
342
|
+
}
|
|
343
|
+
if (vector.length > 16) {
|
|
344
|
+
vector = vector.substring(0, 16);
|
|
345
|
+
}
|
|
346
|
+
return cryptoJs.AES.encrypt(dataStr, cryptoJs.enc.Utf8.parse(key), {
|
|
347
|
+
iv: cryptoJs.enc.Utf8.parse(vector),
|
|
348
|
+
mode: cipherMode
|
|
349
|
+
}).toString();
|
|
350
|
+
},
|
|
351
|
+
/**
|
|
352
|
+
* AES解密
|
|
353
|
+
* @param dataStr 要解密的Base64编码字符串
|
|
354
|
+
* @param key 用于解密的密钥
|
|
355
|
+
* @param vector 用于解密的向量(IV)
|
|
356
|
+
* @param cipherMode 解密模式,默认为CBC模式
|
|
357
|
+
*/
|
|
358
|
+
decrypt(dataStr, key, vector, cipherMode = cryptoJs.mode.CBC) {
|
|
359
|
+
if (!dataStr) {
|
|
360
|
+
return null;
|
|
361
|
+
}
|
|
362
|
+
if (key.length < 32) {
|
|
363
|
+
key = key.padEnd(32, "f");
|
|
364
|
+
}
|
|
365
|
+
if (key.length > 32) {
|
|
366
|
+
key = key.substring(0, 32);
|
|
367
|
+
}
|
|
368
|
+
if (vector.length < 16) {
|
|
369
|
+
vector = vector.padEnd(16, "f");
|
|
370
|
+
}
|
|
371
|
+
if (vector.length > 16) {
|
|
372
|
+
vector = vector.substring(0, 16);
|
|
373
|
+
}
|
|
374
|
+
const resAESData = cryptoJs.AES.decrypt(dataStr, cryptoJs.enc.Utf8.parse(key), {
|
|
375
|
+
iv: cryptoJs.enc.Utf8.parse(vector),
|
|
376
|
+
mode: cipherMode
|
|
377
|
+
});
|
|
378
|
+
try {
|
|
379
|
+
const result = resAESData.toString(cryptoJs.enc.Utf8);
|
|
380
|
+
return JSON.parse(result);
|
|
381
|
+
} catch (error) {
|
|
382
|
+
consoleError("AESCrypto", error);
|
|
383
|
+
return null;
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
},
|
|
387
|
+
/**
|
|
388
|
+
* SHA1
|
|
389
|
+
*/
|
|
390
|
+
sha1: {
|
|
391
|
+
/**
|
|
392
|
+
* SHA1加密
|
|
393
|
+
* @param dataStr 要加密的字符串
|
|
394
|
+
*/
|
|
395
|
+
encrypt(dataStr) {
|
|
396
|
+
if (!dataStr) {
|
|
397
|
+
return dataStr;
|
|
398
|
+
}
|
|
399
|
+
return cryptoJs.SHA1(dataStr).toString(cryptoJs.enc.Hex).toUpperCase();
|
|
400
|
+
}
|
|
401
|
+
},
|
|
402
|
+
/**
|
|
403
|
+
* MD5
|
|
404
|
+
*/
|
|
405
|
+
MD5: {
|
|
406
|
+
/**
|
|
407
|
+
* MD5加密
|
|
408
|
+
* @param dataStr 要加密的字符串
|
|
409
|
+
*/
|
|
410
|
+
encrypt(dataStr) {
|
|
411
|
+
if (!dataStr) {
|
|
412
|
+
return dataStr;
|
|
413
|
+
}
|
|
414
|
+
return cryptoJs.MD5(dataStr).toString(cryptoJs.enc.Hex).toUpperCase();
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
};
|
|
418
|
+
|
|
419
|
+
// src/date/index.ts
|
|
420
|
+
var dateUtil = {
|
|
421
|
+
/**
|
|
422
|
+
* 根据当前时间生成问候语
|
|
423
|
+
*/
|
|
424
|
+
getGreet() {
|
|
425
|
+
const now = /* @__PURE__ */ new Date();
|
|
426
|
+
const hour = now.getHours();
|
|
427
|
+
let greet = "";
|
|
428
|
+
if (hour < 5) {
|
|
429
|
+
greet = "\u591C\u6DF1\u4E86\uFF0C\u6CE8\u610F\u8EAB\u4F53\u54E6\uFF01";
|
|
430
|
+
} else if (hour < 9) {
|
|
431
|
+
greet = "\u65E9\u4E0A\u597D\uFF01\u6B22\u8FCE\u56DE\u6765\uFF01";
|
|
432
|
+
} else if (hour < 12) {
|
|
433
|
+
greet = "\u4E0A\u5348\u597D\uFF01\u6B22\u8FCE\u56DE\u6765\uFF01";
|
|
434
|
+
} else if (hour < 14) {
|
|
435
|
+
greet = "\u4E2D\u5348\u597D\uFF01\u6B22\u8FCE\u56DE\u6765\uFF01";
|
|
436
|
+
} else if (hour < 18) {
|
|
437
|
+
greet = "\u4E0B\u5348\u597D\uFF01\u6B22\u8FCE\u56DE\u6765\uFF01";
|
|
438
|
+
} else if (hour < 24) {
|
|
439
|
+
greet = "\u665A\u4E0A\u597D\uFF01\u6B22\u8FCE\u56DE\u6765\uFF01";
|
|
440
|
+
} else {
|
|
441
|
+
greet = "\u60A8\u597D\uFF01\u6B22\u8FCE\u56DE\u6765\uFF01";
|
|
442
|
+
}
|
|
443
|
+
return greet;
|
|
444
|
+
},
|
|
445
|
+
/**
|
|
446
|
+
* 时间处理翻译
|
|
447
|
+
*/
|
|
448
|
+
dateTimeFix(date) {
|
|
449
|
+
if (date !== null && date !== void 0 && date) {
|
|
450
|
+
if (typeof date === "string") {
|
|
451
|
+
date = new Date(date);
|
|
452
|
+
}
|
|
453
|
+
let timestamp = date.getTime();
|
|
454
|
+
if (timestamp.toString().length < 13) {
|
|
455
|
+
const arrTimestamp = timestamp.toString().split("");
|
|
456
|
+
for (let start = 0; start < 13; start++) {
|
|
457
|
+
if (!arrTimestamp[start]) {
|
|
458
|
+
arrTimestamp[start] = "0";
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
timestamp = parseInt(arrTimestamp.join(""));
|
|
462
|
+
}
|
|
463
|
+
const minute = 1e3 * 60;
|
|
464
|
+
const hour = minute * 60;
|
|
465
|
+
const day = hour * 24;
|
|
466
|
+
const month = day * 30;
|
|
467
|
+
const curTime = (/* @__PURE__ */ new Date()).getTime();
|
|
468
|
+
const diffValue = curTime - timestamp;
|
|
469
|
+
const monthC = diffValue / month;
|
|
470
|
+
const weekC = diffValue / (7 * day);
|
|
471
|
+
const dayC = diffValue / day;
|
|
472
|
+
const hourC = diffValue / hour;
|
|
473
|
+
const minC = diffValue / minute;
|
|
474
|
+
if (diffValue < 0) {
|
|
475
|
+
const monthC1 = Math.abs(monthC);
|
|
476
|
+
const weekC1 = Math.abs(weekC);
|
|
477
|
+
const dayC1 = Math.abs(dayC);
|
|
478
|
+
const hourC1 = Math.abs(hourC);
|
|
479
|
+
const minC1 = Math.abs(minC);
|
|
480
|
+
if (monthC1 > 12) {
|
|
481
|
+
return `${parseInt(`${monthC1 / 12}`)}\u5E74\u540E`;
|
|
482
|
+
} else if (monthC1 >= 6) {
|
|
483
|
+
return "\u534A\u5E74\u540E";
|
|
484
|
+
} else if (monthC1 >= 1) {
|
|
485
|
+
return `${parseInt(`${monthC1}`)}\u6708\u540E`;
|
|
486
|
+
} else if (weekC1 > 2) {
|
|
487
|
+
return "\u534A\u6708\u540E";
|
|
488
|
+
} else if (weekC1 >= 1) {
|
|
489
|
+
return `${parseInt(`${weekC1}`)}\u5468\u540E`;
|
|
490
|
+
} else if (dayC1 >= 1) {
|
|
491
|
+
return `${parseInt(`${dayC1}`)}\u5929\u540E`;
|
|
492
|
+
} else if (hourC1 >= 1) {
|
|
493
|
+
return `${parseInt(`${hourC1}`)}\u5C0F\u65F6\u540E`;
|
|
494
|
+
} else if (minC1 >= 1) {
|
|
495
|
+
return `${parseInt(`${minC1}`)}\u5206\u949F\u540E`;
|
|
496
|
+
}
|
|
497
|
+
return "\u521A\u521A";
|
|
498
|
+
}
|
|
499
|
+
if (monthC > 12) {
|
|
500
|
+
return `${parseInt(`${monthC / 12}`)}\u5E74\u524D`;
|
|
501
|
+
} else if (monthC >= 6) {
|
|
502
|
+
return "\u534A\u5E74\u524D";
|
|
503
|
+
} else if (monthC >= 1) {
|
|
504
|
+
return `${parseInt(`${monthC}`)}\u6708\u524D`;
|
|
505
|
+
} else if (weekC > 2) {
|
|
506
|
+
return "\u534A\u6708\u524D";
|
|
507
|
+
} else if (weekC >= 1) {
|
|
508
|
+
return `${parseInt(`${weekC}`)}\u5468\u524D`;
|
|
509
|
+
} else if (dayC >= 1) {
|
|
510
|
+
return `${parseInt(`${dayC}`)}\u5929\u524D`;
|
|
511
|
+
} else if (hourC >= 1) {
|
|
512
|
+
return `${parseInt(`${hourC}`)}\u5C0F\u65F6\u524D`;
|
|
513
|
+
} else if (minC >= 1) {
|
|
514
|
+
return `${parseInt(`${minC}`)}\u5206\u949F\u524D`;
|
|
515
|
+
}
|
|
516
|
+
return "\u521A\u521A";
|
|
517
|
+
} else {
|
|
518
|
+
return "";
|
|
519
|
+
}
|
|
520
|
+
},
|
|
521
|
+
getDefaultTime() {
|
|
522
|
+
const end = /* @__PURE__ */ new Date();
|
|
523
|
+
const start = /* @__PURE__ */ new Date();
|
|
524
|
+
start.setMonth(start.getMonth() - 1);
|
|
525
|
+
start.setHours(0, 0, 0);
|
|
526
|
+
end.setHours(23, 59, 59);
|
|
527
|
+
return [start, end];
|
|
528
|
+
},
|
|
529
|
+
getSimpleTime() {
|
|
530
|
+
const start = /* @__PURE__ */ new Date();
|
|
531
|
+
start.setHours(0, 0, 0);
|
|
532
|
+
return start;
|
|
533
|
+
},
|
|
534
|
+
getSimpleShortcuts() {
|
|
535
|
+
return [
|
|
536
|
+
{
|
|
537
|
+
text: "\u4ECA\u5929",
|
|
538
|
+
value: () => {
|
|
539
|
+
const date = /* @__PURE__ */ new Date();
|
|
540
|
+
date.setHours(0, 0, 0);
|
|
541
|
+
return date;
|
|
542
|
+
}
|
|
543
|
+
},
|
|
544
|
+
{
|
|
545
|
+
text: "\u6628\u5929",
|
|
546
|
+
value: () => {
|
|
547
|
+
const date = /* @__PURE__ */ new Date();
|
|
548
|
+
date.setDate(date.getDate() - 1);
|
|
549
|
+
date.setHours(0, 0, 0);
|
|
550
|
+
return date;
|
|
551
|
+
}
|
|
552
|
+
},
|
|
553
|
+
{
|
|
554
|
+
text: "\u4E00\u5468\u524D",
|
|
555
|
+
value: () => {
|
|
556
|
+
const date = /* @__PURE__ */ new Date();
|
|
557
|
+
date.setDate(date.getDate() - 7);
|
|
558
|
+
date.setHours(0, 0, 0);
|
|
559
|
+
return date;
|
|
560
|
+
}
|
|
561
|
+
},
|
|
562
|
+
{
|
|
563
|
+
text: "\u4E00\u6708\u524D",
|
|
564
|
+
value: () => {
|
|
565
|
+
const date = /* @__PURE__ */ new Date();
|
|
566
|
+
date.setMonth(date.getMonth() - 1);
|
|
567
|
+
date.setHours(0, 0, 0);
|
|
568
|
+
return date;
|
|
569
|
+
}
|
|
570
|
+
},
|
|
571
|
+
{
|
|
572
|
+
text: "\u4E00\u5E74\u524D",
|
|
573
|
+
value: () => {
|
|
574
|
+
const date = /* @__PURE__ */ new Date();
|
|
575
|
+
date.setFullYear(date.getFullYear() - 1);
|
|
576
|
+
date.setHours(0, 0, 0);
|
|
577
|
+
return date;
|
|
578
|
+
}
|
|
579
|
+
}
|
|
580
|
+
];
|
|
581
|
+
},
|
|
582
|
+
getShortcuts() {
|
|
583
|
+
return [
|
|
584
|
+
{
|
|
585
|
+
text: "\u8FD11\u5929",
|
|
586
|
+
value: () => {
|
|
587
|
+
const end = /* @__PURE__ */ new Date();
|
|
588
|
+
const start = /* @__PURE__ */ new Date();
|
|
589
|
+
start.setDate(start.getDate() - 1);
|
|
590
|
+
start.setHours(0, 0, 0);
|
|
591
|
+
end.setHours(23, 59, 59);
|
|
592
|
+
return [start, end];
|
|
593
|
+
}
|
|
594
|
+
},
|
|
595
|
+
{
|
|
596
|
+
text: "\u8FD13\u5929",
|
|
597
|
+
value: () => {
|
|
598
|
+
const end = /* @__PURE__ */ new Date();
|
|
599
|
+
const start = /* @__PURE__ */ new Date();
|
|
600
|
+
start.setDate(start.getDate() - 3);
|
|
601
|
+
start.setHours(0, 0, 0);
|
|
602
|
+
end.setHours(23, 59, 59);
|
|
603
|
+
return [start, end];
|
|
604
|
+
}
|
|
605
|
+
},
|
|
606
|
+
{
|
|
607
|
+
text: "\u8FD11\u5468",
|
|
608
|
+
value: () => {
|
|
609
|
+
const end = /* @__PURE__ */ new Date();
|
|
610
|
+
const start = /* @__PURE__ */ new Date();
|
|
611
|
+
start.setDate(start.getDate() - 7);
|
|
612
|
+
start.setHours(0, 0, 0);
|
|
613
|
+
end.setHours(23, 59, 59);
|
|
614
|
+
return [start, end];
|
|
615
|
+
}
|
|
616
|
+
},
|
|
617
|
+
{
|
|
618
|
+
text: "\u8FD11\u6708",
|
|
619
|
+
value: () => {
|
|
620
|
+
const end = /* @__PURE__ */ new Date();
|
|
621
|
+
const start = /* @__PURE__ */ new Date();
|
|
622
|
+
start.setMonth(start.getMonth() - 1);
|
|
623
|
+
start.setHours(0, 0, 0);
|
|
624
|
+
end.setHours(23, 59, 59);
|
|
625
|
+
return [start, end];
|
|
626
|
+
}
|
|
627
|
+
},
|
|
628
|
+
{
|
|
629
|
+
text: "\u8FD13\u6708",
|
|
630
|
+
value: () => {
|
|
631
|
+
const end = /* @__PURE__ */ new Date();
|
|
632
|
+
const start = /* @__PURE__ */ new Date();
|
|
633
|
+
start.setMonth(start.getMonth() - 3);
|
|
634
|
+
start.setHours(0, 0, 0);
|
|
635
|
+
end.setHours(23, 59, 59);
|
|
636
|
+
return [start, end];
|
|
637
|
+
}
|
|
638
|
+
},
|
|
639
|
+
{
|
|
640
|
+
text: "\u8FD16\u6708",
|
|
641
|
+
value: () => {
|
|
642
|
+
const end = /* @__PURE__ */ new Date();
|
|
643
|
+
const start = /* @__PURE__ */ new Date();
|
|
644
|
+
start.setMonth(start.getMonth() - 6);
|
|
645
|
+
start.setHours(0, 0, 0);
|
|
646
|
+
end.setHours(23, 59, 59);
|
|
647
|
+
return [start, end];
|
|
648
|
+
}
|
|
649
|
+
},
|
|
650
|
+
{
|
|
651
|
+
text: "\u8FD11\u5E74",
|
|
652
|
+
value: () => {
|
|
653
|
+
const end = /* @__PURE__ */ new Date();
|
|
654
|
+
const start = /* @__PURE__ */ new Date();
|
|
655
|
+
start.setFullYear(start.getFullYear() - 1);
|
|
656
|
+
start.setHours(0, 0, 0);
|
|
657
|
+
end.setHours(23, 59, 59);
|
|
658
|
+
return [start, end];
|
|
659
|
+
}
|
|
660
|
+
}
|
|
661
|
+
];
|
|
662
|
+
},
|
|
663
|
+
getDisabledDate(time) {
|
|
664
|
+
return time.getTime() > Date.now();
|
|
665
|
+
}
|
|
666
|
+
};
|
|
667
|
+
var isStringNumber = (val) => {
|
|
668
|
+
if (!lodashUnified.isString(val)) {
|
|
669
|
+
return false;
|
|
670
|
+
}
|
|
671
|
+
return !Number.isNaN(Number(val));
|
|
672
|
+
};
|
|
673
|
+
var addUnit = (value, defaultUnit = "px") => {
|
|
674
|
+
if (!value) return "";
|
|
675
|
+
if (lodashUnified.isNumber(value) || isStringNumber(value)) {
|
|
676
|
+
return `${value}${defaultUnit}`;
|
|
677
|
+
} else if (lodashUnified.isString(value)) {
|
|
678
|
+
return value;
|
|
679
|
+
}
|
|
680
|
+
consoleWarn("document", "binding value must be a string or number");
|
|
681
|
+
};
|
|
682
|
+
|
|
683
|
+
// src/object/index.ts
|
|
684
|
+
var objectUtil = {
|
|
685
|
+
/**
|
|
686
|
+
* 对象URL参数化
|
|
687
|
+
*/
|
|
688
|
+
objectToQueryString(obj) {
|
|
689
|
+
let params = "";
|
|
690
|
+
for (const key in obj) {
|
|
691
|
+
if (Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
692
|
+
if (params !== "") {
|
|
693
|
+
params += "&";
|
|
694
|
+
}
|
|
695
|
+
params += `${encodeURIComponent(key)}=${encodeURIComponent(obj[key])}`;
|
|
696
|
+
}
|
|
697
|
+
}
|
|
698
|
+
return params;
|
|
699
|
+
},
|
|
700
|
+
/**
|
|
701
|
+
* 是否存在重复值
|
|
702
|
+
*/
|
|
703
|
+
hasDuplicateProperty(arr, prop) {
|
|
704
|
+
const values = arr.map((obj) => obj[prop]);
|
|
705
|
+
const uniqueValues = new Set(values);
|
|
706
|
+
return values.length !== uniqueValues.size;
|
|
707
|
+
},
|
|
708
|
+
/**
|
|
709
|
+
* 是否存在非重复值
|
|
710
|
+
*/
|
|
711
|
+
hasDifferentProperty(arr, prop) {
|
|
712
|
+
const valueSet = /* @__PURE__ */ new Set();
|
|
713
|
+
for (const obj of arr) {
|
|
714
|
+
valueSet.add(obj[prop]);
|
|
715
|
+
if (valueSet.size > 1) {
|
|
716
|
+
return true;
|
|
717
|
+
}
|
|
718
|
+
}
|
|
719
|
+
return false;
|
|
720
|
+
},
|
|
721
|
+
/**
|
|
722
|
+
* 时间处理翻译
|
|
723
|
+
*/
|
|
724
|
+
dateTimeFix(date) {
|
|
725
|
+
if (date !== null && date !== void 0 && date) {
|
|
726
|
+
if (typeof date === "string") {
|
|
727
|
+
date = new Date(date);
|
|
728
|
+
}
|
|
729
|
+
let timestamp = date.getTime();
|
|
730
|
+
if (timestamp.toString().length < 13) {
|
|
731
|
+
const arrTimestamp = timestamp.toString().split("");
|
|
732
|
+
for (let start = 0; start < 13; start++) {
|
|
733
|
+
if (!arrTimestamp[start]) {
|
|
734
|
+
arrTimestamp[start] = "0";
|
|
735
|
+
}
|
|
736
|
+
}
|
|
737
|
+
timestamp = parseInt(arrTimestamp.join(""));
|
|
738
|
+
}
|
|
739
|
+
const minute = 1e3 * 60;
|
|
740
|
+
const hour = minute * 60;
|
|
741
|
+
const day = hour * 24;
|
|
742
|
+
const month = day * 30;
|
|
743
|
+
const curTime = (/* @__PURE__ */ new Date()).getTime();
|
|
744
|
+
const diffValue = curTime - timestamp;
|
|
745
|
+
const monthC = diffValue / month;
|
|
746
|
+
const weekC = diffValue / (7 * day);
|
|
747
|
+
const dayC = diffValue / day;
|
|
748
|
+
const hourC = diffValue / hour;
|
|
749
|
+
const minC = diffValue / minute;
|
|
750
|
+
if (diffValue < 0) {
|
|
751
|
+
const monthC1 = Math.abs(monthC);
|
|
752
|
+
const weekC1 = Math.abs(weekC);
|
|
753
|
+
const dayC1 = Math.abs(dayC);
|
|
754
|
+
const hourC1 = Math.abs(hourC);
|
|
755
|
+
const minC1 = Math.abs(minC);
|
|
756
|
+
if (monthC1 > 12) {
|
|
757
|
+
return `${parseInt(`${monthC1 / 12}`)}\u5E74\u540E`;
|
|
758
|
+
} else if (monthC1 >= 6) {
|
|
759
|
+
return "\u534A\u5E74\u540E";
|
|
760
|
+
} else if (monthC1 >= 1) {
|
|
761
|
+
return `${parseInt(`${monthC1}`)}\u6708\u540E`;
|
|
762
|
+
} else if (weekC1 > 2) {
|
|
763
|
+
return "\u534A\u6708\u540E";
|
|
764
|
+
} else if (weekC1 >= 1) {
|
|
765
|
+
return `${parseInt(`${weekC1}`)}\u5468\u540E`;
|
|
766
|
+
} else if (dayC1 >= 1) {
|
|
767
|
+
return `${parseInt(`${dayC1}`)}\u5929\u540E`;
|
|
768
|
+
} else if (hourC1 >= 1) {
|
|
769
|
+
return `${parseInt(`${hourC1}`)}\u5C0F\u65F6\u540E`;
|
|
770
|
+
} else if (minC1 >= 1) {
|
|
771
|
+
return `${parseInt(`${minC1}`)}\u5206\u949F\u540E`;
|
|
772
|
+
}
|
|
773
|
+
return "\u521A\u521A";
|
|
774
|
+
}
|
|
775
|
+
if (monthC > 12) {
|
|
776
|
+
return `${parseInt(`${monthC / 12}`)}\u5E74\u524D`;
|
|
777
|
+
} else if (monthC >= 6) {
|
|
778
|
+
return "\u534A\u5E74\u524D";
|
|
779
|
+
} else if (monthC >= 1) {
|
|
780
|
+
return `${parseInt(`${monthC}`)}\u6708\u524D`;
|
|
781
|
+
} else if (weekC > 2) {
|
|
782
|
+
return "\u534A\u6708\u524D";
|
|
783
|
+
} else if (weekC >= 1) {
|
|
784
|
+
return `${parseInt(`${weekC}`)}\u5468\u524D`;
|
|
785
|
+
} else if (dayC >= 1) {
|
|
786
|
+
return `${parseInt(`${dayC}`)}\u5929\u524D`;
|
|
787
|
+
} else if (hourC >= 1) {
|
|
788
|
+
return `${parseInt(`${hourC}`)}\u5C0F\u65F6\u524D`;
|
|
789
|
+
} else if (minC >= 1) {
|
|
790
|
+
return `${parseInt(`${minC}`)}\u5206\u949F\u524D`;
|
|
791
|
+
}
|
|
792
|
+
return "\u521A\u521A";
|
|
793
|
+
} else {
|
|
794
|
+
return "";
|
|
795
|
+
}
|
|
796
|
+
}
|
|
797
|
+
};
|
|
798
|
+
var state = vue.reactive({
|
|
799
|
+
prefix: "fast__",
|
|
800
|
+
expireSuffix: "__Expire",
|
|
801
|
+
crypto: false
|
|
802
|
+
});
|
|
803
|
+
var CACHE_PREFIX = vue.computed(() => state.prefix);
|
|
804
|
+
var CACHE_EXPIRE_SUFFIX = vue.computed(() => state.expireSuffix);
|
|
805
|
+
var useStorage = () => {
|
|
806
|
+
return {
|
|
807
|
+
/**
|
|
808
|
+
* 设置缓存前缀 Key
|
|
809
|
+
* @param key
|
|
810
|
+
*/
|
|
811
|
+
prefix(key) {
|
|
812
|
+
state.prefix = key;
|
|
813
|
+
},
|
|
814
|
+
/**
|
|
815
|
+
* 缓存过期值后缀 Key
|
|
816
|
+
* @param key
|
|
817
|
+
*/
|
|
818
|
+
expireSuffix(key) {
|
|
819
|
+
state.expireSuffix = key;
|
|
820
|
+
},
|
|
821
|
+
/**
|
|
822
|
+
* 设置缓存是否加密
|
|
823
|
+
* @param crypto
|
|
824
|
+
*/
|
|
825
|
+
crypto(crypto) {
|
|
826
|
+
state.crypto = crypto;
|
|
827
|
+
}
|
|
828
|
+
};
|
|
829
|
+
};
|
|
830
|
+
var storage = {
|
|
831
|
+
set(key, val) {
|
|
832
|
+
if (typeof uni !== "undefined") {
|
|
833
|
+
uni.setStorageSync(key, val);
|
|
834
|
+
} else {
|
|
835
|
+
window.localStorage.setItem(key, val);
|
|
836
|
+
}
|
|
837
|
+
},
|
|
838
|
+
get(key) {
|
|
839
|
+
if (typeof uni !== "undefined") {
|
|
840
|
+
return uni.getStorageSync(key);
|
|
841
|
+
} else {
|
|
842
|
+
return window.localStorage.getItem(key);
|
|
843
|
+
}
|
|
844
|
+
},
|
|
845
|
+
remove(key) {
|
|
846
|
+
if (typeof uni !== "undefined") {
|
|
847
|
+
uni.removeStorageSync(key);
|
|
848
|
+
} else {
|
|
849
|
+
window.localStorage.removeItem(key);
|
|
850
|
+
}
|
|
851
|
+
},
|
|
852
|
+
clear() {
|
|
853
|
+
if (typeof uni !== "undefined") {
|
|
854
|
+
uni.clearStorageSync();
|
|
855
|
+
} else {
|
|
856
|
+
window.localStorage.clear();
|
|
857
|
+
}
|
|
858
|
+
},
|
|
859
|
+
keys() {
|
|
860
|
+
if (typeof uni !== "undefined") {
|
|
861
|
+
return uni.getStorageInfoSync().keys;
|
|
862
|
+
} else {
|
|
863
|
+
return window.localStorage;
|
|
864
|
+
}
|
|
865
|
+
}
|
|
866
|
+
};
|
|
867
|
+
var Local = {
|
|
868
|
+
/**
|
|
869
|
+
* 设置
|
|
870
|
+
* @param key 缓存的Key
|
|
871
|
+
* @param val 缓存值
|
|
872
|
+
* @param expire 过期时间,单位分钟
|
|
873
|
+
* @param encrypt 是否对缓存的数据加密
|
|
874
|
+
*/
|
|
875
|
+
set(key, val, expire, encrypt) {
|
|
876
|
+
try {
|
|
877
|
+
encrypt ??= state.crypto;
|
|
878
|
+
if (expire) {
|
|
879
|
+
if (isNaN(expire) || expire < 1) {
|
|
880
|
+
throw new Error("\u6709\u6548\u671F\u5E94\u4E3A\u4E00\u4E2A\u6709\u6548\u6570\u503C");
|
|
881
|
+
}
|
|
882
|
+
const expireData = {
|
|
883
|
+
time: Date.now(),
|
|
884
|
+
expire
|
|
885
|
+
};
|
|
886
|
+
const expireJson = JSON.stringify(expireData);
|
|
887
|
+
storage.set(`${state.prefix}${key}${state.expireSuffix}`, expireJson);
|
|
888
|
+
}
|
|
889
|
+
let valJson = JSON.stringify(val);
|
|
890
|
+
if (encrypt) {
|
|
891
|
+
valJson = base64Util.toBase64(valJson);
|
|
892
|
+
}
|
|
893
|
+
storage.set(`${state.prefix}${key}`, valJson);
|
|
894
|
+
} catch (error) {
|
|
895
|
+
consoleError("Local", error);
|
|
896
|
+
}
|
|
897
|
+
},
|
|
898
|
+
/**
|
|
899
|
+
* 获取
|
|
900
|
+
* @param key 缓存的Key
|
|
901
|
+
* @param decrypt 是否对缓存的数据解密
|
|
902
|
+
* @returns {T} 传入的对象类型,默认为 string
|
|
903
|
+
*/
|
|
904
|
+
get(key, decrypt) {
|
|
905
|
+
try {
|
|
906
|
+
decrypt ??= state.crypto;
|
|
907
|
+
let valJson = storage.get(`${state.prefix}${key}`);
|
|
908
|
+
if (valJson) {
|
|
909
|
+
if (decrypt) {
|
|
910
|
+
valJson = base64Util.base64ToStr(valJson);
|
|
911
|
+
}
|
|
912
|
+
const expireJson = storage.get(`${state.prefix}${key}${state.expireSuffix}`);
|
|
913
|
+
if (expireJson) {
|
|
914
|
+
const expireData = JSON.parse(expireJson);
|
|
915
|
+
if (Date.now() > expireData.time + expireData.expire * 60 * 1e3) {
|
|
916
|
+
storage.remove(`${state.prefix}${key}`);
|
|
917
|
+
storage.remove(`${state.prefix}${key}${state.expireSuffix}`);
|
|
918
|
+
return null;
|
|
919
|
+
}
|
|
920
|
+
}
|
|
921
|
+
try {
|
|
922
|
+
return JSON.parse(valJson);
|
|
923
|
+
} catch {
|
|
924
|
+
return valJson;
|
|
925
|
+
}
|
|
926
|
+
}
|
|
927
|
+
return null;
|
|
928
|
+
} catch (error) {
|
|
929
|
+
consoleError("Local", error);
|
|
930
|
+
}
|
|
931
|
+
},
|
|
932
|
+
/**
|
|
933
|
+
* 移除
|
|
934
|
+
* @param key 缓存的Key
|
|
935
|
+
*/
|
|
936
|
+
remove(key) {
|
|
937
|
+
try {
|
|
938
|
+
storage.remove(`${state.prefix}${key}`);
|
|
939
|
+
storage.remove(`${state.prefix}${key}${state.expireSuffix}`);
|
|
940
|
+
} catch (error) {
|
|
941
|
+
consoleError("Local", error);
|
|
942
|
+
}
|
|
943
|
+
},
|
|
944
|
+
/**
|
|
945
|
+
* 根据前缀移除
|
|
946
|
+
* @param key 缓存的Key
|
|
947
|
+
*/
|
|
948
|
+
removeByPrefix(key) {
|
|
949
|
+
try {
|
|
950
|
+
for (const itemKey in storage.keys) {
|
|
951
|
+
if (itemKey.indexOf(`${state.prefix}${key}`) !== -1) {
|
|
952
|
+
storage.remove(itemKey);
|
|
953
|
+
}
|
|
954
|
+
}
|
|
955
|
+
} catch (error) {
|
|
956
|
+
consoleError("Local", error);
|
|
957
|
+
}
|
|
958
|
+
},
|
|
959
|
+
/**
|
|
960
|
+
* 移除全部
|
|
961
|
+
*/
|
|
962
|
+
clear() {
|
|
963
|
+
try {
|
|
964
|
+
storage.clear();
|
|
965
|
+
} catch (error) {
|
|
966
|
+
consoleError("Local", error);
|
|
967
|
+
}
|
|
968
|
+
}
|
|
969
|
+
};
|
|
970
|
+
var Session = {
|
|
971
|
+
/**
|
|
972
|
+
* 设置会话缓存
|
|
973
|
+
* @param key 缓存的Key
|
|
974
|
+
* @param val 缓存值
|
|
975
|
+
* @param expire 过期时间,单位分钟
|
|
976
|
+
* @param encrypt 是否对缓存的数据加密
|
|
977
|
+
*/
|
|
978
|
+
set(key, val, expire, encrypt) {
|
|
979
|
+
if (typeof uni !== "undefined") {
|
|
980
|
+
consoleError("Session", "UniApp \u73AF\u5883\u4E0B [Session] \u4E0D\u53EF\u7528\u3002");
|
|
981
|
+
return;
|
|
982
|
+
}
|
|
983
|
+
try {
|
|
984
|
+
encrypt ??= state.crypto;
|
|
985
|
+
if (expire) {
|
|
986
|
+
if (isNaN(expire) || expire < 1) {
|
|
987
|
+
throw new Error("\u6709\u6548\u671F\u5E94\u4E3A\u4E00\u4E2A\u6709\u6548\u6570\u503C");
|
|
988
|
+
}
|
|
989
|
+
const expireData = {
|
|
990
|
+
time: Date.now(),
|
|
991
|
+
expire
|
|
992
|
+
};
|
|
993
|
+
const expireJson = JSON.stringify(expireData);
|
|
994
|
+
window.sessionStorage.setItem(`${state.prefix}${key}${state.expireSuffix}`, expireJson);
|
|
995
|
+
}
|
|
996
|
+
let valJson = JSON.stringify(val);
|
|
997
|
+
if (encrypt) {
|
|
998
|
+
valJson = base64Util.toBase64(valJson);
|
|
999
|
+
}
|
|
1000
|
+
window.sessionStorage.setItem(`${state.prefix}${key}`, valJson);
|
|
1001
|
+
} catch (error) {
|
|
1002
|
+
consoleError("Session", error);
|
|
1003
|
+
}
|
|
1004
|
+
},
|
|
1005
|
+
/**
|
|
1006
|
+
* 获取会话缓存
|
|
1007
|
+
* @param key 缓存的Key
|
|
1008
|
+
* @param decrypt 是否对缓存的数据解密
|
|
1009
|
+
* @returns {T} 传入的对象类型,默认为 string
|
|
1010
|
+
*/
|
|
1011
|
+
get(key, decrypt) {
|
|
1012
|
+
if (typeof uni !== "undefined") {
|
|
1013
|
+
consoleError("Session", "UniApp \u73AF\u5883\u4E0B [Session] \u4E0D\u53EF\u7528\u3002");
|
|
1014
|
+
return;
|
|
1015
|
+
}
|
|
1016
|
+
try {
|
|
1017
|
+
decrypt ??= state.crypto;
|
|
1018
|
+
let valJson = window.sessionStorage.getItem(`${state.prefix}${key}`);
|
|
1019
|
+
if (valJson) {
|
|
1020
|
+
if (decrypt) {
|
|
1021
|
+
valJson = base64Util.base64ToStr(valJson);
|
|
1022
|
+
}
|
|
1023
|
+
const expireJson = window.sessionStorage.getItem(`${state.prefix}${key}${state.expireSuffix}`);
|
|
1024
|
+
if (expireJson) {
|
|
1025
|
+
const expireData = JSON.parse(expireJson);
|
|
1026
|
+
if (Date.now() > expireData.time + expireData.expire * 60 * 1e3) {
|
|
1027
|
+
window.sessionStorage.removeItem(`${state.prefix}${key}`);
|
|
1028
|
+
window.sessionStorage.removeItem(`${state.prefix}${key}${state.expireSuffix}`);
|
|
1029
|
+
return null;
|
|
1030
|
+
}
|
|
1031
|
+
}
|
|
1032
|
+
try {
|
|
1033
|
+
return JSON.parse(valJson);
|
|
1034
|
+
} catch {
|
|
1035
|
+
return valJson;
|
|
1036
|
+
}
|
|
1037
|
+
}
|
|
1038
|
+
return null;
|
|
1039
|
+
} catch (error) {
|
|
1040
|
+
consoleError("Session", error);
|
|
1041
|
+
}
|
|
1042
|
+
},
|
|
1043
|
+
/**
|
|
1044
|
+
* 移除会话缓存
|
|
1045
|
+
* @param key 缓存的Key
|
|
1046
|
+
*/
|
|
1047
|
+
remove(key) {
|
|
1048
|
+
if (typeof uni !== "undefined") {
|
|
1049
|
+
consoleError("Session", "UniApp \u73AF\u5883\u4E0B [Session] \u4E0D\u53EF\u7528\u3002");
|
|
1050
|
+
return;
|
|
1051
|
+
}
|
|
1052
|
+
try {
|
|
1053
|
+
window.sessionStorage.removeItem(`${state.prefix}${key}`);
|
|
1054
|
+
window.sessionStorage.removeItem(`${state.prefix}${key}${state.expireSuffix}`);
|
|
1055
|
+
} catch (error) {
|
|
1056
|
+
consoleError("Session", error);
|
|
1057
|
+
}
|
|
1058
|
+
},
|
|
1059
|
+
/**
|
|
1060
|
+
* 根据前缀移除会话缓存
|
|
1061
|
+
* @param key 缓存的Key
|
|
1062
|
+
*/
|
|
1063
|
+
removeByPrefix(key) {
|
|
1064
|
+
if (typeof uni !== "undefined") {
|
|
1065
|
+
consoleError("Session", "UniApp \u73AF\u5883\u4E0B [Session] \u4E0D\u53EF\u7528\u3002");
|
|
1066
|
+
return;
|
|
1067
|
+
}
|
|
1068
|
+
try {
|
|
1069
|
+
for (const itemKey in window.sessionStorage) {
|
|
1070
|
+
if (itemKey.indexOf(`${state.prefix}${key}`) !== -1) {
|
|
1071
|
+
window.sessionStorage.removeItem(itemKey);
|
|
1072
|
+
}
|
|
1073
|
+
}
|
|
1074
|
+
} catch (error) {
|
|
1075
|
+
consoleError("Session", error);
|
|
1076
|
+
}
|
|
1077
|
+
},
|
|
1078
|
+
/**
|
|
1079
|
+
* 移除全部会话缓存
|
|
1080
|
+
*/
|
|
1081
|
+
clear() {
|
|
1082
|
+
if (typeof uni !== "undefined") {
|
|
1083
|
+
consoleError("Session", "UniApp \u73AF\u5883\u4E0B [Session] \u4E0D\u53EF\u7528\u3002");
|
|
1084
|
+
return;
|
|
1085
|
+
}
|
|
1086
|
+
try {
|
|
1087
|
+
window.sessionStorage.clear();
|
|
1088
|
+
} catch (error) {
|
|
1089
|
+
consoleError("Session", error);
|
|
1090
|
+
}
|
|
1091
|
+
}
|
|
1092
|
+
};
|
|
1093
|
+
var stringUtil = {
|
|
1094
|
+
/**
|
|
1095
|
+
* 获取Url参数
|
|
1096
|
+
*/
|
|
1097
|
+
getUrlParams(url) {
|
|
1098
|
+
const regex = /[?&][^=?&]+=[^?&]+/g;
|
|
1099
|
+
const params = {};
|
|
1100
|
+
let match;
|
|
1101
|
+
while ((match = regex.exec(url)) !== null) {
|
|
1102
|
+
const [key, value] = match[0].substring(1).split("=");
|
|
1103
|
+
params[key] = decodeURIComponent(value);
|
|
1104
|
+
}
|
|
1105
|
+
return params;
|
|
1106
|
+
},
|
|
1107
|
+
/**
|
|
1108
|
+
* 是否为JSON字符串
|
|
1109
|
+
*/
|
|
1110
|
+
isJson(value) {
|
|
1111
|
+
if (!lodashUnified.isString(value)) return false;
|
|
1112
|
+
value = value.replace(/\s/g, "").replace(/\n|\r/, "");
|
|
1113
|
+
if (/^\{(.*?)\}$/.test(value)) return /"(.*?)":(.*?)/g.test(value);
|
|
1114
|
+
if (/^\[(.*?)\]$/.test(value)) {
|
|
1115
|
+
return value.replace(/^\[/, "").replace(/\]$/, "").replace(/},{/g, "}\n{").split(/\n/).map((s) => {
|
|
1116
|
+
return stringUtil.isJson(s);
|
|
1117
|
+
}).reduce((prev, curr) => {
|
|
1118
|
+
return !!curr;
|
|
1119
|
+
});
|
|
1120
|
+
}
|
|
1121
|
+
return false;
|
|
1122
|
+
},
|
|
1123
|
+
/**
|
|
1124
|
+
* 生成随机字符串
|
|
1125
|
+
*/
|
|
1126
|
+
generateRandomString(length) {
|
|
1127
|
+
const characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
|
1128
|
+
let randomString = "";
|
|
1129
|
+
for (let i = 0; i < length; i++) {
|
|
1130
|
+
const randomIndex = Math.floor(Math.random() * characters.length);
|
|
1131
|
+
randomString += characters.charAt(randomIndex);
|
|
1132
|
+
}
|
|
1133
|
+
return randomString;
|
|
1134
|
+
},
|
|
1135
|
+
/**
|
|
1136
|
+
* @description 生成唯一 uuid
|
|
1137
|
+
*/
|
|
1138
|
+
generateUUID() {
|
|
1139
|
+
let uuid = "";
|
|
1140
|
+
for (let i = 0; i < 32; i++) {
|
|
1141
|
+
const random = Math.random() * 16 | 0;
|
|
1142
|
+
if (i === 8 || i === 12 || i === 16 || i === 20) uuid += "-";
|
|
1143
|
+
uuid += (i === 12 ? 4 : i === 16 ? random & 3 | 8 : random).toString(16);
|
|
1144
|
+
}
|
|
1145
|
+
return uuid;
|
|
1146
|
+
},
|
|
1147
|
+
/**
|
|
1148
|
+
* 复制
|
|
1149
|
+
*/
|
|
1150
|
+
async copy(value) {
|
|
1151
|
+
if (typeof uni !== "undefined") {
|
|
1152
|
+
return new Promise((resolve, reject) => {
|
|
1153
|
+
uni.setClipboardData({
|
|
1154
|
+
data: value,
|
|
1155
|
+
success: () => {
|
|
1156
|
+
resolve();
|
|
1157
|
+
},
|
|
1158
|
+
fail: () => {
|
|
1159
|
+
reject();
|
|
1160
|
+
}
|
|
1161
|
+
});
|
|
1162
|
+
});
|
|
1163
|
+
} else {
|
|
1164
|
+
if (navigator?.clipboard && window.isSecureContext) {
|
|
1165
|
+
await navigator.clipboard.writeText(value);
|
|
1166
|
+
} else {
|
|
1167
|
+
const textareaEl = document.createElement("textarea");
|
|
1168
|
+
textareaEl.value = value;
|
|
1169
|
+
textareaEl.style.position = "absolute";
|
|
1170
|
+
textareaEl.style.opacity = "0";
|
|
1171
|
+
textareaEl.style.left = "-999999px";
|
|
1172
|
+
textareaEl.style.top = "-999999px";
|
|
1173
|
+
document.body.appendChild(textareaEl);
|
|
1174
|
+
textareaEl.focus();
|
|
1175
|
+
textareaEl.select();
|
|
1176
|
+
document.execCommand("copy");
|
|
1177
|
+
textareaEl.remove();
|
|
1178
|
+
}
|
|
1179
|
+
}
|
|
1180
|
+
}
|
|
1181
|
+
};
|
|
1182
|
+
|
|
1183
|
+
// src/vue/expose.ts
|
|
1184
|
+
var useExpose = (expose, exposed) => {
|
|
1185
|
+
expose(exposed);
|
|
1186
|
+
return exposed;
|
|
1187
|
+
};
|
|
1188
|
+
|
|
1189
|
+
// src/vue/func.ts
|
|
1190
|
+
var execFunction = async (fn, ...args) => {
|
|
1191
|
+
if (!fn) return Promise.resolve(void 0);
|
|
1192
|
+
if (fn.constructor.name === "AsyncFunction") {
|
|
1193
|
+
try {
|
|
1194
|
+
return await fn(...args);
|
|
1195
|
+
} catch (error) {
|
|
1196
|
+
consoleError("execFunction", error);
|
|
1197
|
+
return Promise.reject(error);
|
|
1198
|
+
}
|
|
1199
|
+
} else {
|
|
1200
|
+
return new Promise((resolve, reject) => {
|
|
1201
|
+
try {
|
|
1202
|
+
const res = fn(...args);
|
|
1203
|
+
return resolve(res);
|
|
1204
|
+
} catch (error) {
|
|
1205
|
+
consoleError("execFunction", error);
|
|
1206
|
+
return reject(error);
|
|
1207
|
+
}
|
|
1208
|
+
});
|
|
1209
|
+
}
|
|
1210
|
+
};
|
|
1211
|
+
|
|
1212
|
+
// src/vue/install.ts
|
|
1213
|
+
var NOOP = () => {
|
|
1214
|
+
};
|
|
1215
|
+
var withInstall = (main, extra) => {
|
|
1216
|
+
main.install = (app) => {
|
|
1217
|
+
for (const comp of [main, ...Object.values(extra ?? {})]) {
|
|
1218
|
+
app.component(comp.name, comp);
|
|
1219
|
+
}
|
|
1220
|
+
};
|
|
1221
|
+
if (extra) {
|
|
1222
|
+
for (const [key, comp] of Object.entries(extra)) {
|
|
1223
|
+
main[key] = comp;
|
|
1224
|
+
}
|
|
1225
|
+
}
|
|
1226
|
+
return main;
|
|
1227
|
+
};
|
|
1228
|
+
var withNoopInstall = (component) => {
|
|
1229
|
+
component.install = NOOP;
|
|
1230
|
+
return component;
|
|
1231
|
+
};
|
|
1232
|
+
var withInstallDirective = (directive, name) => {
|
|
1233
|
+
directive.install = (app) => {
|
|
1234
|
+
app.directive(name, directive);
|
|
1235
|
+
};
|
|
1236
|
+
return directive;
|
|
1237
|
+
};
|
|
1238
|
+
var definePropType = (val) => val;
|
|
1239
|
+
var useProps = (props, rawProps, ignoreRawProps) => {
|
|
1240
|
+
if (!props) return vue.computed(() => ({}));
|
|
1241
|
+
return vue.computed(() => {
|
|
1242
|
+
const omittedRawProps = rawProps ? lodashUnified.omit(rawProps, ignoreRawProps ?? []) : {};
|
|
1243
|
+
return lodashUnified.pick(props, Object.keys(omittedRawProps));
|
|
1244
|
+
});
|
|
1245
|
+
};
|
|
1246
|
+
|
|
1247
|
+
// src/vue/slots.ts
|
|
1248
|
+
var makeSlots = () => {
|
|
1249
|
+
return Object;
|
|
1250
|
+
};
|
|
1251
|
+
var useRender = (render) => {
|
|
1252
|
+
const vm = vue.getCurrentInstance();
|
|
1253
|
+
if (!vm) {
|
|
1254
|
+
throw new Error("useRender must be called from inside a setup function");
|
|
1255
|
+
}
|
|
1256
|
+
vm.render = render;
|
|
1257
|
+
};
|
|
1258
|
+
|
|
1259
|
+
// src/vue/with.ts
|
|
1260
|
+
var withDefineType = (data = void 0) => {
|
|
1261
|
+
return data;
|
|
1262
|
+
};
|
|
1263
|
+
|
|
1264
|
+
exports.CACHE_EXPIRE_SUFFIX = CACHE_EXPIRE_SUFFIX;
|
|
1265
|
+
exports.CACHE_PREFIX = CACHE_PREFIX;
|
|
1266
|
+
exports.FastError = FastError;
|
|
1267
|
+
exports.Local = Local;
|
|
1268
|
+
exports.Session = Session;
|
|
1269
|
+
exports.addUnit = addUnit;
|
|
1270
|
+
exports.base64Util = base64Util;
|
|
1271
|
+
exports.clickUtil = clickUtil;
|
|
1272
|
+
exports.colorUtil = colorUtil;
|
|
1273
|
+
exports.consoleDebug = consoleDebug;
|
|
1274
|
+
exports.consoleError = consoleError;
|
|
1275
|
+
exports.consoleLog = consoleLog;
|
|
1276
|
+
exports.consoleWarn = consoleWarn;
|
|
1277
|
+
exports.cryptoUtil = cryptoUtil;
|
|
1278
|
+
exports.dateUtil = dateUtil;
|
|
1279
|
+
exports.definePropType = definePropType;
|
|
1280
|
+
exports.execFunction = execFunction;
|
|
1281
|
+
exports.makeSlots = makeSlots;
|
|
1282
|
+
exports.objectUtil = objectUtil;
|
|
1283
|
+
exports.stringUtil = stringUtil;
|
|
1284
|
+
exports.throwError = throwError;
|
|
1285
|
+
exports.useExpose = useExpose;
|
|
1286
|
+
exports.useProps = useProps;
|
|
1287
|
+
exports.useRender = useRender;
|
|
1288
|
+
exports.useStorage = useStorage;
|
|
1289
|
+
exports.withDefineType = withDefineType;
|
|
1290
|
+
exports.withInstall = withInstall;
|
|
1291
|
+
exports.withInstallDirective = withInstallDirective;
|
|
1292
|
+
exports.withNoopInstall = withNoopInstall;
|
|
1293
|
+
//# sourceMappingURL=index.cjs.map
|
|
1294
|
+
//# sourceMappingURL=index.cjs.map
|