@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
package/dist/base.cjs
CHANGED
|
@@ -1,16 +1,35 @@
|
|
|
1
|
-
|
|
1
|
+
'use strict';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
"babel": {
|
|
10
|
-
"plugins": []
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
})
|
|
3
|
+
require('@vue/reactivity');
|
|
4
|
+
require('consola');
|
|
5
|
+
require('es-toolkit');
|
|
6
|
+
const format = require('./shared/utils.DrwfWQ1C.cjs');
|
|
7
|
+
require('element-plus');
|
|
8
|
+
require('./is.cjs');
|
|
14
9
|
|
|
15
|
-
|
|
16
|
-
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
exports.$toast = format.$toast;
|
|
13
|
+
exports.clearStorage = format.clearStorage;
|
|
14
|
+
exports.clone = format.clone;
|
|
15
|
+
exports.confirm = format.confirm;
|
|
16
|
+
exports.copy = format.copy;
|
|
17
|
+
exports.debounce = format.debounce;
|
|
18
|
+
exports.getStorage = format.getStorage;
|
|
19
|
+
exports.getType = format.getType;
|
|
20
|
+
exports.getVariable = format.getVariable;
|
|
21
|
+
exports.isEmpty = format.isEmpty;
|
|
22
|
+
exports.log = format.log;
|
|
23
|
+
exports.merge = format.merge;
|
|
24
|
+
exports.processWidth = format.processWidth;
|
|
25
|
+
exports.random = format.random;
|
|
26
|
+
exports.setStorage = format.setStorage;
|
|
27
|
+
exports.sleep = format.sleep;
|
|
28
|
+
exports.test = format.test;
|
|
29
|
+
exports.throttle = format.throttle;
|
|
30
|
+
exports.toLine = format.toLine;
|
|
31
|
+
exports.tryCatch = format.tryCatch;
|
|
32
|
+
exports.uuid = format.uuid;
|
|
33
|
+
exports.validForm = format.validForm;
|
|
34
|
+
exports.validate = format.validate;
|
|
35
|
+
exports.validateTrigger = format.validateTrigger;
|
package/dist/base.d.cts
CHANGED
|
@@ -1 +1,555 @@
|
|
|
1
|
-
|
|
1
|
+
import * as element_plus from 'element-plus';
|
|
2
|
+
import { MessageOptions, ElMessageBoxOptions } from 'element-plus';
|
|
3
|
+
import * as vue from 'vue';
|
|
4
|
+
import { VNode, AppContext } from 'vue';
|
|
5
|
+
import { Ref } from '@vue/reactivity';
|
|
6
|
+
|
|
7
|
+
type Func<Args extends any[] = any[], Return = any> = (...args: Args) => Return;
|
|
8
|
+
type StorageValue = unknown;
|
|
9
|
+
type StorageMap = Record<string, any>;
|
|
10
|
+
type MaybeRef<T> = T | Ref<T>;
|
|
11
|
+
type WidthStyleResult = {
|
|
12
|
+
width: string;
|
|
13
|
+
};
|
|
14
|
+
type ValidateTriggerType = 'blur' | 'change';
|
|
15
|
+
type ValidateInput = ValidateRules | ValidatePrimitiveValue;
|
|
16
|
+
type ValidateRuleResult = {
|
|
17
|
+
required?: boolean;
|
|
18
|
+
message?: string;
|
|
19
|
+
trigger?: ValidateTriggerType[];
|
|
20
|
+
validator?: (rule: any, value: any, callback: (error?: Error) => void) => void;
|
|
21
|
+
min?: number;
|
|
22
|
+
max?: number;
|
|
23
|
+
};
|
|
24
|
+
type ValidatePrimitiveValue = string | number | boolean | null | undefined;
|
|
25
|
+
type UuidOptionItem<T = any> = {
|
|
26
|
+
label: string;
|
|
27
|
+
value: T;
|
|
28
|
+
};
|
|
29
|
+
interface ToastOptions extends Partial<MessageOptions> {
|
|
30
|
+
/**
|
|
31
|
+
* 调用前是否先关闭全部消息提示。
|
|
32
|
+
*/
|
|
33
|
+
closeAll?: boolean;
|
|
34
|
+
}
|
|
35
|
+
interface ClearStorageExcludeOptions {
|
|
36
|
+
/**
|
|
37
|
+
* 清空时需要保留的 key 列表。
|
|
38
|
+
*/
|
|
39
|
+
exclude: string[];
|
|
40
|
+
}
|
|
41
|
+
type ClearStorageInput = string | string[] | ClearStorageExcludeOptions;
|
|
42
|
+
interface ValidFormOptions {
|
|
43
|
+
/**
|
|
44
|
+
* 校验失败时的提示文案。
|
|
45
|
+
*/
|
|
46
|
+
message?: string;
|
|
47
|
+
/**
|
|
48
|
+
* 是否在提示文案后追加字段名。
|
|
49
|
+
*/
|
|
50
|
+
detail?: boolean;
|
|
51
|
+
/**
|
|
52
|
+
* 是否显示错误提示。
|
|
53
|
+
*/
|
|
54
|
+
showMessage?: boolean;
|
|
55
|
+
}
|
|
56
|
+
interface FormValidateTarget {
|
|
57
|
+
validate: (callback: (valid: boolean, status: StorageMap) => void) => void;
|
|
58
|
+
}
|
|
59
|
+
interface UuidOptions {
|
|
60
|
+
/**
|
|
61
|
+
* `email` 模式下的邮箱后缀,默认 `@qq.com`。
|
|
62
|
+
*/
|
|
63
|
+
emailStr?: string;
|
|
64
|
+
/**
|
|
65
|
+
* `time` 模式下追加的时间格式,默认 `{y}-{m}-{d} {h}:{i}:{s}`。
|
|
66
|
+
*/
|
|
67
|
+
timeStr?: string;
|
|
68
|
+
/**
|
|
69
|
+
* 生成结果前缀。
|
|
70
|
+
*/
|
|
71
|
+
startStr?: string;
|
|
72
|
+
/**
|
|
73
|
+
* 数组选项模式下的固定索引;不传时随机取值。
|
|
74
|
+
*/
|
|
75
|
+
optionsIndex?: number | null;
|
|
76
|
+
}
|
|
77
|
+
interface ValidateRules {
|
|
78
|
+
/**
|
|
79
|
+
* 校验失败提示文案。
|
|
80
|
+
*/
|
|
81
|
+
message?: string;
|
|
82
|
+
/**
|
|
83
|
+
* 最小值或最小长度。
|
|
84
|
+
*/
|
|
85
|
+
min?: number;
|
|
86
|
+
/**
|
|
87
|
+
* 最大值或最大长度。
|
|
88
|
+
*/
|
|
89
|
+
max?: number;
|
|
90
|
+
/**
|
|
91
|
+
* 对比值,例如 `same` 校验时使用。
|
|
92
|
+
*/
|
|
93
|
+
value?: any;
|
|
94
|
+
/**
|
|
95
|
+
* 自定义正则。
|
|
96
|
+
*/
|
|
97
|
+
reg?: RegExp;
|
|
98
|
+
/**
|
|
99
|
+
* 是否必填,默认 `true`。
|
|
100
|
+
*/
|
|
101
|
+
required?: boolean;
|
|
102
|
+
/**
|
|
103
|
+
* 触发时机,常用 `['blur', 'change']`。
|
|
104
|
+
*/
|
|
105
|
+
trigger?: ValidateTriggerType[];
|
|
106
|
+
}
|
|
107
|
+
interface CopyOptions extends ToastOptions {
|
|
108
|
+
/**
|
|
109
|
+
* 是否隐藏复制成功提示。
|
|
110
|
+
*/
|
|
111
|
+
hideToast?: boolean;
|
|
112
|
+
}
|
|
113
|
+
type WidthInput = string | number | Ref<string | number>;
|
|
114
|
+
type ConfirmMessage = string | VNode | (() => VNode);
|
|
115
|
+
type ConfirmAppendTarget = string | HTMLElement | null;
|
|
116
|
+
interface ConfirmOptions extends ElMessageBoxOptions {
|
|
117
|
+
/**
|
|
118
|
+
* 追加到的挂载节点。支持 css 选择器、DOM 节点或 `null`。
|
|
119
|
+
*/
|
|
120
|
+
appendTo?: ConfirmAppendTarget;
|
|
121
|
+
/**
|
|
122
|
+
* 手动传入 appContext,处理多应用或嵌套弹窗场景。
|
|
123
|
+
*/
|
|
124
|
+
appContext?: AppContext | null;
|
|
125
|
+
}
|
|
126
|
+
interface TryCatchResult<T> {
|
|
127
|
+
/**
|
|
128
|
+
* 执行成功时返回的数据;失败时为 `null`。
|
|
129
|
+
*/
|
|
130
|
+
data: T | null;
|
|
131
|
+
/**
|
|
132
|
+
* 执行失败时返回的异常;成功时为 `null`。
|
|
133
|
+
*/
|
|
134
|
+
error: any;
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* 显示消息提示。
|
|
138
|
+
*
|
|
139
|
+
* 支持三种常见写法:
|
|
140
|
+
* 1. `$toast('保存成功')`
|
|
141
|
+
* 2. `$toast('保存失败', 'e')`
|
|
142
|
+
* 3. `$toast({ message: '自定义', type: 'warning' })`
|
|
143
|
+
*
|
|
144
|
+
* @param message 提示内容,支持纯文本、VNode、渲染函数,或完整配置对象。
|
|
145
|
+
* @param type 提示类型,支持 `success/info/error/warning` 和简写 `s/i/e/w`,也支持直接传配置对象。
|
|
146
|
+
* @param otherParams 额外配置,例如 `duration`、`customClass`、`closeAll`。
|
|
147
|
+
* @returns 无返回值。
|
|
148
|
+
*
|
|
149
|
+
* @example
|
|
150
|
+
* $toast('保存成功')
|
|
151
|
+
*
|
|
152
|
+
* @example
|
|
153
|
+
* $toast('保存失败', 'e')
|
|
154
|
+
*
|
|
155
|
+
* @example
|
|
156
|
+
* $toast({
|
|
157
|
+
* message: '自定义提示',
|
|
158
|
+
* type: 'warning',
|
|
159
|
+
* duration: 1000,
|
|
160
|
+
* closeAll: true,
|
|
161
|
+
* })
|
|
162
|
+
*/
|
|
163
|
+
type MessageType = 'success' | 'info' | 'error' | 'warning';
|
|
164
|
+
type ShortType = 's' | 'i' | 'e' | 'w';
|
|
165
|
+
type ToastType = MessageType | ShortType;
|
|
166
|
+
declare function $toast(message: string | ToastOptions | VNode | (() => VNode), type?: ToastType | ToastOptions, otherParams?: ToastOptions): void;
|
|
167
|
+
declare namespace $toast {
|
|
168
|
+
var success: (message: string | ToastOptions | VNode<vue.RendererNode, vue.RendererElement, {
|
|
169
|
+
[key: string]: any;
|
|
170
|
+
}> | (() => VNode<vue.RendererNode, vue.RendererElement, {
|
|
171
|
+
[key: string]: any;
|
|
172
|
+
}>), otherParams?: ToastOptions) => void;
|
|
173
|
+
var info: (message: string | ToastOptions | VNode<vue.RendererNode, vue.RendererElement, {
|
|
174
|
+
[key: string]: any;
|
|
175
|
+
}> | (() => VNode<vue.RendererNode, vue.RendererElement, {
|
|
176
|
+
[key: string]: any;
|
|
177
|
+
}>), otherParams?: ToastOptions) => void;
|
|
178
|
+
var error: (message: string | ToastOptions | VNode<vue.RendererNode, vue.RendererElement, {
|
|
179
|
+
[key: string]: any;
|
|
180
|
+
}> | (() => VNode<vue.RendererNode, vue.RendererElement, {
|
|
181
|
+
[key: string]: any;
|
|
182
|
+
}>), otherParams?: ToastOptions) => void;
|
|
183
|
+
var warning: (message: string | ToastOptions | VNode<vue.RendererNode, vue.RendererElement, {
|
|
184
|
+
[key: string]: any;
|
|
185
|
+
}> | (() => VNode<vue.RendererNode, vue.RendererElement, {
|
|
186
|
+
[key: string]: any;
|
|
187
|
+
}>), otherParams?: ToastOptions) => void;
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* 写入浏览器缓存。
|
|
191
|
+
*
|
|
192
|
+
* @param storageName 缓存 key。
|
|
193
|
+
* @param params 要保存的值;对象和数组会自动序列化。
|
|
194
|
+
* @param isSession 是否写入 `sessionStorage`;默认写入 `localStorage`。
|
|
195
|
+
* 在 SSR / Node 环境下会自动跳过,不会抛错。
|
|
196
|
+
*
|
|
197
|
+
* @example
|
|
198
|
+
* setStorage('token', 'abc123')
|
|
199
|
+
*
|
|
200
|
+
* @example
|
|
201
|
+
* setStorage('userInfo', { id: 1, name: 'andy' }, true)
|
|
202
|
+
*/
|
|
203
|
+
declare function setStorage(storageName: string, params: StorageValue, isSession?: boolean): void;
|
|
204
|
+
/**
|
|
205
|
+
* 读取浏览器缓存。
|
|
206
|
+
*
|
|
207
|
+
* @param data 缓存 key。
|
|
208
|
+
* @param isSession 是否从 `sessionStorage` 读取;默认从 `localStorage` 读取。
|
|
209
|
+
* @returns 读取到的缓存值;不存在或在 SSR 环境下时返回 `null`。
|
|
210
|
+
*
|
|
211
|
+
* @example
|
|
212
|
+
* const token = getStorage('token')
|
|
213
|
+
*
|
|
214
|
+
* @example
|
|
215
|
+
* const userInfo = getStorage('userInfo', true)
|
|
216
|
+
*/
|
|
217
|
+
declare function getStorage<T = any>(data: string, isSession?: boolean): T | string | number | null;
|
|
218
|
+
/**
|
|
219
|
+
* 清空浏览器缓存。
|
|
220
|
+
*
|
|
221
|
+
* @param str 要清空的 key;不传时清空全部,传 `exclude` 时表示保留指定 key。
|
|
222
|
+
* @returns 无返回值。
|
|
223
|
+
* 在 SSR / Node 环境下会自动跳过。
|
|
224
|
+
*
|
|
225
|
+
* @example
|
|
226
|
+
* clearStorage()
|
|
227
|
+
*
|
|
228
|
+
* @example
|
|
229
|
+
* clearStorage('loginId')
|
|
230
|
+
*
|
|
231
|
+
* @example
|
|
232
|
+
* clearStorage({ exclude: ['token', 'theme'] })
|
|
233
|
+
*/
|
|
234
|
+
declare function clearStorage(str?: ClearStorageInput): void;
|
|
235
|
+
/**
|
|
236
|
+
* 将 Element Plus 表单校验封装为 Promise。
|
|
237
|
+
*
|
|
238
|
+
* @param ref 表单实例或表单实例的 `ref`。
|
|
239
|
+
* @param options 校验配置。
|
|
240
|
+
* @returns 校验通过时返回表单状态对象,失败时 reject 对应状态对象。
|
|
241
|
+
*
|
|
242
|
+
* @example
|
|
243
|
+
* await validForm(formRef)
|
|
244
|
+
*
|
|
245
|
+
* @example
|
|
246
|
+
* await validForm(formRef, { message: '请检查表单信息', detail: true })
|
|
247
|
+
*/
|
|
248
|
+
declare function validForm(ref: MaybeRef<FormValidateTarget>, { message, detail, showMessage }?: ValidFormOptions): Promise<StorageMap>;
|
|
249
|
+
/**
|
|
250
|
+
* 判断值是否为空。
|
|
251
|
+
*
|
|
252
|
+
* 默认采用更安全的“结构空值”语义:
|
|
253
|
+
* `undefined`、`null`、空字符串、空数组、空对象、`NaN`、空 `Map` / `Set`、无效日期会返回 `true`。
|
|
254
|
+
*
|
|
255
|
+
* @param data 要判断的值。
|
|
256
|
+
* @param strict 是否使用严格模式。默认 `true`;传 `false` 时会沿用旧语义,把 `0` 和 `false` 也视为空值。
|
|
257
|
+
* @returns 是否为空。
|
|
258
|
+
*
|
|
259
|
+
* @example
|
|
260
|
+
* isEmpty(' ')
|
|
261
|
+
* // => true
|
|
262
|
+
*
|
|
263
|
+
* @example
|
|
264
|
+
* isEmpty(0)
|
|
265
|
+
* // => false
|
|
266
|
+
*
|
|
267
|
+
* @example
|
|
268
|
+
* isEmpty(0, false)
|
|
269
|
+
* // => true
|
|
270
|
+
*/
|
|
271
|
+
declare function isEmpty(data: any, strict?: boolean): boolean;
|
|
272
|
+
/**
|
|
273
|
+
* 合并两个对象。
|
|
274
|
+
*
|
|
275
|
+
* 当同名字段同时有值时,以第二个对象为准;当其中一个字段为空时,保留有值的一侧。
|
|
276
|
+
*
|
|
277
|
+
* @param obj1 第一个对象。
|
|
278
|
+
* @param obj2 第二个对象。
|
|
279
|
+
* @returns 合并后的对象。
|
|
280
|
+
*
|
|
281
|
+
* @example
|
|
282
|
+
* merge(
|
|
283
|
+
* { name: '', age: 18, city: 'beijing' },
|
|
284
|
+
* { name: 'andy', age: 20, city: '' },
|
|
285
|
+
* )
|
|
286
|
+
*/
|
|
287
|
+
declare function merge<T extends StorageMap, U extends StorageMap>(obj1: T, obj2: U): T & U;
|
|
288
|
+
/**
|
|
289
|
+
* 深拷贝数据;传入数组时可按次数重复展开。
|
|
290
|
+
*
|
|
291
|
+
* @param data 要克隆的数据。
|
|
292
|
+
* @param times 当 `data` 是数组时的复制次数,默认 `1`。
|
|
293
|
+
* @returns 克隆后的数据。
|
|
294
|
+
*
|
|
295
|
+
* @example
|
|
296
|
+
* clone({ name: 'andy', info: { id: 1 } })
|
|
297
|
+
*
|
|
298
|
+
* @example
|
|
299
|
+
* clone([1, 2, { name: 'andy' }], 2)
|
|
300
|
+
* // => [1, 2, { name: 'andy' }, 1, 2, { name: 'andy' }]
|
|
301
|
+
*/
|
|
302
|
+
declare function clone<T>(data: T[], times?: number): T[];
|
|
303
|
+
declare function clone<T>(data: T, times?: number): T;
|
|
304
|
+
/**
|
|
305
|
+
* 生成随机字符串,也支持手机号、邮箱、时间、数字、IP、端口等特殊模式。
|
|
306
|
+
*
|
|
307
|
+
* @param type 生成模式,支持空字符串、`phone`、`email`、`time`、`number`、`ip`、`port`,也支持传选项数组。
|
|
308
|
+
* @param length 随机字符串或数字的长度,默认 `4`。
|
|
309
|
+
* @param options 额外配置。
|
|
310
|
+
* @returns 生成结果。
|
|
311
|
+
*
|
|
312
|
+
* @example
|
|
313
|
+
* uuid()
|
|
314
|
+
* // => 'aB3d'
|
|
315
|
+
*
|
|
316
|
+
* @example
|
|
317
|
+
* uuid('phone')
|
|
318
|
+
* // => '13603312460'
|
|
319
|
+
*
|
|
320
|
+
* @example
|
|
321
|
+
* uuid('time', 0, { startStr: 'andy', timeStr: '{h}:{i}:{s}' })
|
|
322
|
+
*/
|
|
323
|
+
declare function uuid(type?: string | Array<UuidOptionItem>, length?: number, options?: UuidOptions): string | number | any;
|
|
324
|
+
/**
|
|
325
|
+
* 获取值的原始类型名称,返回值统一为小写字符串。
|
|
326
|
+
*
|
|
327
|
+
* @param type 要判断的值。
|
|
328
|
+
* @returns 类型名称,例如 `array`、`date`、`object`、`null`。
|
|
329
|
+
*
|
|
330
|
+
* @example
|
|
331
|
+
* getType(new RegExp())
|
|
332
|
+
* // => 'regexp'
|
|
333
|
+
*
|
|
334
|
+
* @example
|
|
335
|
+
* getType([])
|
|
336
|
+
* // => 'array'
|
|
337
|
+
*/
|
|
338
|
+
declare function getType(type: unknown): string;
|
|
339
|
+
/**
|
|
340
|
+
* 一个辅助函数,用于在代码中创建一个暂停(延迟)。
|
|
341
|
+
* 它返回一个 Promise,你可以在 `await` 后使用它来实现类似 "sleep" 的效果。
|
|
342
|
+
*
|
|
343
|
+
* @param delay - 等待的毫秒数。默认值为 0,表示不延迟。
|
|
344
|
+
* @param fn - (可选) 一个在延迟结束后立即执行的函数。
|
|
345
|
+
*
|
|
346
|
+
* @returns 一个 Promise,当延迟结束后解析(resolve)。
|
|
347
|
+
*
|
|
348
|
+
* @example
|
|
349
|
+
* // 基本用法:延迟 2 秒后打印消息
|
|
350
|
+
* console.log('开始');
|
|
351
|
+
* await sleep(2000);
|
|
352
|
+
* console.log('2秒后执行');
|
|
353
|
+
*
|
|
354
|
+
* @example
|
|
355
|
+
* // 带回调函数的用法:延迟 1 秒后执行清理工作
|
|
356
|
+
* sleep(1000, () => {
|
|
357
|
+
* console.log('执行清理操作...');
|
|
358
|
+
* // 清理代码...
|
|
359
|
+
* });
|
|
360
|
+
*
|
|
361
|
+
* @example
|
|
362
|
+
* // 在循环中使用:每次迭代后延迟 500 毫秒
|
|
363
|
+
* for (let i = 0; i < 5; i++) {
|
|
364
|
+
* console.log(`当前值: ${i}`);
|
|
365
|
+
* await sleep(500);
|
|
366
|
+
* }
|
|
367
|
+
*/
|
|
368
|
+
declare function sleep(delay?: number, fn?: () => void): Promise<void>;
|
|
369
|
+
/**
|
|
370
|
+
* 为 `validate` 预置默认触发时机 `['blur', 'change']`。
|
|
371
|
+
*
|
|
372
|
+
* @param type 校验类型。
|
|
373
|
+
* @param rules 校验规则。
|
|
374
|
+
* @param pureValid 是否直接返回布尔值。
|
|
375
|
+
* @returns 与 `validate` 一致。
|
|
376
|
+
*
|
|
377
|
+
* @example
|
|
378
|
+
* const rule = validateTrigger('required', { message: '请输入名称' })
|
|
379
|
+
*/
|
|
380
|
+
declare function validateTrigger(type?: string, rules?: ValidateRules, pureValid?: boolean): boolean | ValidateRuleResult;
|
|
381
|
+
declare function validate(type?: string, rules?: ValidateInput, pureValid?: boolean): ValidateRuleResult | boolean;
|
|
382
|
+
/**
|
|
383
|
+
* 复制文本到剪贴板。
|
|
384
|
+
*
|
|
385
|
+
* @param text 需要复制的文本。
|
|
386
|
+
* @param toastParams 提示配置;传 `hideToast: true` 时不显示成功提示。
|
|
387
|
+
* @returns 是否复制成功。
|
|
388
|
+
*
|
|
389
|
+
* @example
|
|
390
|
+
* copy('这是要复制的文本')
|
|
391
|
+
*
|
|
392
|
+
* @example
|
|
393
|
+
* copy('静默复制', { hideToast: true })
|
|
394
|
+
*/
|
|
395
|
+
declare const copy: (text: string, toastParams?: CopyOptions) => boolean;
|
|
396
|
+
/**
|
|
397
|
+
* 带变量名的日志输出封装。
|
|
398
|
+
*
|
|
399
|
+
* @param variableStr 变量名或标签名。
|
|
400
|
+
* @param variable 需要打印的值。
|
|
401
|
+
* @param otherInfo 附加信息,常用于手动传入文件路径。
|
|
402
|
+
*
|
|
403
|
+
* @example
|
|
404
|
+
* const formData = { id: 1, name: 'andy' }
|
|
405
|
+
* log('formData', formData)
|
|
406
|
+
*/
|
|
407
|
+
declare function log(variableStr: string, variable: unknown, otherInfo?: string): void;
|
|
408
|
+
/**
|
|
409
|
+
* 生成指定范围内的随机整数。
|
|
410
|
+
*
|
|
411
|
+
* @param min 最小值,默认 `0`。
|
|
412
|
+
* @param max 最大值,默认 `10`。
|
|
413
|
+
* @returns 随机整数。
|
|
414
|
+
*
|
|
415
|
+
* @example
|
|
416
|
+
* random()
|
|
417
|
+
*
|
|
418
|
+
* @example
|
|
419
|
+
* random(100, 999)
|
|
420
|
+
*/
|
|
421
|
+
declare function random(min?: number, max?: number): number;
|
|
422
|
+
/**
|
|
423
|
+
* 将驼峰命名转换为连接符命名。
|
|
424
|
+
*
|
|
425
|
+
* @param text 要转换的文本。
|
|
426
|
+
* @param connect 连接符,默认 `-`。
|
|
427
|
+
* @returns 转换后的文本。
|
|
428
|
+
*
|
|
429
|
+
* @example
|
|
430
|
+
* toLine('NameAndy')
|
|
431
|
+
* // => 'name-andy'
|
|
432
|
+
*
|
|
433
|
+
* @example
|
|
434
|
+
* toLine('CompTitle', '_')
|
|
435
|
+
* // => 'comp_title'
|
|
436
|
+
*/
|
|
437
|
+
declare function toLine(text: string, connect?: string): string;
|
|
438
|
+
/**
|
|
439
|
+
* 将宽度值规范化为可直接用于样式的结果。
|
|
440
|
+
*
|
|
441
|
+
* @param initValue 宽度值,支持数字、数字字符串、CSS 长度字符串和 `ref`。
|
|
442
|
+
* @param isBase 为 `true` 时直接返回宽度字符串;否则返回 `{ width }` 对象。
|
|
443
|
+
* @returns 宽度字符串或宽度样式对象;无效值返回空字符串或空对象。
|
|
444
|
+
*
|
|
445
|
+
* @example
|
|
446
|
+
* processWidth(200)
|
|
447
|
+
* // => { width: '200px' }
|
|
448
|
+
*
|
|
449
|
+
* @example
|
|
450
|
+
* processWidth('50%', true)
|
|
451
|
+
* // => '50%'
|
|
452
|
+
*/
|
|
453
|
+
declare function processWidth(initValue: WidthInput, isBase: true): string;
|
|
454
|
+
declare function processWidth(initValue: WidthInput, isBase?: false): WidthStyleResult | {};
|
|
455
|
+
/**
|
|
456
|
+
* 创建节流函数。
|
|
457
|
+
*
|
|
458
|
+
* @param fn 需要节流执行的函数。
|
|
459
|
+
* @param delay 节流间隔,单位毫秒,默认 `1000`。
|
|
460
|
+
* @returns 节流后的函数。
|
|
461
|
+
*
|
|
462
|
+
* @example
|
|
463
|
+
* const onResize = throttle(() => {
|
|
464
|
+
* console.log('resize')
|
|
465
|
+
* }, 300)
|
|
466
|
+
*/
|
|
467
|
+
declare function throttle<T extends Func>(fn: T, delay?: number): (...args: Parameters<T>) => void;
|
|
468
|
+
/**
|
|
469
|
+
* 统一处理 Promise 或任务函数执行结果。
|
|
470
|
+
*
|
|
471
|
+
* 推荐优先传入函数,这样可以同时捕获同步 `throw` 和异步 `reject`。
|
|
472
|
+
*
|
|
473
|
+
* @param task Promise,或返回值 / Promise 的函数。
|
|
474
|
+
* @param sendLoading 可选的 loading `ref`。
|
|
475
|
+
* @returns 包含 `data` 和 `error` 的结果对象。
|
|
476
|
+
*
|
|
477
|
+
* @example
|
|
478
|
+
* const loading = ref(false)
|
|
479
|
+
* const { data, error } = await tryCatch(() => fetchUserData(), loading)
|
|
480
|
+
*
|
|
481
|
+
* @example
|
|
482
|
+
* const { data, error } = await tryCatch(Promise.resolve({ id: 1 }))
|
|
483
|
+
*
|
|
484
|
+
* @example
|
|
485
|
+
* const { data, error } = await tryCatch(() => {
|
|
486
|
+
* if (!form.name) throw new Error('请输入名称')
|
|
487
|
+
* return submitForm(form)
|
|
488
|
+
* })
|
|
489
|
+
*/
|
|
490
|
+
declare function tryCatch<T>(task: Promise<T>, sendLoading?: Ref<boolean> | null): Promise<TryCatchResult<T>>;
|
|
491
|
+
declare function tryCatch<T>(task: () => T | Promise<T>, sendLoading?: Ref<boolean> | null): Promise<TryCatchResult<T>>;
|
|
492
|
+
/**
|
|
493
|
+
* 防抖函数返回值类型。
|
|
494
|
+
*/
|
|
495
|
+
type DebouncedFunction<T extends Func> = ((...args: Parameters<T>) => Promise<Awaited<ReturnType<T>>>) & {
|
|
496
|
+
cancel: () => void;
|
|
497
|
+
};
|
|
498
|
+
/**
|
|
499
|
+
* 创建防抖函数。
|
|
500
|
+
*
|
|
501
|
+
* @param func 需要防抖执行的函数。
|
|
502
|
+
* @param delay 延迟时间,单位毫秒,默认 `500`。
|
|
503
|
+
* @param immediate 是否在第一次调用时立即执行。
|
|
504
|
+
* @param resultCallback 每次真正执行后触发的结果回调。
|
|
505
|
+
* @returns 带 `cancel()` 方法的防抖函数。
|
|
506
|
+
*
|
|
507
|
+
* @example
|
|
508
|
+
* const search = debounce((keyword: string) => {
|
|
509
|
+
* return keyword.trim()
|
|
510
|
+
* }, 300)
|
|
511
|
+
*
|
|
512
|
+
* await search('sybz')
|
|
513
|
+
*/
|
|
514
|
+
declare function debounce<T extends Func>(func: T, delay?: number, immediate?: boolean, resultCallback?: (result: ReturnType<T>) => void): DebouncedFunction<T>;
|
|
515
|
+
/**
|
|
516
|
+
* 打开确认框。
|
|
517
|
+
*
|
|
518
|
+
* 相比直接调用 `ElMessageBox.confirm`,这里额外处理了默认参数、嵌套弹窗挂载点和 `appContext`。
|
|
519
|
+
*
|
|
520
|
+
* @param message 确认框内容,支持字符串、VNode 或渲染函数。
|
|
521
|
+
* @param options MessageBox 配置项。
|
|
522
|
+
* @param appContext 可选的 Vue 应用上下文。
|
|
523
|
+
* @returns `ElMessageBox.confirm` 返回的 Promise。
|
|
524
|
+
*
|
|
525
|
+
* @example
|
|
526
|
+
* await confirm('确定删除吗?')
|
|
527
|
+
*
|
|
528
|
+
* @example
|
|
529
|
+
* await confirm('确认提交?', {
|
|
530
|
+
* showCancelButton: true,
|
|
531
|
+
* appendTo: '#dialogRoot',
|
|
532
|
+
* })
|
|
533
|
+
*/
|
|
534
|
+
declare function confirm(message: ConfirmMessage, options?: ConfirmOptions, appContext?: AppContext | null): Promise<element_plus.MessageBoxData>;
|
|
535
|
+
/**
|
|
536
|
+
* 读取根节点上的 CSS 自定义变量。
|
|
537
|
+
*
|
|
538
|
+
* @param propertyName CSS 变量名,例如 `--blue`。
|
|
539
|
+
* @returns CSS 变量的值。
|
|
540
|
+
*
|
|
541
|
+
* @example
|
|
542
|
+
* getVariable('--vp-c-brand-1')
|
|
543
|
+
*/
|
|
544
|
+
declare function getVariable(propertyName: string, fallback?: string): string;
|
|
545
|
+
/**
|
|
546
|
+
* 返回当前 utils 包的构建时间。
|
|
547
|
+
*
|
|
548
|
+
* @returns 构建时间字符串。
|
|
549
|
+
*
|
|
550
|
+
* @example
|
|
551
|
+
* test()
|
|
552
|
+
*/
|
|
553
|
+
declare function test(): string;
|
|
554
|
+
|
|
555
|
+
export { $toast, clearStorage, clone, confirm, copy, debounce, getStorage, getType, getVariable, isEmpty, log, merge, processWidth, random, setStorage, sleep, test, throttle, toLine, tryCatch, uuid, validForm, validate, validateTrigger };
|