@oeos-components/utils 0.0.2 → 0.0.3
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.cjs +784 -12
- package/dist/index.d.cts +309 -1
- package/dist/index.d.mts +309 -1
- package/dist/index.d.ts +309 -1
- package/dist/index.mjs +748 -70
- package/package.json +3 -2
package/dist/index.d.ts
CHANGED
|
@@ -1 +1,309 @@
|
|
|
1
|
-
|
|
1
|
+
import * as element_plus from 'element-plus';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* 现有方法如下
|
|
5
|
+
* $toast(message, type: string | object = 'success', otherParams: object = {})
|
|
6
|
+
* setStorage(storageName: string, params: any, isSession = false)
|
|
7
|
+
* getStorage(data, isSession = false)
|
|
8
|
+
* clearStorage(str: string | [] | object = '')
|
|
9
|
+
* validForm(ref, { message = '表单校验错误, 请检查', detail = false, showMessage = true } = {})
|
|
10
|
+
* isEmpty(data: any): boolean
|
|
11
|
+
* notEmpty(v: any): boolean
|
|
12
|
+
* merge(obj1: object, obj2: object): object
|
|
13
|
+
* clone(data, times = 1)
|
|
14
|
+
* formatTime(time, cFormat = '{y}-{m}-{d} {h}:{i}:{s}')
|
|
15
|
+
* formatDurationTime(timestamp, cFormat = '{d} 天 {h} 时 {i} 分 {s} 秒')
|
|
16
|
+
* uuid(type = '',length = 4,{ emailStr = '@qq.com', timeStr = '{m}-{d} {h}:{i}:{s}', startStr = '', optionsIndex = null } = {},)
|
|
17
|
+
* getType(type)
|
|
18
|
+
* sleep(delay = 0, fn?: () => void)
|
|
19
|
+
* validate(type = 'required', rules = {}, pureValid = false)
|
|
20
|
+
* asyncWrapper(func, ...args)
|
|
21
|
+
* formatImg(photoName, addPath = '', { basePath = 'assets/images' } = {})
|
|
22
|
+
* copy = (text, toastParams = {})
|
|
23
|
+
* formatThousands(number)
|
|
24
|
+
* log(variableStr, variable, otherInfo = '')
|
|
25
|
+
* random(min = 0, max = 10)
|
|
26
|
+
* toLine(text, connect = '-')
|
|
27
|
+
* processWidth(initValue, isBase = false)
|
|
28
|
+
* formatBytes(bytes)
|
|
29
|
+
* formatBytesConvert(bytes)
|
|
30
|
+
* throttle(fn, delay = 1000)
|
|
31
|
+
* debounce(fn, delay = 1000)
|
|
32
|
+
* confirm(message, options)
|
|
33
|
+
* formatNewLines(str)
|
|
34
|
+
* getVariable('--green')
|
|
35
|
+
*/
|
|
36
|
+
declare const isString: (val: any) => val is string;
|
|
37
|
+
declare const isStringNumber: (val: string) => boolean;
|
|
38
|
+
declare const isNumber: (val: any) => val is number;
|
|
39
|
+
/**
|
|
40
|
+
* @example
|
|
41
|
+
proxy.$toast('保存成功')
|
|
42
|
+
proxy.$toast('保存失败', 'e')
|
|
43
|
+
proxy.$toast({
|
|
44
|
+
message: 'andy',
|
|
45
|
+
type: 'warning',
|
|
46
|
+
})
|
|
47
|
+
* $toast.success('This is a success message')
|
|
48
|
+
* @example 显示对象
|
|
49
|
+
* $toast({
|
|
50
|
+
dangerouslyUseHTMLString: true,
|
|
51
|
+
message: `<h6>复制成功</h6><pre>${JSON.stringify(obj, null, 2)}</pre>`,
|
|
52
|
+
type: 'success',
|
|
53
|
+
duration: 5000,
|
|
54
|
+
})
|
|
55
|
+
*/
|
|
56
|
+
declare function $toast(message: any, type?: string | object, otherParams?: object): void;
|
|
57
|
+
declare namespace $toast {
|
|
58
|
+
var success: (message: any, otherParams?: {}) => void;
|
|
59
|
+
var info: (message: any, otherParams?: {}) => void;
|
|
60
|
+
var error: (message: any, otherParams?: {}) => void;
|
|
61
|
+
var warning: (message: any, otherParams?: {}) => void;
|
|
62
|
+
}
|
|
63
|
+
declare function setStorage(storageName: string, params: any, isSession?: boolean): void;
|
|
64
|
+
declare function getStorage(data: any, isSession?: boolean): string | null;
|
|
65
|
+
/**
|
|
66
|
+
*
|
|
67
|
+
* @param {*} str 需要清空的localStorage或sessionStorage, 如果不传清空所有
|
|
68
|
+
* @param {*} param1 需要排除的sessionStorage或者localStorage
|
|
69
|
+
* @example
|
|
70
|
+
* clearStorage()
|
|
71
|
+
* clearStorage('loginId')
|
|
72
|
+
* clearStorage(['loginId', 'token'])
|
|
73
|
+
* clearStorage({ exclude: ['loginId', 'token'] })
|
|
74
|
+
*/
|
|
75
|
+
declare function clearStorage(str?: string | [] | object): void;
|
|
76
|
+
declare function validForm(ref: any, { message, detail, showMessage }?: {
|
|
77
|
+
message?: string | undefined;
|
|
78
|
+
detail?: boolean | undefined;
|
|
79
|
+
showMessage?: boolean | undefined;
|
|
80
|
+
}): Promise<unknown>;
|
|
81
|
+
/**
|
|
82
|
+
* 判断变量是否空值
|
|
83
|
+
* undefined, null, '', ' ', false, 0, [], {} 均返回true,否则返回false
|
|
84
|
+
*/
|
|
85
|
+
declare function isEmpty(data: any): boolean;
|
|
86
|
+
declare function notEmpty(v: any): boolean;
|
|
87
|
+
/**
|
|
88
|
+
* 将两个对象合并, 以第二个对象为准, 如果两个对象, 一个属性有值, 一个没值, 合并后有值; 如果两个属性都有值, 以第二个属性为准
|
|
89
|
+
* */
|
|
90
|
+
declare function merge(obj1: object, obj2: object): object;
|
|
91
|
+
/**
|
|
92
|
+
* 克隆数据并根据需要复制数组
|
|
93
|
+
* @param {any} data - 要克隆的数据
|
|
94
|
+
* @param {number} [times=1] - 如果是数组,要复制的次数
|
|
95
|
+
* @returns {any} - 克隆后的数据或复制后的数组
|
|
96
|
+
* clone(123) => 123
|
|
97
|
+
* clone([1,2, {name: 'andy'}], 2) => [1, 2, {name: 'andy'}, 1, 2, {name: 'andy'}]
|
|
98
|
+
*/
|
|
99
|
+
declare function clone(data: any, times?: number): any;
|
|
100
|
+
/**
|
|
101
|
+
* 格式化时间为年月日时分秒的格式, 格式可以自定义。
|
|
102
|
+
* ① 时间戳10位和13位都可以转换成格式化的日期
|
|
103
|
+
* ② java8格式的日期和有效的日期都可以转换成定义的日期格式
|
|
104
|
+
* @param {Date, string} 都有默认参数
|
|
105
|
+
* @example
|
|
106
|
+
* formatTime() // 2020-07-17 09:53:07
|
|
107
|
+
* formatTime('2018-02-13T06:17') // 2018-02-13 06:17:00
|
|
108
|
+
* formatTime('2020/03/02 06:02') // 2020-03-02 06:02:00
|
|
109
|
+
* formatTime(1541927611000); //2018-11-11 17:13:21
|
|
110
|
+
* formatTime(1541927611000, "{y}年{m}月{d}日 {h}时{m}分{s}秒"); // 2018年11月11日 17时11分31秒
|
|
111
|
+
* formatTime(1541927611, "{y}/{m}/{d} {h}:{m}:{s}"); // 2018/11/11 17:11:31
|
|
112
|
+
* formatTime(new Date()); //2018-11-11 17:13:21
|
|
113
|
+
* formatTime(new Date().getTime()); //2018-11-11 17:13:21
|
|
114
|
+
*/
|
|
115
|
+
declare function formatTime(time: any, cFormat?: string): any;
|
|
116
|
+
/**
|
|
117
|
+
*
|
|
118
|
+
* @param timestamp 持续的时间戳
|
|
119
|
+
* @param cFormat 格式化的规则
|
|
120
|
+
* @returns 天时分秒的字符串
|
|
121
|
+
* @example
|
|
122
|
+
* formatDurationTime(1162821) => 19分24秒
|
|
123
|
+
*/
|
|
124
|
+
declare function formatDurationTime(timestamp: any, cFormat?: string): string;
|
|
125
|
+
/**
|
|
126
|
+
* 生成 UUID
|
|
127
|
+
* @param {string} [type=''] - 生成 UUID 的类型,可以是 'phone', 'email', 'time', 'number' 或空字符串
|
|
128
|
+
* @param {number} [length=4] - 生成字符串的长度
|
|
129
|
+
* @param {object} [options={}] - 额外的选项
|
|
130
|
+
* @param {string} [options.emailStr='@qq.com'] - 生成 email 时使用的后缀
|
|
131
|
+
* @param {string} [options.timeStr='{m}-{d} {h}:{i}:{s}'] - 生成时间字符串的格式
|
|
132
|
+
* @param {string} [options.startStr=''] - 起始字符串
|
|
133
|
+
* @param {number|null} [options.optionsIndex=null] - 数组索引
|
|
134
|
+
* @returns {string|number} - 生成的 UUID
|
|
135
|
+
* uuid("名字") => 名字hc8f
|
|
136
|
+
* uuid() => abcd
|
|
137
|
+
* uuid('time') => 25MR 10-27 17:34:01
|
|
138
|
+
* uuid('time', 0, {startStr:'andy', timeStr:"{h}:{i}:{s}"}) => andy 17:38:23
|
|
139
|
+
* uuid('phone') => 13603312460
|
|
140
|
+
* uuid('email') => cBZA@qq.com
|
|
141
|
+
* uuid('number') => 2319
|
|
142
|
+
* uuid([ { label: "小泽泽", value: "xzz" },{ label: "小月月", value: "xyy" }]) => xzz
|
|
143
|
+
*/
|
|
144
|
+
declare function uuid(type?: string, length?: number, { emailStr, timeStr, startStr, optionsIndex }?: {
|
|
145
|
+
emailStr?: string | undefined;
|
|
146
|
+
timeStr?: string | undefined;
|
|
147
|
+
startStr?: string | undefined;
|
|
148
|
+
optionsIndex?: null | undefined;
|
|
149
|
+
}): any;
|
|
150
|
+
/**
|
|
151
|
+
* 判断传入参数的类型
|
|
152
|
+
* @param {*} type
|
|
153
|
+
* getType(new RegExp()) regexp
|
|
154
|
+
* getType(new Date()) date
|
|
155
|
+
* getType([]) array
|
|
156
|
+
* getType({}) object
|
|
157
|
+
* getType(null) null
|
|
158
|
+
* getType(123) number
|
|
159
|
+
*/
|
|
160
|
+
declare function getType(type: any): string;
|
|
161
|
+
declare function sleep(delay?: number, fn?: () => void): Promise<unknown>;
|
|
162
|
+
/** @使用方式
|
|
163
|
+
* 1. 在el-form中使用
|
|
164
|
+
name: [ proxy.validate('name', { message: '你干嘛哈哈' })],
|
|
165
|
+
between: [ proxy.validate('between', { max: 99 })],
|
|
166
|
+
number: [ proxy.validate('number')],
|
|
167
|
+
length: [proxy.validate('length')],
|
|
168
|
+
mobile: [ proxy.validate('mobile')],
|
|
169
|
+
ip: [ proxy.validate('ip')],
|
|
170
|
+
custom: [proxy.validate('custom', { message: '最多保留2位小数', reg: /^\d+\.?\d{0,2}$/ })]
|
|
171
|
+
confirmRegPwd: [
|
|
172
|
+
proxy.validate('same', { value: form.value.regPwd }),
|
|
173
|
+
], //1. 如果判断两个密码一致, 还要在input输入值改变的时候, 再校验一下两个input
|
|
174
|
+
formRef.value.validate('regPwd')
|
|
175
|
+
formRef.value.validate('confirmRegPwd')
|
|
176
|
+
// 2. rules需要使用computed包裹, 否则值改变无法传递
|
|
177
|
+
* 2. 在函数中使用, 返回boolean
|
|
178
|
+
let ip = proxy.validate('ip', 122322, true)
|
|
179
|
+
let custom = proxy.validate('custom', { value: -123, reg: /^-\d+\.?\d{0,2}$/ }, true)
|
|
180
|
+
*/
|
|
181
|
+
declare function validate(type?: string, rules?: {}, pureValid?: boolean): any;
|
|
182
|
+
/**
|
|
183
|
+
*
|
|
184
|
+
const { res, err } = await proxy.asyncWrapper(listTests, pickForm);
|
|
185
|
+
if (err) {
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
188
|
+
*/
|
|
189
|
+
declare function asyncWrapper(func: any, ...args: any[]): Promise<{
|
|
190
|
+
res: any;
|
|
191
|
+
err?: undefined;
|
|
192
|
+
} | {
|
|
193
|
+
err: unknown;
|
|
194
|
+
res?: undefined;
|
|
195
|
+
}>;
|
|
196
|
+
/** 获取assets静态资源
|
|
197
|
+
* @example
|
|
198
|
+
* proxy.formatImg('1.png')
|
|
199
|
+
* proxy.formatImg('1.png', 'menu')
|
|
200
|
+
* */
|
|
201
|
+
declare function formatImg(photoName: any, addPath?: string, { basePath }?: {
|
|
202
|
+
basePath?: string | undefined;
|
|
203
|
+
}): any;
|
|
204
|
+
/**
|
|
205
|
+
* 复制文本
|
|
206
|
+
*
|
|
207
|
+
* copy('这是要复制的文本');
|
|
208
|
+
* copy('这是要复制的文本', {duration: 500});
|
|
209
|
+
*
|
|
210
|
+
* */
|
|
211
|
+
declare const copy: (text: any, toastParams?: {}) => void;
|
|
212
|
+
/**
|
|
213
|
+
* 1234 => 1,234
|
|
214
|
+
* 1234b => 1,234b
|
|
215
|
+
* 1234.12b => 1,234.12b
|
|
216
|
+
* @param number 加千分位
|
|
217
|
+
* @returns
|
|
218
|
+
*/
|
|
219
|
+
declare function formatThousands(number: any): any;
|
|
220
|
+
declare function log(variableStr: any, variable: any, otherInfo?: string): void;
|
|
221
|
+
/**
|
|
222
|
+
* 生成指定范围内的随机整数
|
|
223
|
+
*
|
|
224
|
+
* @param min 最小值,默认为0
|
|
225
|
+
* @param max 最大值,默认为10
|
|
226
|
+
* @returns 返回生成的随机整数
|
|
227
|
+
*/
|
|
228
|
+
declare function random(min?: number, max?: number): number;
|
|
229
|
+
/**
|
|
230
|
+
* 将文本转换为带有连接符的行文本
|
|
231
|
+
*
|
|
232
|
+
* @param text 要转换的文本
|
|
233
|
+
* @param connect 连接符,默认为'-'
|
|
234
|
+
* @returns 返回转换后的行文本
|
|
235
|
+
* toLine('NameAndy') // name-andy
|
|
236
|
+
* toLine('nameAndy') // name-andy
|
|
237
|
+
* toLine('_nameAndy') // _name-andy
|
|
238
|
+
*/
|
|
239
|
+
declare function toLine(text: any, connect?: string): any;
|
|
240
|
+
declare function processWidth(initValue: any, isBase?: boolean): any;
|
|
241
|
+
/**
|
|
242
|
+
* 增加小数点
|
|
243
|
+
* toFixed(22) -> '22.00'
|
|
244
|
+
* proxy.toFixed('22') -> '22.00'
|
|
245
|
+
* proxy.toFixed('22', 4) -> '22.0000'
|
|
246
|
+
* proxy.toFixed('22', 2, true) -> 22
|
|
247
|
+
*/
|
|
248
|
+
declare function toFixed(value: any, digits?: number): any;
|
|
249
|
+
/**
|
|
250
|
+
* 只有对正整数或者字符串正整数才进行单位的转换,
|
|
251
|
+
* 否则返回原始数据
|
|
252
|
+
* proxy.formatBytes(536870912) // 512MB
|
|
253
|
+
*/
|
|
254
|
+
declare function formatBytes(bytes: any, { toFixed, thousands }?: {
|
|
255
|
+
toFixed?: number | undefined;
|
|
256
|
+
thousands?: boolean | undefined;
|
|
257
|
+
}): any;
|
|
258
|
+
declare function formatBytesConvert(oBytes: any, { thounsand, toFixed }?: {
|
|
259
|
+
thounsand?: boolean | undefined;
|
|
260
|
+
toFixed?: number | undefined;
|
|
261
|
+
}): any;
|
|
262
|
+
declare function throttle(fn: any, delay?: number): () => void;
|
|
263
|
+
declare function debounce(fn: any, delay?: number): () => void;
|
|
264
|
+
/**
|
|
265
|
+
* proxy.confirm('确定删除吗?')
|
|
266
|
+
* proxy.confirm('哈哈', { icon: 'el-icon-plus' })
|
|
267
|
+
* close-on-click-modal: 是否可通过点击遮罩层关闭 MessageBox 默认true
|
|
268
|
+
* lock-scroll: 是否在 MessageBox 出现时将 body 滚动锁定. 默认true
|
|
269
|
+
* 设置宽度, 内容使用组件
|
|
270
|
+
import GWarning from '@/autoComponents/gWarning.vue'
|
|
271
|
+
await proxy.confirm('', {
|
|
272
|
+
dangerouslyUseHTMLString: true,
|
|
273
|
+
customStyle: {
|
|
274
|
+
maxWidth: '600px',
|
|
275
|
+
},
|
|
276
|
+
message: h(GWarning, {
|
|
277
|
+
content:
|
|
278
|
+
'对于光存储开启保持原始对象名称后,对象将作为独立文件在光存储介质直接存储。<br>注意:当桶内文件大小普遍较小(<100MB)或过大(>5GB)时不推荐打开此功能!您确定开启此功能吗?',
|
|
279
|
+
}),
|
|
280
|
+
showCancelButton: true,
|
|
281
|
+
cancelButtonText: '取消',
|
|
282
|
+
appendTo: '#highSettingsForm',
|
|
283
|
+
})
|
|
284
|
+
* 如果是多个dialog嵌套, 可以给上层的dom设置个id如highSettingsForm, 然后appendTo: '#highSettingsForm'
|
|
285
|
+
*/
|
|
286
|
+
declare function confirm(message: any, options: any): Promise<element_plus.MessageBoxData>;
|
|
287
|
+
/**
|
|
288
|
+
* 格式化字符串中的换行符和制表符
|
|
289
|
+
* @param str 待格式化的字符串
|
|
290
|
+
* @returns 格式化后的字符串,如果输入的不是字符串或为空,则返回原字符串
|
|
291
|
+
* @example
|
|
292
|
+
$toast(
|
|
293
|
+
formatNewLines(
|
|
294
|
+
'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',
|
|
295
|
+
),
|
|
296
|
+
{
|
|
297
|
+
duration: 5000,
|
|
298
|
+
dangerouslyUseHTMLString: true,
|
|
299
|
+
},
|
|
300
|
+
)
|
|
301
|
+
*/
|
|
302
|
+
declare function formatNewLines(str: any): any;
|
|
303
|
+
/** Function to get a CSS custom property value
|
|
304
|
+
*
|
|
305
|
+
* getVariable('--blue');
|
|
306
|
+
* */
|
|
307
|
+
declare function getVariable(propertyName: any): string;
|
|
308
|
+
|
|
309
|
+
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, throttle, toFixed, toLine, uuid, validForm, validate };
|