zhl-methods 1.1.16 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +0 -2
- package/VERSION.md +15 -1
- package/css/colorui.css +733 -0
- package/css/normalize.css +349 -0
- package/css/scrollbar.css +27 -0
- package/index.css +3 -48
- package/js/ScanUDI.js +1 -1
- package/js/index.ts +220 -0
- package/package.json +1 -1
- package/utils/validatorRule.js +25 -0
- package/index.js +0 -20
- package/js/index.js +0 -292
- package/vue3/hook.js +0 -77
package/js/index.js
DELETED
|
@@ -1,292 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 手机号校验
|
|
3
|
-
* @example isPhone('15093676561') => true
|
|
4
|
-
* @param {value} 要校验的数据
|
|
5
|
-
* @returns {Boolean} true false 是 否
|
|
6
|
-
*/
|
|
7
|
-
export const isPhone = (value) => {
|
|
8
|
-
if (typeof value == "number" || typeof value == "string") {
|
|
9
|
-
if (typeof value == "number") {
|
|
10
|
-
value = String(value);
|
|
11
|
-
}
|
|
12
|
-
return /^1[3456789]\d{9}$/.test(value);
|
|
13
|
-
}
|
|
14
|
-
return false;
|
|
15
|
-
};
|
|
16
|
-
/**
|
|
17
|
-
* 身份证号校验
|
|
18
|
-
* @example isIDCode('410781199909090000') => true
|
|
19
|
-
* @param value 要校验的数据
|
|
20
|
-
* @returns true false 是 否
|
|
21
|
-
*/
|
|
22
|
-
export const isIDCode = (value) => {
|
|
23
|
-
if (typeof value == "string") {
|
|
24
|
-
return /^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}([0-9]|X)$/.test(
|
|
25
|
-
value
|
|
26
|
-
);
|
|
27
|
-
}
|
|
28
|
-
return false;
|
|
29
|
-
};
|
|
30
|
-
/**
|
|
31
|
-
* 对象转url参数
|
|
32
|
-
* @example toUrlQuery({a:1}) => '?a=1'
|
|
33
|
-
* @param {Object} 要转换的对象
|
|
34
|
-
* @returns {String} '?a=1'
|
|
35
|
-
*/
|
|
36
|
-
export const toUrlQuery = (query) => {
|
|
37
|
-
try {
|
|
38
|
-
let str = "?";
|
|
39
|
-
Object.keys(query).forEach((key) => {
|
|
40
|
-
str += `${key}=${query[key] ? query[key] : ""}&`;
|
|
41
|
-
});
|
|
42
|
-
return str.slice(0, -1);
|
|
43
|
-
} catch (error) {
|
|
44
|
-
console.log(error, "toUrlQuery");
|
|
45
|
-
}
|
|
46
|
-
};
|
|
47
|
-
/**
|
|
48
|
-
* url参数转对象
|
|
49
|
-
* @example urlQueryToObject('?a=1') => {a:1}
|
|
50
|
-
* @param {String} 要转换的url参数
|
|
51
|
-
* @returns {Object} {a:1}
|
|
52
|
-
*/
|
|
53
|
-
export const urlQueryToObject = (str) => {
|
|
54
|
-
try {
|
|
55
|
-
if (str) {
|
|
56
|
-
const params = new URLSearchParams(str);
|
|
57
|
-
let obj = {};
|
|
58
|
-
params.forEach((item, index) => {
|
|
59
|
-
obj[index] = item;
|
|
60
|
-
});
|
|
61
|
-
return obj;
|
|
62
|
-
} else {
|
|
63
|
-
return {};
|
|
64
|
-
}
|
|
65
|
-
} catch (error) {
|
|
66
|
-
console.log(error);
|
|
67
|
-
return {};
|
|
68
|
-
}
|
|
69
|
-
};
|
|
70
|
-
/**
|
|
71
|
-
* 将传入的数据转换成千位符
|
|
72
|
-
* @example numberToPrice(1234.12) => '1,234.12'
|
|
73
|
-
* @param {number} 要转换的数字
|
|
74
|
-
* @returns {String} '1,234.12'
|
|
75
|
-
*/
|
|
76
|
-
export const numberToPrice = (number) => {
|
|
77
|
-
try {
|
|
78
|
-
return Number(number).toLocaleString("zh", {
|
|
79
|
-
minimumFractionDigits: 2,
|
|
80
|
-
maximumFractionDigits: 2,
|
|
81
|
-
style: "decimal",
|
|
82
|
-
});
|
|
83
|
-
} catch (error) {
|
|
84
|
-
console.log(error, "numberToPrice");
|
|
85
|
-
}
|
|
86
|
-
};
|
|
87
|
-
/**
|
|
88
|
-
* 千位符格式转换数字
|
|
89
|
-
* @example moneyToNumber('123,456.789') => 123456.789
|
|
90
|
-
* @author zhl
|
|
91
|
-
* @date 2023/11/23
|
|
92
|
-
* @param data 要转换的数据
|
|
93
|
-
* @returns 转换完成的数据
|
|
94
|
-
*/
|
|
95
|
-
export const priceToNumber = (data) => {
|
|
96
|
-
return Number(data.replace(/,/gi, ""));
|
|
97
|
-
};
|
|
98
|
-
/**
|
|
99
|
-
* 保留两位小数
|
|
100
|
-
* @example setTwoDecimal(3.144) => '3.14'
|
|
101
|
-
* @param {number} 要保留两位小数的数字
|
|
102
|
-
* @param {isAdjust} 是否四舍五入
|
|
103
|
-
* @returns {String} '3.14'
|
|
104
|
-
*/
|
|
105
|
-
export const setTwoDecimal = (number, isAdjust) => {
|
|
106
|
-
try {
|
|
107
|
-
if (isAdjust) {
|
|
108
|
-
return Math.round(number * Math.pow(10, 2)) / Math.pow(10, 2);
|
|
109
|
-
}
|
|
110
|
-
return (Math.floor(number * 100) / 100).toFixed(2);
|
|
111
|
-
} catch (error) {
|
|
112
|
-
console.log(error, "setTwoDecimal");
|
|
113
|
-
}
|
|
114
|
-
};
|
|
115
|
-
/**
|
|
116
|
-
* 生成随机数
|
|
117
|
-
* @example getRandomNumber(1,100) => 98
|
|
118
|
-
* @param {min} 最小值
|
|
119
|
-
* @param {max} 最大值
|
|
120
|
-
* @returns {Number} 98
|
|
121
|
-
*/
|
|
122
|
-
export const getRandomNumber = (min, max) => {
|
|
123
|
-
return Math.floor(Math.random() * (max - min + 1)) + min;
|
|
124
|
-
};
|
|
125
|
-
/**
|
|
126
|
-
* 检测数据格式
|
|
127
|
-
* @example isType({},object) => true
|
|
128
|
-
* @example isType({}) => object
|
|
129
|
-
* @author zhl
|
|
130
|
-
* @param data 要检测的数据
|
|
131
|
-
* @param type 类型 非必填
|
|
132
|
-
* @returns 不传type 返回数据的类型
|
|
133
|
-
* 传type 返回 true false
|
|
134
|
-
*/
|
|
135
|
-
export const isType = (data, type) => {
|
|
136
|
-
const regex = /\[object (\w+)\]/;
|
|
137
|
-
let str = Object.prototype.toString.call(data);
|
|
138
|
-
const match = regex.exec(str);
|
|
139
|
-
return type ? match[1] === type : match[1];
|
|
140
|
-
};
|
|
141
|
-
/**
|
|
142
|
-
* 时间戳转换成时间
|
|
143
|
-
* @example toTypeDate('1701139100',true) => 2023-11-28 10:38:20
|
|
144
|
-
* @author zhl
|
|
145
|
-
* @param date 要转换的数据 Date格式
|
|
146
|
-
* @param isSeconds 是否显示秒
|
|
147
|
-
* @returns 转换完成的数据
|
|
148
|
-
*/
|
|
149
|
-
export const toTypeDate = (date, isSeconds) => {
|
|
150
|
-
if (date && typeof date == "number") {
|
|
151
|
-
String(date).length == 10
|
|
152
|
-
? (date = new Date(date * 1000))
|
|
153
|
-
: (date = new Date(date));
|
|
154
|
-
} else {
|
|
155
|
-
date = new Date();
|
|
156
|
-
}
|
|
157
|
-
const year = date.getFullYear();
|
|
158
|
-
let month = date.getMonth() + 1;
|
|
159
|
-
let ri = date.getDate();
|
|
160
|
-
let hours = date.getHours();
|
|
161
|
-
let minutes = date.getMinutes();
|
|
162
|
-
let seconds = date.getSeconds();
|
|
163
|
-
if (month < 10) month = "0" + month;
|
|
164
|
-
if (ri < 10) ri = "0" + ri;
|
|
165
|
-
if (hours < 10) hours = "0" + hours;
|
|
166
|
-
if (minutes < 10) minutes = "0" + minutes;
|
|
167
|
-
if (seconds < 10) seconds = "0" + seconds;
|
|
168
|
-
|
|
169
|
-
return (
|
|
170
|
-
year +
|
|
171
|
-
"-" +
|
|
172
|
-
month +
|
|
173
|
-
"-" +
|
|
174
|
-
ri +
|
|
175
|
-
" " +
|
|
176
|
-
hours +
|
|
177
|
-
":" +
|
|
178
|
-
minutes +
|
|
179
|
-
(isSeconds ? ":" + seconds : "")
|
|
180
|
-
);
|
|
181
|
-
};
|
|
182
|
-
/**
|
|
183
|
-
* 转换成整数
|
|
184
|
-
* @example toInt(123.123) => 123
|
|
185
|
-
* @param value 要转成整数的数据 字符串 数字
|
|
186
|
-
* @returns true false 是 否
|
|
187
|
-
*/
|
|
188
|
-
export const toInt = (value) => {
|
|
189
|
-
if (typeof value == "number") {
|
|
190
|
-
return ~~value;
|
|
191
|
-
}
|
|
192
|
-
if (typeof value == "string") {
|
|
193
|
-
return parseInt(value, 10);
|
|
194
|
-
}
|
|
195
|
-
return 0;
|
|
196
|
-
};
|
|
197
|
-
/**
|
|
198
|
-
* 复制
|
|
199
|
-
* @example copyText(123) => Promise
|
|
200
|
-
* @param content 要复制的数据
|
|
201
|
-
* @returns Promise 复制成功 失败
|
|
202
|
-
*/
|
|
203
|
-
export const copyText = (content) => {
|
|
204
|
-
return new Promise((resolve, reject) => {
|
|
205
|
-
try {
|
|
206
|
-
// 创建输入框元素
|
|
207
|
-
const input = document.createElement("input"); //不会保留文本格式
|
|
208
|
-
//如果要保留文本格式,比如保留换行符,或者多行文本,可以使用 textarea 标签,再配和模板字符串 ` `
|
|
209
|
-
//const input = document.createElement('textarea')
|
|
210
|
-
// 将想要复制的值
|
|
211
|
-
input.value = content;
|
|
212
|
-
// 页面底部追加输入框
|
|
213
|
-
document.body.appendChild(input);
|
|
214
|
-
// 选中输入框
|
|
215
|
-
input.select();
|
|
216
|
-
// 执行浏览器复制命令
|
|
217
|
-
document.execCommand("Copy");
|
|
218
|
-
// 弹出复制成功信息
|
|
219
|
-
//this.$message.success('复制成功');
|
|
220
|
-
// 复制后移除输入框
|
|
221
|
-
input.remove();
|
|
222
|
-
resolve(true);
|
|
223
|
-
} catch (err) {
|
|
224
|
-
reject(err);
|
|
225
|
-
}
|
|
226
|
-
});
|
|
227
|
-
};
|
|
228
|
-
/**
|
|
229
|
-
* 下载文件
|
|
230
|
-
* @example downloadFile('www.baidu.com','文件名称')
|
|
231
|
-
* @param url 要下载的文件 地址
|
|
232
|
-
* @param name 要下载的文件名称
|
|
233
|
-
* @returns 没有返回值
|
|
234
|
-
*/
|
|
235
|
-
export const downloadFile = (url, name) => {
|
|
236
|
-
let a = document.createElement("a");
|
|
237
|
-
a.href = url;
|
|
238
|
-
a.download = name;
|
|
239
|
-
a.style.display = "none";
|
|
240
|
-
document.body.appendChild(a);
|
|
241
|
-
a.click();
|
|
242
|
-
a.remove();
|
|
243
|
-
};
|
|
244
|
-
/**
|
|
245
|
-
* 防抖
|
|
246
|
-
* @example debounce(() => {}, 250)
|
|
247
|
-
* @param fn 防抖的函数
|
|
248
|
-
* @param wait 防抖时间 毫秒
|
|
249
|
-
* @returns fn
|
|
250
|
-
*/
|
|
251
|
-
export const debounce = (fn, wait = 250) => {
|
|
252
|
-
let timeout = null;
|
|
253
|
-
return function () {
|
|
254
|
-
let context = this;
|
|
255
|
-
let args = arguments;
|
|
256
|
-
if (timeout) clearTimeout(timeout);
|
|
257
|
-
let callNow = !timeout;
|
|
258
|
-
timeout = setTimeout(() => {
|
|
259
|
-
timeout = null;
|
|
260
|
-
}, wait);
|
|
261
|
-
if (callNow) fn.apply(context, args);
|
|
262
|
-
};
|
|
263
|
-
};
|
|
264
|
-
/**
|
|
265
|
-
* 节流
|
|
266
|
-
* @example throttle(()=>{})
|
|
267
|
-
* @param fn 节流的函数
|
|
268
|
-
* @param threshhold 节流时间
|
|
269
|
-
* @param scope this
|
|
270
|
-
* @returns 没有返回值
|
|
271
|
-
*/
|
|
272
|
-
export const throttle = (fn, threshhold, scope) => {
|
|
273
|
-
threshhold || (threshhold = 250);
|
|
274
|
-
let last, timer;
|
|
275
|
-
return function () {
|
|
276
|
-
let context = scope || this;
|
|
277
|
-
let now = +new Date(),
|
|
278
|
-
args = arguments;
|
|
279
|
-
if (last && now < last + threshhold) {
|
|
280
|
-
// 如果在节流时间内,则取消之前的延迟调用
|
|
281
|
-
clearTimeout(timer);
|
|
282
|
-
// 设定一个新的延迟调用
|
|
283
|
-
timer = setTimeout(function () {
|
|
284
|
-
last = now;
|
|
285
|
-
fn.apply(context, args);
|
|
286
|
-
}, threshhold);
|
|
287
|
-
} else {
|
|
288
|
-
last = now;
|
|
289
|
-
fn.apply(context, args);
|
|
290
|
-
}
|
|
291
|
-
};
|
|
292
|
-
};
|
package/vue3/hook.js
DELETED
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
import { ref, getCurrentInstance } from "vue";
|
|
2
|
-
const useEmitter = () => {
|
|
3
|
-
const internalInstance = getCurrentInstance();
|
|
4
|
-
const emitter = internalInstance.appContext.config.globalProperties.emitter;
|
|
5
|
-
return emitter;
|
|
6
|
-
};
|
|
7
|
-
//请求接口
|
|
8
|
-
const useRequest = (api, options = {}) => {
|
|
9
|
-
const loading = ref(false);
|
|
10
|
-
const query = ref(options.query ? options.query : {});
|
|
11
|
-
const data = ref({});
|
|
12
|
-
const run = async (callback) => {
|
|
13
|
-
loading.value = true;
|
|
14
|
-
try {
|
|
15
|
-
let apiRequest;
|
|
16
|
-
if (options.setQueryFormat) {
|
|
17
|
-
apiRequest = options.setQueryFormat(query.value);
|
|
18
|
-
} else {
|
|
19
|
-
apiRequest = query.value;
|
|
20
|
-
}
|
|
21
|
-
const res = await api(apiRequest);
|
|
22
|
-
if (res.code === 200) {
|
|
23
|
-
data.value = res.data;
|
|
24
|
-
if (callback) {
|
|
25
|
-
callback(res);
|
|
26
|
-
} else if (options.success) {
|
|
27
|
-
options.success(res);
|
|
28
|
-
}
|
|
29
|
-
} else {
|
|
30
|
-
if (options.error) {
|
|
31
|
-
options.error(res);
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
} catch (err) {
|
|
35
|
-
if (options.error) {
|
|
36
|
-
options.error(err);
|
|
37
|
-
}
|
|
38
|
-
} finally {
|
|
39
|
-
loading.value = false;
|
|
40
|
-
}
|
|
41
|
-
};
|
|
42
|
-
if (options.autoRequest) {
|
|
43
|
-
run();
|
|
44
|
-
}
|
|
45
|
-
return [loading, query, data, run];
|
|
46
|
-
};
|
|
47
|
-
//请求接口-分页
|
|
48
|
-
const usePageRequest = (api, options = {}) => {
|
|
49
|
-
const page = ref(1);
|
|
50
|
-
const limit = ref(15);
|
|
51
|
-
const total = ref(0);
|
|
52
|
-
const [loading, query, data, run] = useRequest(api, {
|
|
53
|
-
...options,
|
|
54
|
-
query: {
|
|
55
|
-
page,
|
|
56
|
-
limit,
|
|
57
|
-
...options.query,
|
|
58
|
-
},
|
|
59
|
-
success(res) {
|
|
60
|
-
total.value = res.data.total;
|
|
61
|
-
},
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
const pageChange = (p, l) => {
|
|
65
|
-
console.log(123);
|
|
66
|
-
page.value = p;
|
|
67
|
-
limit.value = l;
|
|
68
|
-
run();
|
|
69
|
-
};
|
|
70
|
-
const refresh = () => {
|
|
71
|
-
page.value = 1;
|
|
72
|
-
limit.value = 15;
|
|
73
|
-
run();
|
|
74
|
-
};
|
|
75
|
-
return [loading, query, data, page, limit, total, pageChange, refresh];
|
|
76
|
-
};
|
|
77
|
-
export { useEmitter, useRequest, usePageRequest };
|