@sybz-components/utils 0.0.5 → 0.0.6
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/base.cjs +33 -14
- package/dist/base.d.cts +555 -1
- package/dist/base.d.mts +555 -1
- package/dist/base.d.ts +555 -1
- package/dist/base.mjs +6 -60
- package/dist/day.cjs +38 -13
- package/dist/day.d.cts +81 -1
- package/dist/day.d.mts +81 -1
- package/dist/day.d.ts +81 -1
- package/dist/day.mjs +28 -21
- package/dist/format.cjs +17 -14
- package/dist/format.d.cts +208 -1
- package/dist/format.d.mts +208 -1
- package/dist/format.d.ts +208 -1
- package/dist/format.mjs +6 -27
- package/dist/index.cjs +75 -14
- package/dist/index.d.cts +10 -1
- package/dist/index.d.mts +10 -1
- package/dist/index.d.ts +10 -1
- package/dist/index.mjs +11 -101
- package/dist/is.cjs +63 -13
- package/dist/is.d.cts +248 -1
- package/dist/is.d.mts +248 -1
- package/dist/is.d.ts +248 -1
- package/dist/is.mjs +41 -38
- package/dist/shared/utils.DrwfWQ1C.cjs +957 -0
- package/dist/shared/utils.SMYVKGgi.mjs +923 -0
- package/dist/test.cjs +5 -14
- package/dist/test.d.cts +14 -1
- package/dist/test.d.mts +14 -1
- package/dist/test.d.ts +14 -1
- package/dist/test.mjs +4 -17
- package/dist/ws.cjs +171 -12
- package/dist/ws.d.cts +165 -1
- package/dist/ws.d.mts +165 -1
- package/dist/ws.d.ts +165 -1
- package/dist/ws.mjs +165 -14
- package/package.json +1 -1
|
@@ -0,0 +1,923 @@
|
|
|
1
|
+
import { isRef, unref, toRaw } from '@vue/reactivity';
|
|
2
|
+
import { consola } from 'consola';
|
|
3
|
+
import { cloneDeep } from 'es-toolkit';
|
|
4
|
+
import { ElMessage, ElMessageBox } from 'element-plus';
|
|
5
|
+
import { isStringNumber, isNumber } from '../is.mjs';
|
|
6
|
+
|
|
7
|
+
function formatBytes(bytes, options = {}) {
|
|
8
|
+
let { digit = 2, thousands = false, prefix = "", suffix = "", roundType = "floor" } = options;
|
|
9
|
+
if (isStringNumber(bytes) || isNumber(bytes)) {
|
|
10
|
+
bytes = Number(bytes);
|
|
11
|
+
} else {
|
|
12
|
+
return bytes;
|
|
13
|
+
}
|
|
14
|
+
if (bytes <= 1) {
|
|
15
|
+
return Math[roundType](bytes * Math.pow(10, digit)) / Math.pow(10, digit) + " B";
|
|
16
|
+
}
|
|
17
|
+
const k = 1024;
|
|
18
|
+
const sizes = ["B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"];
|
|
19
|
+
const i = Math.floor(Math.log(bytes) / Math.log(k));
|
|
20
|
+
const power = Math.pow(k, i);
|
|
21
|
+
let num = bytes / power;
|
|
22
|
+
num = Math[roundType](num * Math.pow(10, digit)) / Math.pow(10, digit);
|
|
23
|
+
let res = num.toFixed(digit) + " " + sizes[i];
|
|
24
|
+
if (thousands) {
|
|
25
|
+
res = String(formatThousands(res));
|
|
26
|
+
}
|
|
27
|
+
return `${prefix}${res}${suffix}`;
|
|
28
|
+
}
|
|
29
|
+
function formatBytesConvert(oBytes, options = {}) {
|
|
30
|
+
let { thounsands = false, digit = 0 } = options;
|
|
31
|
+
let bytes = oBytes;
|
|
32
|
+
const parseDigitThounsands = (val) => {
|
|
33
|
+
let finalRes = val;
|
|
34
|
+
if (digit) {
|
|
35
|
+
finalRes = Number(finalRes).toFixed(digit);
|
|
36
|
+
}
|
|
37
|
+
if (thounsands) {
|
|
38
|
+
finalRes = formatThousands(finalRes);
|
|
39
|
+
}
|
|
40
|
+
return finalRes;
|
|
41
|
+
};
|
|
42
|
+
if (isStringNumber(oBytes) || isNumber(oBytes) || getType(oBytes) !== "string") {
|
|
43
|
+
return parseDigitThounsands(oBytes);
|
|
44
|
+
}
|
|
45
|
+
if (!oBytes) {
|
|
46
|
+
return parseDigitThounsands(oBytes);
|
|
47
|
+
}
|
|
48
|
+
const regex = /^\d{1,3}(,\d{3})*(\.\d+)?[a-zA-Z ]*$/;
|
|
49
|
+
if (typeof oBytes === "string" && regex.test(oBytes)) {
|
|
50
|
+
bytes = oBytes.replace(/,/g, "");
|
|
51
|
+
if (isStringNumber(bytes) || isNumber(bytes) || getType(bytes) !== "string") {
|
|
52
|
+
return parseDigitThounsands(bytes);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
const bytesRegex = /^(\d+(?:\.\d+)?)\s*([BKMGTPEZY]?B|Byte)$/i;
|
|
56
|
+
const units = {
|
|
57
|
+
B: 1,
|
|
58
|
+
BYTE: 1,
|
|
59
|
+
KB: 1024,
|
|
60
|
+
MB: 1024 ** 2,
|
|
61
|
+
GB: 1024 ** 3,
|
|
62
|
+
TB: 1024 ** 4,
|
|
63
|
+
PB: 1024 ** 5,
|
|
64
|
+
EB: 1024 ** 6,
|
|
65
|
+
ZB: 1024 ** 7,
|
|
66
|
+
YB: 1024 ** 8
|
|
67
|
+
};
|
|
68
|
+
if (typeof bytes !== "string") {
|
|
69
|
+
return parseDigitThounsands(bytes);
|
|
70
|
+
}
|
|
71
|
+
const match = bytes.match(bytesRegex);
|
|
72
|
+
if (!match) {
|
|
73
|
+
console.warn("Invalid bytes format. Please provide a valid bytes string, like '100GB'.");
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
const size = parseFloat(match[1]);
|
|
77
|
+
const unit = match[2].toUpperCase();
|
|
78
|
+
if (!Object.prototype.hasOwnProperty.call(units, unit)) {
|
|
79
|
+
console.warn(
|
|
80
|
+
"Invalid bytes unit. Please provide a valid unit, like 'B', 'BYTE', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', or 'YB'."
|
|
81
|
+
);
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
return parseDigitThounsands(size * units[unit]);
|
|
85
|
+
}
|
|
86
|
+
function formatThousands(value) {
|
|
87
|
+
const matches = ("" + value).match(/^([\d,]+)(\.?)(\d+)?(\D+)?$/);
|
|
88
|
+
if (!matches) {
|
|
89
|
+
return value;
|
|
90
|
+
}
|
|
91
|
+
const numericString = matches[1].replace(/\D/g, "");
|
|
92
|
+
const decimalString = matches[3] ? `.${matches[3]}` : "";
|
|
93
|
+
const unit = matches[4] || "";
|
|
94
|
+
const numberWithSeparator = numericString.replace(/\B(?=(\d{3})+(?!\d))/g, ",");
|
|
95
|
+
return `${numberWithSeparator}${decimalString}${unit}`;
|
|
96
|
+
}
|
|
97
|
+
function formatTime(time = /* @__PURE__ */ new Date(), cFormat = "{y}-{m}-{d} {h}:{i}:{s}", fallback = (value) => String(value)) {
|
|
98
|
+
let date;
|
|
99
|
+
const timeStr = String(time);
|
|
100
|
+
if (typeof time === "object" && time instanceof Date) {
|
|
101
|
+
date = time;
|
|
102
|
+
} else {
|
|
103
|
+
const isoRegex = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}(?::\d{2}(?:\.\d{1,3})?)?$/;
|
|
104
|
+
const dateOnlyRegex = /^(\d{4})-(\d{2})-(\d{2})$/;
|
|
105
|
+
if (isoRegex.test(timeStr)) {
|
|
106
|
+
date = new Date(time);
|
|
107
|
+
} else if (dateOnlyRegex.test(timeStr)) {
|
|
108
|
+
const [, year, month, day] = timeStr.match(dateOnlyRegex);
|
|
109
|
+
date = new Date(Number(year), Number(month) - 1, Number(day));
|
|
110
|
+
} else if (timeStr.includes(".") && !isNaN(parseFloat(timeStr))) {
|
|
111
|
+
date = new Date(parseFloat(timeStr) * 1e3);
|
|
112
|
+
} else if (/^\d{10}$/.test(timeStr)) {
|
|
113
|
+
date = new Date(parseInt(timeStr) * 1e3);
|
|
114
|
+
} else {
|
|
115
|
+
date = new Date(time);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
if (isNaN(date.getTime())) {
|
|
119
|
+
return typeof fallback === "function" ? fallback(time) : fallback;
|
|
120
|
+
}
|
|
121
|
+
const formatObj = {
|
|
122
|
+
y: date.getFullYear(),
|
|
123
|
+
m: date.getMonth() + 1,
|
|
124
|
+
d: date.getDate(),
|
|
125
|
+
h: date.getHours(),
|
|
126
|
+
i: date.getMinutes(),
|
|
127
|
+
s: date.getSeconds(),
|
|
128
|
+
a: date.getDay()
|
|
129
|
+
};
|
|
130
|
+
return cFormat.replace(/{(y|m|d|h|i|s|a)+}/g, (result, key) => {
|
|
131
|
+
const value = formatObj[key];
|
|
132
|
+
if (key === "a") {
|
|
133
|
+
return ["\u65E5", "\u4E00", "\u4E8C", "\u4E09", "\u56DB", "\u4E94", "\u516D"][value];
|
|
134
|
+
}
|
|
135
|
+
if (result.length > 0 && value < 10) {
|
|
136
|
+
return "0" + value;
|
|
137
|
+
}
|
|
138
|
+
return String(value);
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
function formatDurationTime(timestamp, cFormat = "{d}\u5929{h}\u65F6{i}\u5206{s}\u79D2") {
|
|
142
|
+
const secondsPerMinute = 60;
|
|
143
|
+
const minutesPerHour = 60;
|
|
144
|
+
const hoursPerDay = 24;
|
|
145
|
+
let totalSeconds = Math.floor(timestamp / 1e3);
|
|
146
|
+
let days = 0;
|
|
147
|
+
if (cFormat.indexOf("d") !== -1) {
|
|
148
|
+
days = Math.floor(totalSeconds / (secondsPerMinute * minutesPerHour * hoursPerDay));
|
|
149
|
+
totalSeconds %= secondsPerMinute * minutesPerHour * hoursPerDay;
|
|
150
|
+
}
|
|
151
|
+
const hours = Math.floor(totalSeconds / (secondsPerMinute * minutesPerHour));
|
|
152
|
+
totalSeconds %= secondsPerMinute * minutesPerHour;
|
|
153
|
+
const minutes = Math.floor(totalSeconds / secondsPerMinute);
|
|
154
|
+
const seconds = totalSeconds % secondsPerMinute;
|
|
155
|
+
const formatObj = {
|
|
156
|
+
d: days,
|
|
157
|
+
h: hours,
|
|
158
|
+
i: minutes,
|
|
159
|
+
s: seconds
|
|
160
|
+
};
|
|
161
|
+
let parseFormat = cFormat;
|
|
162
|
+
if (days === 0) {
|
|
163
|
+
parseFormat = cFormat.match(/{h}.*/g)?.[0] ?? "";
|
|
164
|
+
if (hours === 0) {
|
|
165
|
+
parseFormat = cFormat.match(/{i}.*/g)?.[0] ?? "";
|
|
166
|
+
if (minutes === 0) {
|
|
167
|
+
parseFormat = cFormat.match(/{s}.*/g)?.[0] ?? "";
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
return parseFormat.replace(/{(y|m|d|h|i|s)+}/g, (result, key) => {
|
|
172
|
+
let value = formatObj[key];
|
|
173
|
+
if (result.length > 0 && value < 10 && value !== 0) {
|
|
174
|
+
return `0${value}`;
|
|
175
|
+
}
|
|
176
|
+
return String(value || "00");
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
function formatImg(photoName, addPath = "", { basePath = "assets/images" } = {}) {
|
|
180
|
+
if (photoName.startsWith("http") || photoName.startsWith("https")) {
|
|
181
|
+
return photoName;
|
|
182
|
+
}
|
|
183
|
+
if (photoName.indexOf(".") === -1) {
|
|
184
|
+
photoName = photoName + ".png";
|
|
185
|
+
}
|
|
186
|
+
const addLastSlash = addPath.endsWith("/") || !addPath ? addPath : `${addPath}/`;
|
|
187
|
+
const addLastBasePathSlash = basePath.endsWith("/") || !basePath ? basePath : `${basePath}/`;
|
|
188
|
+
const mergeSrc = `${addLastSlash}${photoName}`;
|
|
189
|
+
return new URL(`../${addLastBasePathSlash}${mergeSrc}`, import.meta.url).href;
|
|
190
|
+
}
|
|
191
|
+
function formatToFixed(value, options) {
|
|
192
|
+
if (typeof options === "number") {
|
|
193
|
+
options = { digit: options };
|
|
194
|
+
}
|
|
195
|
+
const finalOptions = {
|
|
196
|
+
digit: 2,
|
|
197
|
+
prefix: "",
|
|
198
|
+
suffix: "",
|
|
199
|
+
unit: true,
|
|
200
|
+
thousands: false,
|
|
201
|
+
...options
|
|
202
|
+
};
|
|
203
|
+
const { digit, prefix, suffix, unit, thousands } = finalOptions;
|
|
204
|
+
const matches = ("" + value).match(/^([\d,]+)(\.?)(\d+)?(\D+)?$/);
|
|
205
|
+
if (!matches) {
|
|
206
|
+
return String(value);
|
|
207
|
+
}
|
|
208
|
+
const numericString = matches[1].replace(/\D/g, "");
|
|
209
|
+
const decimalString = matches[3] ? `.${matches[3]}` : "";
|
|
210
|
+
let finalUnit = matches[4] || "";
|
|
211
|
+
let res = numericString;
|
|
212
|
+
if (isStringNumber(numericString) || isNumber(numericString)) {
|
|
213
|
+
res = Number(numericString + decimalString).toFixed(digit);
|
|
214
|
+
}
|
|
215
|
+
if (thousands) {
|
|
216
|
+
res = String(formatThousands(res));
|
|
217
|
+
}
|
|
218
|
+
if (!unit) {
|
|
219
|
+
finalUnit = "";
|
|
220
|
+
}
|
|
221
|
+
return `${prefix}${res}${finalUnit}${suffix}`;
|
|
222
|
+
}
|
|
223
|
+
function formatTextToHtml(str) {
|
|
224
|
+
if (!str || typeof str !== "string") {
|
|
225
|
+
return str;
|
|
226
|
+
}
|
|
227
|
+
str = str.replace(/\n/g, "<br>");
|
|
228
|
+
str = str.replace(/\t/g, " ");
|
|
229
|
+
return str;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
const DEFAULT_CONFIRM_BUTTON_CLASS = "s-message-box__confirm-btn";
|
|
233
|
+
const DEFAULT_CANCEL_BUTTON_CLASS = "s-message-box__cancel-btn";
|
|
234
|
+
function _getBrowserStorage(isSession = false) {
|
|
235
|
+
if (typeof window === "undefined") {
|
|
236
|
+
return null;
|
|
237
|
+
}
|
|
238
|
+
try {
|
|
239
|
+
return isSession ? window.sessionStorage : window.localStorage;
|
|
240
|
+
} catch (error) {
|
|
241
|
+
return null;
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
function _parseStorageValue(value) {
|
|
245
|
+
if (value == null) {
|
|
246
|
+
return null;
|
|
247
|
+
}
|
|
248
|
+
try {
|
|
249
|
+
const parsed = JSON.parse(value);
|
|
250
|
+
if (typeof parsed !== "number") {
|
|
251
|
+
return parsed;
|
|
252
|
+
}
|
|
253
|
+
} catch (error) {
|
|
254
|
+
}
|
|
255
|
+
return value;
|
|
256
|
+
}
|
|
257
|
+
function $toast(message, type = "success", otherParams = {}) {
|
|
258
|
+
const typeMap = {
|
|
259
|
+
s: "success",
|
|
260
|
+
i: "info",
|
|
261
|
+
e: "error",
|
|
262
|
+
w: "warning"
|
|
263
|
+
};
|
|
264
|
+
function isShortType(t) {
|
|
265
|
+
return ["s", "i", "e", "w"].includes(t);
|
|
266
|
+
}
|
|
267
|
+
function isToastOptions(obj) {
|
|
268
|
+
return typeof obj === "object" && obj !== null;
|
|
269
|
+
}
|
|
270
|
+
if (isToastOptions(message)) {
|
|
271
|
+
if (message.closeAll) {
|
|
272
|
+
ElMessage.closeAll();
|
|
273
|
+
}
|
|
274
|
+
message.customClass = message.customClass === "el" ? "" : "s-antd-message";
|
|
275
|
+
ElMessage(message);
|
|
276
|
+
return;
|
|
277
|
+
}
|
|
278
|
+
if (isToastOptions(type)) {
|
|
279
|
+
if (type.closeAll) {
|
|
280
|
+
ElMessage.closeAll();
|
|
281
|
+
}
|
|
282
|
+
type.customClass = type.customClass === "el" ? "" : "s-antd-message";
|
|
283
|
+
ElMessage({
|
|
284
|
+
message,
|
|
285
|
+
type: "success",
|
|
286
|
+
...type
|
|
287
|
+
});
|
|
288
|
+
return;
|
|
289
|
+
}
|
|
290
|
+
if (otherParams.closeAll) {
|
|
291
|
+
ElMessage.closeAll();
|
|
292
|
+
}
|
|
293
|
+
const resolvedType = isShortType(type) ? typeMap[type] : type;
|
|
294
|
+
otherParams.customClass = otherParams.customClass === "el" ? "" : "s-antd-message";
|
|
295
|
+
ElMessage({
|
|
296
|
+
message,
|
|
297
|
+
type: resolvedType,
|
|
298
|
+
...otherParams
|
|
299
|
+
});
|
|
300
|
+
}
|
|
301
|
+
$toast.success = (message, otherParams = {}) => $toast(message, "success", otherParams);
|
|
302
|
+
$toast.info = (message, otherParams = {}) => $toast(message, "info", otherParams);
|
|
303
|
+
$toast.error = (message, otherParams = {}) => $toast(message, "error", otherParams);
|
|
304
|
+
$toast.warning = (message, otherParams = {}) => $toast(message, "warning", otherParams);
|
|
305
|
+
function setStorage(storageName, params, isSession = false) {
|
|
306
|
+
const storage = _getBrowserStorage(isSession);
|
|
307
|
+
if (!storage) {
|
|
308
|
+
return;
|
|
309
|
+
}
|
|
310
|
+
let handleParams;
|
|
311
|
+
if (typeof params === "number" || typeof params === "string") {
|
|
312
|
+
handleParams = params;
|
|
313
|
+
} else {
|
|
314
|
+
handleParams = JSON.stringify(params);
|
|
315
|
+
}
|
|
316
|
+
storage.setItem(storageName, handleParams);
|
|
317
|
+
}
|
|
318
|
+
function getStorage(data, isSession = false) {
|
|
319
|
+
const storage = _getBrowserStorage(isSession);
|
|
320
|
+
if (!storage) {
|
|
321
|
+
return null;
|
|
322
|
+
}
|
|
323
|
+
return _parseStorageValue(storage.getItem(data));
|
|
324
|
+
}
|
|
325
|
+
function clearStorage(str = "") {
|
|
326
|
+
const sessionStorageRef = _getBrowserStorage(true);
|
|
327
|
+
const localStorageRef = _getBrowserStorage(false);
|
|
328
|
+
if (!sessionStorageRef && !localStorageRef) {
|
|
329
|
+
return;
|
|
330
|
+
}
|
|
331
|
+
if (isEmpty(str)) {
|
|
332
|
+
sessionStorageRef?.clear();
|
|
333
|
+
localStorageRef?.clear();
|
|
334
|
+
}
|
|
335
|
+
if (!isEmpty(str) && getType(str) !== "object") {
|
|
336
|
+
let strArr = Array.isArray(str) ? str : [str];
|
|
337
|
+
for (let i = 0; i < strArr.length; i++) {
|
|
338
|
+
sessionStorageRef?.removeItem(strArr[i]);
|
|
339
|
+
localStorageRef?.removeItem(strArr[i]);
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
if (_isObjectWithExclude(str)) {
|
|
343
|
+
if (!isEmpty(str.exclude) && getType(str) === "object") {
|
|
344
|
+
let sessionStorageObj = {};
|
|
345
|
+
let localStorageObj = {};
|
|
346
|
+
for (const key in str.exclude) {
|
|
347
|
+
if (Object.prototype.hasOwnProperty.call(str.exclude, key)) {
|
|
348
|
+
const name = str.exclude[key];
|
|
349
|
+
if (getStorage(name)) {
|
|
350
|
+
localStorageObj[name] = getStorage(name);
|
|
351
|
+
}
|
|
352
|
+
if (getStorage(name, true)) {
|
|
353
|
+
sessionStorageObj[name] = getStorage(name, true);
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
sessionStorageRef?.clear();
|
|
358
|
+
localStorageRef?.clear();
|
|
359
|
+
for (const key in sessionStorageObj) {
|
|
360
|
+
setStorage(key, sessionStorageObj[key], true);
|
|
361
|
+
}
|
|
362
|
+
for (const key in localStorageObj) {
|
|
363
|
+
setStorage(key, localStorageObj[key]);
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
function _isObjectWithExclude(obj) {
|
|
369
|
+
return typeof obj === "object" && obj !== null && "exclude" in obj && typeof obj.exclude === "object";
|
|
370
|
+
}
|
|
371
|
+
function validForm(ref, { message = "\u8868\u5355\u6821\u9A8C\u9519\u8BEF, \u8BF7\u68C0\u67E5", detail = false, showMessage = true } = {}) {
|
|
372
|
+
return new Promise((resolve, reject) => {
|
|
373
|
+
unref(ref).validate((valid, status) => {
|
|
374
|
+
if (valid) {
|
|
375
|
+
resolve(status);
|
|
376
|
+
} else {
|
|
377
|
+
if (message && showMessage) {
|
|
378
|
+
let errorText = Object.keys(status);
|
|
379
|
+
let toastMessage = message;
|
|
380
|
+
if (detail) {
|
|
381
|
+
toastMessage = message + errorText.join(",");
|
|
382
|
+
}
|
|
383
|
+
$toast(toastMessage, "e");
|
|
384
|
+
}
|
|
385
|
+
reject(status);
|
|
386
|
+
}
|
|
387
|
+
});
|
|
388
|
+
});
|
|
389
|
+
}
|
|
390
|
+
function isPlainObject(data) {
|
|
391
|
+
if (Object.prototype.toString.call(data) !== "[object Object]") {
|
|
392
|
+
return false;
|
|
393
|
+
}
|
|
394
|
+
const proto = Object.getPrototypeOf(data);
|
|
395
|
+
return proto === Object.prototype || proto === null;
|
|
396
|
+
}
|
|
397
|
+
function isEmpty(data, strict = true) {
|
|
398
|
+
if (isRef(data)) {
|
|
399
|
+
data = unref(data);
|
|
400
|
+
}
|
|
401
|
+
if (data == null) return true;
|
|
402
|
+
if (data instanceof Date) {
|
|
403
|
+
return Number.isNaN(data.getTime());
|
|
404
|
+
}
|
|
405
|
+
switch (typeof data) {
|
|
406
|
+
case "string":
|
|
407
|
+
return data.trim().length === 0;
|
|
408
|
+
case "boolean":
|
|
409
|
+
return strict ? false : !data;
|
|
410
|
+
case "number":
|
|
411
|
+
return Number.isNaN(data) || !strict && data === 0;
|
|
412
|
+
case "symbol":
|
|
413
|
+
return false;
|
|
414
|
+
case "bigint":
|
|
415
|
+
return strict ? false : data === BigInt(0);
|
|
416
|
+
case "function":
|
|
417
|
+
return false;
|
|
418
|
+
}
|
|
419
|
+
if (data instanceof Map || data instanceof Set) return data.size === 0;
|
|
420
|
+
if (Array.isArray(data)) {
|
|
421
|
+
return data.length === 0;
|
|
422
|
+
}
|
|
423
|
+
if (isPlainObject(data)) {
|
|
424
|
+
return Reflect.ownKeys(data).length === 0;
|
|
425
|
+
}
|
|
426
|
+
return false;
|
|
427
|
+
}
|
|
428
|
+
function merge(obj1, obj2) {
|
|
429
|
+
let merged = { ...obj1, ...obj2 };
|
|
430
|
+
for (let key in merged) {
|
|
431
|
+
if (!isEmpty(obj1[key]) && !isEmpty(obj2[key])) {
|
|
432
|
+
merged[key] = obj2[key];
|
|
433
|
+
} else if (isEmpty(obj1[key]) && !isEmpty(obj2[key])) {
|
|
434
|
+
merged[key] = obj2[key];
|
|
435
|
+
} else if (!isEmpty(obj1[key]) && isEmpty(obj2[key])) {
|
|
436
|
+
merged[key] = obj1[key];
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
return merged;
|
|
440
|
+
}
|
|
441
|
+
function clone(data, times = 1) {
|
|
442
|
+
if (isRef(data)) {
|
|
443
|
+
data = unref(data);
|
|
444
|
+
}
|
|
445
|
+
if (getType(data) !== "array") {
|
|
446
|
+
return cloneDeep(data);
|
|
447
|
+
}
|
|
448
|
+
const clonedData = cloneDeep(data);
|
|
449
|
+
const result = [];
|
|
450
|
+
for (let i = 0; i < times; i++) {
|
|
451
|
+
result.push(...clonedData);
|
|
452
|
+
}
|
|
453
|
+
return result;
|
|
454
|
+
}
|
|
455
|
+
function uuid(type = "", length = 4, options = {}) {
|
|
456
|
+
const { emailStr = "@qq.com", timeStr = "{y}-{m}-{d} {h}:{i}:{s}", startStr = "", optionsIndex = null } = options;
|
|
457
|
+
function isRef2(obj) {
|
|
458
|
+
return obj && typeof obj === "object" && obj._isRef === true;
|
|
459
|
+
}
|
|
460
|
+
function unref2(ref) {
|
|
461
|
+
return isRef2(ref) ? ref.value : ref;
|
|
462
|
+
}
|
|
463
|
+
function random2(min, max) {
|
|
464
|
+
return Math.floor(Math.random() * (max - min + 1) + min);
|
|
465
|
+
}
|
|
466
|
+
type = unref2(type);
|
|
467
|
+
if (Array.isArray(type)) {
|
|
468
|
+
if (type.length === 0) return "";
|
|
469
|
+
const randIndex = optionsIndex ?? random2(0, type.length - 1);
|
|
470
|
+
const selectedItem = type[randIndex];
|
|
471
|
+
if (typeof selectedItem === "object" && selectedItem !== null && "value" in selectedItem) {
|
|
472
|
+
return selectedItem.value;
|
|
473
|
+
}
|
|
474
|
+
return selectedItem;
|
|
475
|
+
}
|
|
476
|
+
let randomChars = "ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678";
|
|
477
|
+
let result = startStr;
|
|
478
|
+
if (type === "phone") {
|
|
479
|
+
const prefixes = ["130", "131", "132", "133", "135", "136", "137", "138", "170", "187", "189"];
|
|
480
|
+
result = prefixes[random2(0, prefixes.length - 1)];
|
|
481
|
+
for (let i = 0; i < 8; i++) {
|
|
482
|
+
result += Math.floor(Math.random() * 10);
|
|
483
|
+
}
|
|
484
|
+
return result;
|
|
485
|
+
}
|
|
486
|
+
if (type === "email") {
|
|
487
|
+
result = uuid(startStr, length) + emailStr;
|
|
488
|
+
return result;
|
|
489
|
+
}
|
|
490
|
+
if (type === "time") {
|
|
491
|
+
return uuid(startStr, length, options) + " " + formatTime(/* @__PURE__ */ new Date(), timeStr);
|
|
492
|
+
}
|
|
493
|
+
if (type === "number") {
|
|
494
|
+
const numChars = "123456789";
|
|
495
|
+
result = "";
|
|
496
|
+
for (let i = 0; i < length; i++) {
|
|
497
|
+
result += numChars[random2(0, numChars.length - 1)];
|
|
498
|
+
}
|
|
499
|
+
return Number(result);
|
|
500
|
+
}
|
|
501
|
+
if (type === "ip") {
|
|
502
|
+
const randomNum = random2(1, 99);
|
|
503
|
+
return `10.0.11.${randomNum}`;
|
|
504
|
+
}
|
|
505
|
+
if (type === "port") {
|
|
506
|
+
return random2(1, 65535);
|
|
507
|
+
}
|
|
508
|
+
for (let i = 0; i < length; i++) {
|
|
509
|
+
result += randomChars[random2(0, randomChars.length - 1)];
|
|
510
|
+
}
|
|
511
|
+
return result;
|
|
512
|
+
}
|
|
513
|
+
function getType(type) {
|
|
514
|
+
if (typeof type === "object") {
|
|
515
|
+
const objType = Object.prototype.toString.call(type).slice(8, -1).toLowerCase();
|
|
516
|
+
return objType;
|
|
517
|
+
} else {
|
|
518
|
+
return typeof type;
|
|
519
|
+
}
|
|
520
|
+
}
|
|
521
|
+
function sleep(delay = 0, fn) {
|
|
522
|
+
return new Promise(
|
|
523
|
+
(resolve) => setTimeout(() => {
|
|
524
|
+
fn?.();
|
|
525
|
+
resolve();
|
|
526
|
+
}, delay)
|
|
527
|
+
);
|
|
528
|
+
}
|
|
529
|
+
function validateTrigger(type = "required", rules = {}, pureValid = false) {
|
|
530
|
+
let mergeRules = {
|
|
531
|
+
trigger: ["blur", "change"],
|
|
532
|
+
...rules
|
|
533
|
+
};
|
|
534
|
+
return validate(type, mergeRules, pureValid);
|
|
535
|
+
}
|
|
536
|
+
var ValidateType = /* @__PURE__ */ ((ValidateType2) => {
|
|
537
|
+
ValidateType2["REQUIRED"] = "required";
|
|
538
|
+
ValidateType2["PASSWORD"] = "password";
|
|
539
|
+
ValidateType2["NUMBER"] = "number";
|
|
540
|
+
ValidateType2["POSITIVE"] = "positive";
|
|
541
|
+
ValidateType2["ZERO_POSITIVE"] = "zeroPositive";
|
|
542
|
+
ValidateType2["INTEGER"] = "integer";
|
|
543
|
+
ValidateType2["DECIMAL"] = "decimal";
|
|
544
|
+
ValidateType2["MOBILE"] = "mobile";
|
|
545
|
+
ValidateType2["EMAIL"] = "email";
|
|
546
|
+
ValidateType2["IP"] = "ip";
|
|
547
|
+
ValidateType2["PORT"] = "port";
|
|
548
|
+
ValidateType2["BETWEEN"] = "between";
|
|
549
|
+
ValidateType2["LENGTH"] = "length";
|
|
550
|
+
ValidateType2["SAME"] = "same";
|
|
551
|
+
ValidateType2["CUSTOM"] = "custom";
|
|
552
|
+
return ValidateType2;
|
|
553
|
+
})(ValidateType || {});
|
|
554
|
+
function validate(type = "required", rules = {}, pureValid = false) {
|
|
555
|
+
const rulesObject = typeof rules === "object" && rules !== null ? rules : {};
|
|
556
|
+
let trigger = rulesObject.trigger || [];
|
|
557
|
+
const typeMaps = Object.values(ValidateType);
|
|
558
|
+
let parseRequired = rulesObject.required ?? true;
|
|
559
|
+
if (!typeMaps.includes(type)) {
|
|
560
|
+
return {
|
|
561
|
+
required: parseRequired,
|
|
562
|
+
message: type,
|
|
563
|
+
trigger
|
|
564
|
+
};
|
|
565
|
+
}
|
|
566
|
+
if (type === "required" /* REQUIRED */) {
|
|
567
|
+
return {
|
|
568
|
+
required: parseRequired,
|
|
569
|
+
message: rulesObject.message ?? "\u8BF7\u8F93\u5165",
|
|
570
|
+
trigger
|
|
571
|
+
};
|
|
572
|
+
}
|
|
573
|
+
if (type === "password" /* PASSWORD */) {
|
|
574
|
+
const validateName = (rule, value, callback) => {
|
|
575
|
+
let validFlag = /^[a-zA-Z0-9_-]+$/.test(value);
|
|
576
|
+
if (!validFlag) {
|
|
577
|
+
callback(new Error(rulesObject.message || "\u5BC6\u7801\u53EA\u80FD\u7531\u82F1\u6587\u3001\u6570\u5B57\u3001\u4E0B\u5212\u7EBF\u3001\u4E2D\u5212\u7EBF\u7EC4\u6210"));
|
|
578
|
+
} else {
|
|
579
|
+
callback();
|
|
580
|
+
}
|
|
581
|
+
};
|
|
582
|
+
return {
|
|
583
|
+
validator: validateName,
|
|
584
|
+
trigger
|
|
585
|
+
};
|
|
586
|
+
}
|
|
587
|
+
if (type === "positive" /* POSITIVE */ || type === "number" /* NUMBER */) {
|
|
588
|
+
return _validValue(rules, "\u8BF7\u8F93\u5165\u6B63\u6574\u6570", pureValid, /^[1-9]+\d*$/);
|
|
589
|
+
}
|
|
590
|
+
if (type === "zeroPositive" /* ZERO_POSITIVE */) {
|
|
591
|
+
return _validValue(rules, "\u8BF7\u8F93\u5165\u975E\u8D1F\u6574\u6570", pureValid, /^(0|[1-9]+\d*)$/);
|
|
592
|
+
}
|
|
593
|
+
if (type === "integer" /* INTEGER */) {
|
|
594
|
+
return _validValue(rules, "\u8BF7\u8F93\u5165\u6574\u6570", pureValid, /^(0|[-]?[1-9]\d*)$/);
|
|
595
|
+
}
|
|
596
|
+
if (type === "decimal" /* DECIMAL */) {
|
|
597
|
+
return _validValue(rules, "\u8BF7\u8F93\u5165\u975E\u8D1F\u6570\u5B57, \u5305\u542B\u5C0F\u6570\u4E14\u6700\u591A2\u4F4D", pureValid, /(0|[1-9]\d*)(\.\d{1, 2})?|0\.\d{1,2}/);
|
|
598
|
+
}
|
|
599
|
+
if (type === "mobile" /* MOBILE */) {
|
|
600
|
+
return _validValue(rules, "\u8BF7\u8F93\u5165\u6B63\u786E\u7684\u624B\u673A\u53F7", pureValid, /^[1][0-9]{10}$/);
|
|
601
|
+
}
|
|
602
|
+
if (type === "email" /* EMAIL */) {
|
|
603
|
+
return _validValue(rules, "\u8BF7\u8F93\u5165\u6B63\u786E\u7684email", pureValid, /^[^\s@]+@[^\s@]+\.[^\s@]+$/);
|
|
604
|
+
}
|
|
605
|
+
if (type === "ip" /* IP */) {
|
|
606
|
+
return _validValue(
|
|
607
|
+
rules,
|
|
608
|
+
"\u8BF7\u8F93\u5165\u6B63\u786E\u7684ip\u5730\u5740",
|
|
609
|
+
pureValid,
|
|
610
|
+
/^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/
|
|
611
|
+
);
|
|
612
|
+
}
|
|
613
|
+
if (type === "port" /* PORT */) {
|
|
614
|
+
return _validValue(
|
|
615
|
+
rules,
|
|
616
|
+
"\u8BF7\u8F93\u51651-65535\u7684\u7AEF\u53E3\u53F7",
|
|
617
|
+
pureValid,
|
|
618
|
+
/^([1-9]|[1-9][0-9]{1,3}|[1-5][0-9]{4}|6[0-5][0-5][0-3][0-5])$/
|
|
619
|
+
);
|
|
620
|
+
}
|
|
621
|
+
if (type === "between" /* BETWEEN */) {
|
|
622
|
+
let min = rulesObject.min;
|
|
623
|
+
let max = rulesObject.max;
|
|
624
|
+
const validateBetween = (rule, value, callback) => {
|
|
625
|
+
let validFlag = /^-?[0-9]+$/.test(value);
|
|
626
|
+
if (!validFlag) {
|
|
627
|
+
callback(new Error("\u8BF7\u8F93\u5165\u6570\u5B57"));
|
|
628
|
+
}
|
|
629
|
+
if (value < min && min !== void 0) {
|
|
630
|
+
callback(new Error(`\u6570\u5B57\u4E0D\u80FD\u5C0F\u4E8E${min}`));
|
|
631
|
+
}
|
|
632
|
+
if (value > max && max !== void 0) {
|
|
633
|
+
callback(new Error(`\u6570\u5B57\u4E0D\u80FD\u5927\u4E8E${max}`));
|
|
634
|
+
}
|
|
635
|
+
callback();
|
|
636
|
+
};
|
|
637
|
+
return {
|
|
638
|
+
validator: validateBetween,
|
|
639
|
+
trigger,
|
|
640
|
+
required: parseRequired
|
|
641
|
+
};
|
|
642
|
+
}
|
|
643
|
+
if (type === "length" /* LENGTH */) {
|
|
644
|
+
return {
|
|
645
|
+
min: rulesObject.min,
|
|
646
|
+
max: rulesObject.max,
|
|
647
|
+
message: rulesObject.message ?? `\u8BF7\u8F93\u5165${rulesObject.min}\u5230${rulesObject.max}\u4E2A\u5B57\u7B26`,
|
|
648
|
+
trigger,
|
|
649
|
+
required: parseRequired
|
|
650
|
+
};
|
|
651
|
+
}
|
|
652
|
+
if (type === "same" /* SAME */) {
|
|
653
|
+
const validateSame = (rule, value, callback) => {
|
|
654
|
+
let isSame = value === rulesObject.value;
|
|
655
|
+
if (!isSame) {
|
|
656
|
+
const errMessage = rulesObject.message || "\u5BC6\u7801\u548C\u786E\u8BA4\u5BC6\u7801\u8981\u4E00\u81F4";
|
|
657
|
+
callback(new Error(errMessage));
|
|
658
|
+
}
|
|
659
|
+
if (parseRequired && !value) {
|
|
660
|
+
callback(new Error(rulesObject.message || "\u8BF7\u8F93\u5165"));
|
|
661
|
+
}
|
|
662
|
+
callback();
|
|
663
|
+
};
|
|
664
|
+
let res = {
|
|
665
|
+
validator: validateSame,
|
|
666
|
+
trigger,
|
|
667
|
+
required: parseRequired
|
|
668
|
+
};
|
|
669
|
+
return res;
|
|
670
|
+
}
|
|
671
|
+
if (type === "custom" /* CUSTOM */) {
|
|
672
|
+
if (pureValid) {
|
|
673
|
+
return _validValue(rulesObject.value, rulesObject.message, pureValid, rulesObject.reg);
|
|
674
|
+
} else {
|
|
675
|
+
return _validValue(rulesObject, rulesObject.message, pureValid, rulesObject.reg);
|
|
676
|
+
}
|
|
677
|
+
}
|
|
678
|
+
function _validValue(rules2, msg, pureValid2, reg) {
|
|
679
|
+
if (pureValid2 === true) {
|
|
680
|
+
return reg.test(rules2);
|
|
681
|
+
}
|
|
682
|
+
const validatePhone = (rule, value, callback) => {
|
|
683
|
+
let validFlag = reg.test(value);
|
|
684
|
+
if (!validFlag) {
|
|
685
|
+
callback(new Error(rules2.message ?? msg));
|
|
686
|
+
} else {
|
|
687
|
+
callback();
|
|
688
|
+
}
|
|
689
|
+
};
|
|
690
|
+
return {
|
|
691
|
+
validator: validatePhone,
|
|
692
|
+
required: rules2.required ?? true,
|
|
693
|
+
trigger
|
|
694
|
+
};
|
|
695
|
+
}
|
|
696
|
+
}
|
|
697
|
+
const copy = (text, toastParams = {}) => {
|
|
698
|
+
const textarea = document.createElement("textarea");
|
|
699
|
+
textarea.value = text;
|
|
700
|
+
textarea.style.position = "fixed";
|
|
701
|
+
document.body.appendChild(textarea);
|
|
702
|
+
textarea.select();
|
|
703
|
+
document.execCommand("copy");
|
|
704
|
+
document.body.removeChild(textarea);
|
|
705
|
+
if (!toastParams.hideToast) {
|
|
706
|
+
const { hideToast, ...toastOptions } = toastParams;
|
|
707
|
+
$toast(text + "\u590D\u5236\u6210\u529F", toastOptions);
|
|
708
|
+
return true;
|
|
709
|
+
}
|
|
710
|
+
return true;
|
|
711
|
+
};
|
|
712
|
+
function log(variableStr, variable, otherInfo = "") {
|
|
713
|
+
const stack = new Error().stack.split("\n")[2].trim();
|
|
714
|
+
const matchResult = stack.match(/\((.*):(\d+):(\d+)\)/);
|
|
715
|
+
let fileInfo = "";
|
|
716
|
+
try {
|
|
717
|
+
if (matchResult && otherInfo) {
|
|
718
|
+
const lineNumber = matchResult[2];
|
|
719
|
+
fileInfo = `vscode://file${JSON.parse(otherInfo)}:${lineNumber}`;
|
|
720
|
+
}
|
|
721
|
+
} catch (error) {
|
|
722
|
+
fileInfo = otherInfo;
|
|
723
|
+
}
|
|
724
|
+
if (isRef(variable)) {
|
|
725
|
+
let unrefVariable = unref(variable);
|
|
726
|
+
_log(toRaw(unrefVariable));
|
|
727
|
+
} else {
|
|
728
|
+
_log(variable);
|
|
729
|
+
}
|
|
730
|
+
function _log(consoleData) {
|
|
731
|
+
if (getType2(consoleData) === "object" || getType2(consoleData) === "array") {
|
|
732
|
+
consola.log(
|
|
733
|
+
`%c${variableStr} `,
|
|
734
|
+
"background:#fff; color: blue;font-size: 0.8em",
|
|
735
|
+
JSON.stringify(consoleData, null, " "),
|
|
736
|
+
`${fileInfo}`
|
|
737
|
+
);
|
|
738
|
+
} else {
|
|
739
|
+
consola.log(`%c${variableStr} `, "background:#fff; color: blue;font-size: 0.8em", consoleData, `${fileInfo}`);
|
|
740
|
+
}
|
|
741
|
+
}
|
|
742
|
+
function getType2(type) {
|
|
743
|
+
if (typeof type === "object") {
|
|
744
|
+
const objType = Object.prototype.toString.call(type).slice(8, -1).toLowerCase();
|
|
745
|
+
return objType;
|
|
746
|
+
} else {
|
|
747
|
+
return typeof type;
|
|
748
|
+
}
|
|
749
|
+
}
|
|
750
|
+
}
|
|
751
|
+
function random(min = 0, max = 10) {
|
|
752
|
+
return Math.floor(Math.random() * (max - min + 1)) + min;
|
|
753
|
+
}
|
|
754
|
+
function toLine(text, connect = "-") {
|
|
755
|
+
let translateText = text.replace(/([A-Z])/g, (match, p1, offset, origin) => {
|
|
756
|
+
if (offset === 0) {
|
|
757
|
+
return `${match.toLocaleLowerCase()}`;
|
|
758
|
+
} else {
|
|
759
|
+
return `${connect}${match.toLocaleLowerCase()}`;
|
|
760
|
+
}
|
|
761
|
+
}).toLocaleLowerCase();
|
|
762
|
+
return translateText;
|
|
763
|
+
}
|
|
764
|
+
const _CSS_UNIT_RE = /^[0-9]+(\.[0-9]+)?(px|%|em|rem|vw|vh|ch)$/;
|
|
765
|
+
function processWidth(initValue, isBase = false) {
|
|
766
|
+
const raw = unref(initValue);
|
|
767
|
+
if (!raw) {
|
|
768
|
+
return isBase ? "" : {};
|
|
769
|
+
}
|
|
770
|
+
const str = typeof raw === "number" ? `${raw}` : raw;
|
|
771
|
+
let res;
|
|
772
|
+
if (!isNaN(Number(str))) {
|
|
773
|
+
res = str + "px";
|
|
774
|
+
} else if (_CSS_UNIT_RE.test(str)) {
|
|
775
|
+
res = str;
|
|
776
|
+
} else {
|
|
777
|
+
return isBase ? "" : {};
|
|
778
|
+
}
|
|
779
|
+
return isBase ? res : { width: res };
|
|
780
|
+
}
|
|
781
|
+
function throttle(fn, delay = 1e3) {
|
|
782
|
+
let last = 0;
|
|
783
|
+
let timer = void 0;
|
|
784
|
+
return function(...args) {
|
|
785
|
+
let context = this;
|
|
786
|
+
let now = +/* @__PURE__ */ new Date();
|
|
787
|
+
if (now - last < delay) {
|
|
788
|
+
clearTimeout(timer);
|
|
789
|
+
timer = setTimeout(function() {
|
|
790
|
+
last = now;
|
|
791
|
+
fn.apply(context, args);
|
|
792
|
+
}, delay);
|
|
793
|
+
} else {
|
|
794
|
+
last = now;
|
|
795
|
+
fn.apply(context, args);
|
|
796
|
+
}
|
|
797
|
+
};
|
|
798
|
+
}
|
|
799
|
+
async function tryCatch(task, sendLoading) {
|
|
800
|
+
const updateLoading = (value) => {
|
|
801
|
+
if (isRef(sendLoading)) {
|
|
802
|
+
sendLoading.value = value;
|
|
803
|
+
} else if (sendLoading !== void 0 && sendLoading !== null) {
|
|
804
|
+
console.warn("Cannot modify non-ref sendLoading directly!");
|
|
805
|
+
}
|
|
806
|
+
};
|
|
807
|
+
updateLoading(true);
|
|
808
|
+
try {
|
|
809
|
+
const data = typeof task === "function" ? await task() : await task;
|
|
810
|
+
return { data, error: null };
|
|
811
|
+
} catch (error) {
|
|
812
|
+
return { data: null, error };
|
|
813
|
+
} finally {
|
|
814
|
+
updateLoading(false);
|
|
815
|
+
}
|
|
816
|
+
}
|
|
817
|
+
function debounce(func, delay = 500, immediate, resultCallback) {
|
|
818
|
+
let timer = null;
|
|
819
|
+
let isInvoke = false;
|
|
820
|
+
const _debounce = function(...args) {
|
|
821
|
+
return new Promise((resolve, reject) => {
|
|
822
|
+
if (timer) clearTimeout(timer);
|
|
823
|
+
if (immediate && !isInvoke) {
|
|
824
|
+
try {
|
|
825
|
+
const result = func.apply(this, args);
|
|
826
|
+
if (resultCallback) resultCallback(result);
|
|
827
|
+
resolve(result);
|
|
828
|
+
} catch (e) {
|
|
829
|
+
reject(e);
|
|
830
|
+
}
|
|
831
|
+
isInvoke = true;
|
|
832
|
+
} else {
|
|
833
|
+
timer = setTimeout(() => {
|
|
834
|
+
try {
|
|
835
|
+
const result = func.apply(this, args);
|
|
836
|
+
if (resultCallback) resultCallback(result);
|
|
837
|
+
resolve(result);
|
|
838
|
+
} catch (e) {
|
|
839
|
+
reject(e);
|
|
840
|
+
}
|
|
841
|
+
isInvoke = false;
|
|
842
|
+
timer = null;
|
|
843
|
+
}, delay);
|
|
844
|
+
}
|
|
845
|
+
});
|
|
846
|
+
};
|
|
847
|
+
_debounce.cancel = function() {
|
|
848
|
+
if (timer) clearTimeout(timer);
|
|
849
|
+
isInvoke = false;
|
|
850
|
+
timer = null;
|
|
851
|
+
};
|
|
852
|
+
return _debounce;
|
|
853
|
+
}
|
|
854
|
+
function confirm(message, options = {}, appContext = null) {
|
|
855
|
+
const resolvedMessage = typeof message === "function" ? message() : message;
|
|
856
|
+
const resolvedAppendTo = _resolveAppendTarget(options?.appendTo);
|
|
857
|
+
const resolvedAppContext = _resolveAppContext(options?.appContext || appContext);
|
|
858
|
+
const mergeOptions = {
|
|
859
|
+
title: "\u63D0\u793A",
|
|
860
|
+
draggable: true,
|
|
861
|
+
showCancelButton: true,
|
|
862
|
+
cancelButtonText: "\u53D6\u6D88",
|
|
863
|
+
confirmButtonText: "\u786E\u5B9A",
|
|
864
|
+
dangerouslyUseHTMLString: true,
|
|
865
|
+
...options,
|
|
866
|
+
appendTo: resolvedAppendTo,
|
|
867
|
+
appContext: resolvedAppContext,
|
|
868
|
+
confirmButtonClass: _mergeClassNames(DEFAULT_CONFIRM_BUTTON_CLASS, options?.confirmButtonClass),
|
|
869
|
+
cancelButtonClass: _mergeClassNames(DEFAULT_CANCEL_BUTTON_CLASS, options?.cancelButtonClass)
|
|
870
|
+
};
|
|
871
|
+
return ElMessageBox.confirm(resolvedMessage, mergeOptions);
|
|
872
|
+
}
|
|
873
|
+
function _mergeClassNames(...classNames) {
|
|
874
|
+
return classNames.filter(Boolean).join(" ");
|
|
875
|
+
}
|
|
876
|
+
function _resolveAppendTarget(appendTo) {
|
|
877
|
+
if (typeof document === "undefined") {
|
|
878
|
+
return appendTo;
|
|
879
|
+
}
|
|
880
|
+
if (appendTo instanceof HTMLElement) {
|
|
881
|
+
return appendTo;
|
|
882
|
+
}
|
|
883
|
+
if (typeof appendTo === "string" && appendTo.trim()) {
|
|
884
|
+
const rawSelector = appendTo.trim();
|
|
885
|
+
try {
|
|
886
|
+
const selector = rawSelector.startsWith("#") || rawSelector.startsWith(".") || rawSelector.startsWith("[") ? rawSelector : `#${rawSelector}`;
|
|
887
|
+
return document.querySelector(selector) || appendTo;
|
|
888
|
+
} catch (error) {
|
|
889
|
+
return appendTo;
|
|
890
|
+
}
|
|
891
|
+
}
|
|
892
|
+
const overlayList = Array.from(document.querySelectorAll(".el-overlay"));
|
|
893
|
+
const dialogOverlay = overlayList.filter((item) => {
|
|
894
|
+
if (!item.isConnected || item.style.display === "none") {
|
|
895
|
+
return false;
|
|
896
|
+
}
|
|
897
|
+
const containsDialog = item.querySelector(".el-dialog, .el-drawer");
|
|
898
|
+
const containsMessageBox = item.querySelector(".el-message-box");
|
|
899
|
+
return !!containsDialog && !containsMessageBox;
|
|
900
|
+
}).at(-1);
|
|
901
|
+
return dialogOverlay || appendTo;
|
|
902
|
+
}
|
|
903
|
+
function _resolveAppContext(appContext) {
|
|
904
|
+
if (appContext) {
|
|
905
|
+
return appContext;
|
|
906
|
+
}
|
|
907
|
+
if (typeof document === "undefined") {
|
|
908
|
+
return ElMessageBox.install?.context || ElMessageBox._context;
|
|
909
|
+
}
|
|
910
|
+
return ElMessageBox.install?.context || ElMessageBox._context || document.querySelector("#app")?._vue_app?._context;
|
|
911
|
+
}
|
|
912
|
+
function getVariable(propertyName, fallback = "") {
|
|
913
|
+
if (typeof document === "undefined") {
|
|
914
|
+
return fallback;
|
|
915
|
+
}
|
|
916
|
+
const res = getComputedStyle(document.documentElement).getPropertyValue(propertyName).trim();
|
|
917
|
+
return res || fallback;
|
|
918
|
+
}
|
|
919
|
+
function test() {
|
|
920
|
+
return `build time: ${"2026-06-09 10:40:54"}`;
|
|
921
|
+
}
|
|
922
|
+
|
|
923
|
+
export { $toast as $, formatImg as A, formatTextToHtml as B, formatThousands as C, formatTime as D, formatToFixed as E, clone as a, confirm as b, clearStorage as c, copy as d, debounce as e, getType as f, getStorage as g, getVariable as h, isEmpty as i, sleep as j, throttle as k, log as l, merge as m, toLine as n, tryCatch as o, processWidth as p, validate as q, random as r, setStorage as s, test as t, uuid as u, validForm as v, validateTrigger as w, formatBytes as x, formatBytesConvert as y, formatDurationTime as z };
|