@oeos-components/utils 0.0.19 → 0.0.22

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.cts CHANGED
@@ -1,404 +1,10 @@
1
- import * as element_plus from 'element-plus';
2
- import { MessageOptions } from 'element-plus';
3
- import { Ref } from '@vue/reactivity';
4
-
5
- /**
6
- * 现有方法如下
7
- * $toast(message, type: string | object = 'success', otherParams: object = {})
8
- * setStorage(storageName: string, params: any, isSession = false)
9
- * getStorage(data, isSession = false)
10
- * clearStorage(str: string | [] | object = '')
11
- * validForm(ref, { message = '表单校验错误, 请检查', detail = false, showMessage = true } = {})
12
- * isEmpty(data: any): boolean
13
- * notEmpty(v: any): boolean
14
- * merge(obj1: object, obj2: object): object
15
- * clone(data, times = 1)
16
- * formatTime(time, cFormat = '{y}-{m}-{d} {h}:{i}:{s}')
17
- * formatDurationTime(timestamp, cFormat = '{d} 天 {h} 时 {i} 分 {s} 秒')
18
- * uuid(type = '',length = 4,{ emailStr = '@qq.com', timeStr = '{m}-{d} {h}:{i}:{s}', startStr = '', optionsIndex = null } = {},)
19
- * getType(type)
20
- * sleep(delay = 0, fn?: () => void)
21
- * validate(type = 'required', rules = {}, pureValid = false)
22
- * asyncWrapper(func, ...args)
23
- * formatImg(photoName, addPath = '', { basePath = 'assets/images' } = {})
24
- * copy = (text, toastParams = {})
25
- * formatThousands(number)
26
- * log(variableStr, variable, otherInfo = '')
27
- * random(min = 0, max = 10)
28
- * toLine(text, connect = '-')
29
- * processWidth(initValue, isBase = false)
30
- * formatBytes(bytes)
31
- * formatBytesConvert(bytes)
32
- * throttle(fn, delay = 1000)
33
- * debounce(fn, delay = 1000)
34
- * confirm(message, options)
35
- * formatNewLines(str)
36
- * getVariable('--green')
37
- */
38
- declare const isString: (val: any) => val is string;
39
- declare const isStringNumber: (val: string) => boolean;
40
- declare const isNumber: (val: any) => val is number;
41
- /**
42
- * @example1
43
- proxy.$toast('保存成功') // s:success; i: info; w: warning; e: error;
44
- proxy.$toast('保存失败', 'e')
45
- proxy.$toast('永不关闭', {duration: 0})
46
- proxy.$toast({
47
- message: 'andy',
48
- type: 'warning',
49
- duration: 300,
50
- closeAll: true,
51
- })
52
- * $toast.success('This is a success message')
53
- * @example2 显示对象
54
- * $toast({
55
- dangerouslyUseHTMLString: true,
56
- message: `<h6>复制成功</h6><pre>${JSON.stringify(obj, null, 2)}</pre>`,
57
- type: 'success',
58
- duration: 5000,
59
- })
60
- */
61
- type MessageType = 'success' | 'info' | 'error' | 'warning';
62
- type ShortType = 's' | 'i' | 'e' | 'w';
63
- type ToastType = MessageType | ShortType;
64
- type ToastOptions = Partial<MessageOptions> & {
65
- closeAll?: boolean;
66
- };
67
- declare function $toast(message: string | ToastOptions, type?: ToastType | ToastOptions, otherParams?: ToastOptions): void;
68
- declare namespace $toast {
69
- var success: (message: any, otherParams?: {}) => void;
70
- var info: (message: any, otherParams?: {}) => void;
71
- var error: (message: any, otherParams?: {}) => void;
72
- var warning: (message: any, otherParams?: {}) => void;
73
- }
74
- declare function setStorage(storageName: string, params: any, isSession?: boolean): void;
75
- declare function getStorage(data: any, isSession?: boolean): string | null;
76
- /**
77
- *
78
- * @param {*} str 需要清空的localStorage或sessionStorage, 如果不传清空所有
79
- * @param {*} param1 需要排除的sessionStorage或者localStorage
80
- * @example
81
- * clearStorage()
82
- * clearStorage('loginId')
83
- * clearStorage(['loginId', 'token'])
84
- * clearStorage({ exclude: ['loginId', 'token'] })
85
- */
86
- declare function clearStorage(str?: string | [] | object): void;
87
- /**
88
- * element-plus的form表单使用promise进行封装
89
- * @param ref
90
- * @param param1
91
- * @returns Promise
92
- * await proxy.validForm(formRef);
93
- * await proxy.validForm(formRef, {message: '自定义错误'});
94
- * await proxy.validForm(formRef, {showMessage: false});
95
- * await proxy.validForm(formRef, {detail: true});
96
- */
97
- declare function validForm(ref: any, { message, detail, showMessage }?: {
98
- message?: string | undefined;
99
- detail?: boolean | undefined;
100
- showMessage?: boolean | undefined;
101
- }): Promise<unknown>;
102
- /**
103
- * 判断变量是否空值
104
- * undefined, null, '', ' ', false, 0, [], {}, NaN, new Set(), new Map(), BigInt(0), new Date('无效日期') 均返回true,否则返回false
105
- */
106
- declare function isEmpty(data: any, strict?: boolean): boolean;
107
- declare function notEmpty(v: any): boolean;
108
- /**
109
- * 将两个对象合并, 以第二个对象为准, 如果两个对象, 一个属性有值, 一个没值, 合并后有值; 如果两个属性都有值, 以第二个属性为准
110
- * */
111
- declare function merge(obj1: object, obj2: object): object;
112
- /**
113
- * 克隆数据并根据需要复制数组
114
- * @param {any} data - 要克隆的数据
115
- * @param {number} [times=1] - 如果是数组,要复制的次数
116
- * @returns {any} - 克隆后的数据或复制后的数组
117
- * clone(123) => 123
118
- * clone([1,2, {name: 'andy'}], 2) => [1, 2, {name: 'andy'}, 1, 2, {name: 'andy'}]
119
- */
120
- declare function clone(data: any, times?: number): any;
121
- /**
122
- * 格式化时间为年月日时分秒的格式, 格式可以自定义。
123
- * ① 时间戳10位和13位都可以转换成格式化的日期
124
- * ② java8格式的日期和有效的日期都可以转换成定义的日期格式
125
- * @param {Date, string} 都有默认参数
126
- * @example
127
- * formatTime() // 2020-07-17 09:53:07
128
- * formatTime('2018-02-13T06:17') // 2018-02-13 06:17:00
129
- * formatTime('2020/03/02 06:02') // 2020-03-02 06:02:00
130
- * formatTime(1541927611000); //2018-11-11 17:13:21
131
- * formatTime(1541927611000, "{y}年{m}月{d}日 {h}时{m}分{s}秒"); // 2018年11月11日 17时11分31秒
132
- * formatTime(1541927611, "{y}/{m}/{d} {h}:{m}:{s}"); // 2018/11/11 17:11:31
133
- * formatTime(new Date()); // 2018-11-11 17:13:21
134
- * formatTime(new Date().getTime()); // 2018-11-11 17:13:21
135
- * formatTime('1764128798.456'); // 2025/11/26 11:11:38
136
- */
137
- declare function formatTime(time: any, cFormat?: string): any;
138
- /**
139
- *
140
- * @param timestamp 持续的时间戳
141
- * @param cFormat 格式化的规则
142
- * @returns 天时分秒的字符串
143
- * @example
144
- * formatDurationTime(1162821) => 19分24秒
145
- */
146
- declare function formatDurationTime(timestamp: any, cFormat?: string): string;
147
- /**
148
- * 生成 UUID
149
- * @param type - 生成 UUID 的类型,可以是 'phone', 'email', 'time', 'number', 'ip', 'port' 或空字符串
150
- * @param length - 生成字符串的长度(默认为4)
151
- * @param options - 额外的选项
152
- * @param options.emailStr - 生成 email 时使用的后缀(默认为 '@qq.com')
153
- * @param options.timeStr - 生成时间字符串的格式(默认为 '{m}-{d} {h}:{i}:{s}')
154
- * @param options.startStr - 起始字符串(默认为空)
155
- * @param options.optionsIndex - 数组索引(默认为随机)
156
- * @returns 生成的 UUID (字符串或数字)
157
- * * uuid("名字") => 名字hc8f
158
- * uuid() => abcd
159
- * uuid('time') => 25MR 10-27 17:34:01
160
- * uuid('time', 0, {startStr:'andy', timeStr:"{h}:{i}:{s}"}) => andy 17:38:23
161
- * uuid('phone') => 13603312460
162
- * uuid('email') => cBZA@qq.com
163
- * uuid('number') => 2319
164
- * uuid([ { label: "小泽泽", value: "xzz" },{ label: "小月月", value: "xyy" }]) => xzz
165
- */
166
- declare function uuid(type?: string | Array<{
167
- label: string;
168
- value: any;
169
- }>, length?: number, options?: {
170
- emailStr?: string;
171
- timeStr?: string;
172
- startStr?: string;
173
- optionsIndex?: number | null;
174
- }): string | number;
175
- /**
176
- * 判断传入参数的类型
177
- * @param {*} type
178
- * getType(new RegExp()) regexp
179
- * getType(new Date()) date
180
- * getType([]) array
181
- * getType({}) object
182
- * getType(null) null
183
- * getType(123) number
184
- */
185
- declare function getType(type: any): string;
186
- /**
187
- * 一个辅助函数,用于在代码中创建一个暂停(延迟)。
188
- * 它返回一个 Promise,你可以在 `await` 后使用它来实现类似 "sleep" 的效果。
189
- *
190
- * @param delay - 等待的毫秒数。默认值为 0,表示不延迟。
191
- * @param fn - (可选) 一个在延迟结束后立即执行的函数。
192
- *
193
- * @returns 一个 Promise,当延迟结束后解析(resolve)。
194
- *
195
- * @example
196
- * // 基本用法:延迟 2 秒后打印消息
197
- * console.log('开始');
198
- * await sleep(2000);
199
- * console.log('2秒后执行');
200
- *
201
- * @example
202
- * // 带回调函数的用法:延迟 1 秒后执行清理工作
203
- * sleep(1000, () => {
204
- * console.log('执行清理操作...');
205
- * // 清理代码...
206
- * });
207
- *
208
- * @example
209
- * // 在循环中使用:每次迭代后延迟 500 毫秒
210
- * for (let i = 0; i < 5; i++) {
211
- * console.log(`当前值: ${i}`);
212
- * await sleep(500);
213
- * }
214
- */
215
- declare function sleep(delay?: number, fn?: () => void): Promise<void>;
216
- /** @使用方式
217
- * 1. 在el-form中使用
218
- name: [ proxy.validate('name', { message: '你干嘛哈哈' })],
219
- between: [ proxy.validate('between', { max: 99 })],
220
- number: [ proxy.validate('number')],
221
- length: [proxy.validate('length')],
222
- mobile: [ proxy.validate('mobile')],
223
- ip: [ proxy.validate('ip')],
224
- custom: [proxy.validate('custom', { message: '最多保留2位小数', reg: /^\d+\.?\d{0,2}$/ })]
225
- confirmRegPwd: [
226
- proxy.validate('same', { value: form.value.regPwd }),
227
- ], //1. 如果判断两个密码一致, 还要在input输入值改变的时候, 再校验一下两个input
228
- formRef.value.validate('regPwd')
229
- formRef.value.validate('confirmRegPwd')
230
- // 2. rules需要使用computed包裹, 否则值改变无法传递
231
- * 2. 在函数中使用, 返回boolean
232
- let ip = proxy.validate('ip', 122322, true)
233
- let custom = proxy.validate('custom', { value: -123, reg: /^-\d+\.?\d{0,2}$/ }, true)
234
- */
235
- declare function validateTrigger(type?: string, rules?: {}, pureValid?: boolean): any;
236
- declare function validate(type?: string, rules?: {}, pureValid?: boolean): any;
237
- /**
238
- *
239
- const { res, err } = await proxy.asyncWrapper(listTests, pickForm);
240
- if (err) {
241
- return;
242
- }
243
- */
244
- declare function asyncWrapper(func: any, ...args: any[]): Promise<{
245
- res: any;
246
- err?: undefined;
247
- } | {
248
- err: unknown;
249
- res?: undefined;
250
- }>;
251
- /** 获取assets静态资源
252
- * @example
253
- * proxy.formatImg('1.png')
254
- * proxy.formatImg('1.png', 'menu')
255
- * */
256
- declare function formatImg(photoName: any, addPath?: string, { basePath }?: {
257
- basePath?: string | undefined;
258
- }): any;
259
- /**
260
- * 复制文本
261
- *
262
- * copy('这是要复制的文本');
263
- * copy('这是要复制的文本', {duration: 500});
264
- *
265
- * */
266
- declare const copy: (text: any, toastParams?: {}) => void;
267
- /**
268
- * 1234 => 1,234
269
- * 1234b => 1,234b
270
- * 1234.12b => 1,234.12b
271
- * @param number 加千分位
272
- * @returns
273
- */
274
- declare function formatThousands(number: any): any;
275
- declare function log(variableStr: any, variable: any, otherInfo?: string): void;
276
- /**
277
- * 生成指定范围内的随机整数
278
- *
279
- * @param min 最小值,默认为0
280
- * @param max 最大值,默认为10
281
- * @returns 返回生成的随机整数
282
- */
283
- declare function random(min?: number, max?: number): number;
284
- /**
285
- * 将文本转换为带有连接符的行文本
286
- *
287
- * @param text 要转换的文本
288
- * @param connect 连接符,默认为'-'
289
- * @returns 返回转换后的行文本
290
- * toLine('NameAndy') // name-andy
291
- * toLine('nameAndy') // name-andy
292
- * toLine('_nameAndy') // _name-andy
293
- */
294
- declare function toLine(text: any, connect?: string): any;
295
- declare function processWidth(initValue: any, isBase?: boolean): any;
296
- /**
297
- * 增加小数点
298
- * toFixed(22) -> '22.00'
299
- * toFixed('22') -> '22.00'
300
- * toFixed('22', 4) -> '22.0000'
301
- * toFixed('22', 2) -> 22
302
- * toFixed('22 TB', {prefix: '$', suffix: '%', unit: false}) -> $22.00%
303
- */
304
- declare function toFixed(value: any, options?: {
305
- digit?: number;
306
- prefix?: string;
307
- suffix?: string;
308
- unit?: boolean;
309
- } | number): any;
310
- /**
311
- * 格式化字节单位
312
- * @param bytes - 字节数
313
- * @param options - 配置项
314
- * @param options.digit - 小数位数(默认2)
315
- * @param options.thousands - 是否千分位分隔(默认true)
316
- * @param options.prefix - 前缀(默认空)
317
- * @param options.suffix - 后缀(默认空)
318
- * @param options.roundType - 取整方式:'floor'(向下, 默认) | 'ceil'(向上) | 'round'(四舍五入)
319
- */
320
- declare function formatBytes(bytes: number | string, options?: {
321
- digit?: number;
322
- thousands?: boolean;
323
- prefix?: string;
324
- suffix?: string;
325
- roundType?: 'floor' | 'ceil' | 'round';
326
- }): string;
327
- /**
328
- * 字节转数字
329
- * @param oBytes
330
- * @param param1
331
- * @returns number
332
- * formatBytesConvert('0.5GB') 536870912
333
- * formatBytesConvert('1,234 GB') 1324997410816
334
- * formatBytesConvert('1,234 GB', {thousand: true}) 1,324,997,410,816
335
- * formatBytesConvert('1,234 GB', {toFixed: 2}) 1324997410816.00
336
- */
337
- declare function formatBytesConvert(oBytes: any, { thounsands, digit }?: {
338
- thounsands?: boolean | undefined;
339
- digit?: number | undefined;
340
- }): any;
341
- declare function throttle(fn: any, delay?: number): () => void;
342
- /**
343
- * 封装 Promise 执行,提供自动 loading 状态管理
344
- * @param promise 需要执行的 Promise
345
- * @param sendLoading 可选的 loading 状态(支持 Ref<boolean> 或 boolean)
346
- * @returns Promise<{ data: T | null; error: any }>
347
- * @example1
348
- * const loading = ref(false);
349
- * const { data, error } = await tryCatch(fetchUserData(), loading);
350
- * @example2 // 无视 loading 状态
351
- * const { data, error } = await tryCatch(fetchUserData());
352
- */
353
- declare function tryCatch<T>(promise: Promise<T>, sendLoading?: Ref<boolean> | null): Promise<{
354
- data: T | null;
355
- error: any;
356
- }>;
357
- declare function debounce(fn: any, delay?: number): () => void;
358
- /**
359
- * proxy.confirm('确定删除吗?')
360
- * proxy.confirm('哈哈', { icon: 'el-icon-plus' })
361
- * close-on-click-modal: 是否可通过点击遮罩层关闭 MessageBox 默认true
362
- * lock-scroll: 是否在 MessageBox 出现时将 body 滚动锁定. 默认true
363
- * 设置宽度, 内容使用组件
364
- import GWarning from '@/autoComponents/gWarning.vue'
365
- await proxy.confirm('', {
366
- dangerouslyUseHTMLString: true,
367
- customStyle: {
368
- maxWidth: '600px',
369
- },
370
- message: h(GWarning, {
371
- content:
372
- '对于光存储开启保持原始对象名称后,对象将作为独立文件在光存储介质直接存储。<br>注意:当桶内文件大小普遍较小(<100MB)或过大(>5GB)时不推荐打开此功能!您确定开启此功能吗?',
373
- }),
374
- showCancelButton: true,
375
- cancelButtonText: '取消',
376
- appendTo: '#highSettingsForm',
377
- })
378
- * 如果是多个dialog嵌套, 可以给上层的dom设置个id如highSettingsForm, 然后appendTo: '#highSettingsForm'
379
- */
380
- declare function confirm(message: any, options: any): Promise<element_plus.MessageBoxData>;
381
- /**
382
- * 格式化字符串中的换行符和制表符
383
- * @param str 待格式化的字符串
384
- * @returns 格式化后的字符串,如果输入的不是字符串或为空,则返回原字符串
385
- * @example
386
- $toast(
387
- formatNewLines(
388
- 'Example file\n File : 111.jpeg\n CreateTime : 1721011155921 2024-07-15 10:39:15\n LastUpdateTime : 1721011155921 2024-07-15 10:39:15\n------------------------------------------------------------------------\nExtract:\n aa=231\n------------------------------------------------------------------------\n',
389
- ),
390
- {
391
- duration: 5000,
392
- dangerouslyUseHTMLString: true,
393
- },
394
- )
395
- */
396
- declare function formatNewLines(str: any): any;
397
- /** Function to get a CSS custom property value
398
- *
399
- * getVariable('--blue');
400
- * */
401
- declare function getVariable(propertyName: any): string;
402
- declare function test(): string;
403
-
404
- export { $toast, asyncWrapper, clearStorage, clone, confirm, copy, debounce, formatBytes, formatBytesConvert, formatDurationTime, formatImg, formatNewLines, formatThousands, formatTime, getStorage, getType, getVariable, isEmpty, isNumber, isString, isStringNumber, log, merge, notEmpty, processWidth, random, setStorage, sleep, test, throttle, toFixed, toLine, tryCatch, uuid, validForm, validate, validateTrigger };
1
+ export { $toast, asyncWrapper, clearStorage, clone, confirm, copy, debounce, getStorage, getType, getVariable, isEmpty, log, merge, notEmpty, processWidth, random, setStorage, sleep, test, throttle, toLine, tryCatch, uuid, validForm, validate, validateTrigger } from './base.cjs';
2
+ export { diffDate, diffDateFromCurrent, formatDate, formatDateToDay, formatDateToMinute } from './day.cjs';
3
+ export { isArray, isBoolean, isComponent, isDate, isEmptyObject, isFunction, isIOS, isMap, isNumber, isObject, isPlainObject, isPromise, isRegExp, isSVGElement, isSet, isString, isStringNumber, isSymbol, isUrl, objectToString, toRawType, toTypeString } from './is.cjs';
4
+ export { WS, WSOptions } from './ws.cjs';
5
+ export { formatBytes, formatBytesConvert, formatDurationTime, formatImg, formatTextToHtml, formatThousands, formatTime, formatToFixed } from './format.cjs';
6
+ export { onlyTest } from './test.cjs';
7
+ import 'element-plus';
8
+ import 'vue';
9
+ import '@vue/reactivity';
10
+ import 'dayjs';