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
|
@@ -0,0 +1,349 @@
|
|
|
1
|
+
/*! normalize.css v8.0.1 | MIT License | github.com/necolas/normalize.css */
|
|
2
|
+
|
|
3
|
+
/* Document
|
|
4
|
+
========================================================================== */
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* 1. Correct the line height in all browsers.
|
|
8
|
+
* 2. Prevent adjustments of font size after orientation changes in iOS.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
html {
|
|
12
|
+
line-height: 1.15; /* 1 */
|
|
13
|
+
-webkit-text-size-adjust: 100%; /* 2 */
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/* Sections
|
|
17
|
+
========================================================================== */
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Remove the margin in all browsers.
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
body {
|
|
24
|
+
margin: 0;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Render the `main` element consistently in IE.
|
|
29
|
+
*/
|
|
30
|
+
|
|
31
|
+
main {
|
|
32
|
+
display: block;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Correct the font size and margin on `h1` elements within `section` and
|
|
37
|
+
* `article` contexts in Chrome, Firefox, and Safari.
|
|
38
|
+
*/
|
|
39
|
+
|
|
40
|
+
h1 {
|
|
41
|
+
font-size: 2em;
|
|
42
|
+
margin: 0.67em 0;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/* Grouping content
|
|
46
|
+
========================================================================== */
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* 1. Add the correct box sizing in Firefox.
|
|
50
|
+
* 2. Show the overflow in Edge and IE.
|
|
51
|
+
*/
|
|
52
|
+
|
|
53
|
+
hr {
|
|
54
|
+
box-sizing: content-box; /* 1 */
|
|
55
|
+
height: 0; /* 1 */
|
|
56
|
+
overflow: visible; /* 2 */
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* 1. Correct the inheritance and scaling of font size in all browsers.
|
|
61
|
+
* 2. Correct the odd `em` font sizing in all browsers.
|
|
62
|
+
*/
|
|
63
|
+
|
|
64
|
+
pre {
|
|
65
|
+
font-family: monospace, monospace; /* 1 */
|
|
66
|
+
font-size: 1em; /* 2 */
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/* Text-level semantics
|
|
70
|
+
========================================================================== */
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Remove the gray background on active links in IE 10.
|
|
74
|
+
*/
|
|
75
|
+
|
|
76
|
+
a {
|
|
77
|
+
background-color: transparent;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* 1. Remove the bottom border in Chrome 57-
|
|
82
|
+
* 2. Add the correct text decoration in Chrome, Edge, IE, Opera, and Safari.
|
|
83
|
+
*/
|
|
84
|
+
|
|
85
|
+
abbr[title] {
|
|
86
|
+
border-bottom: none; /* 1 */
|
|
87
|
+
text-decoration: underline; /* 2 */
|
|
88
|
+
text-decoration: underline dotted; /* 2 */
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Add the correct font weight in Chrome, Edge, and Safari.
|
|
93
|
+
*/
|
|
94
|
+
|
|
95
|
+
b,
|
|
96
|
+
strong {
|
|
97
|
+
font-weight: bolder;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* 1. Correct the inheritance and scaling of font size in all browsers.
|
|
102
|
+
* 2. Correct the odd `em` font sizing in all browsers.
|
|
103
|
+
*/
|
|
104
|
+
|
|
105
|
+
code,
|
|
106
|
+
kbd,
|
|
107
|
+
samp {
|
|
108
|
+
font-family: monospace, monospace; /* 1 */
|
|
109
|
+
font-size: 1em; /* 2 */
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Add the correct font size in all browsers.
|
|
114
|
+
*/
|
|
115
|
+
|
|
116
|
+
small {
|
|
117
|
+
font-size: 80%;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Prevent `sub` and `sup` elements from affecting the line height in
|
|
122
|
+
* all browsers.
|
|
123
|
+
*/
|
|
124
|
+
|
|
125
|
+
sub,
|
|
126
|
+
sup {
|
|
127
|
+
font-size: 75%;
|
|
128
|
+
line-height: 0;
|
|
129
|
+
position: relative;
|
|
130
|
+
vertical-align: baseline;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
sub {
|
|
134
|
+
bottom: -0.25em;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
sup {
|
|
138
|
+
top: -0.5em;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/* Embedded content
|
|
142
|
+
========================================================================== */
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* Remove the border on images inside links in IE 10.
|
|
146
|
+
*/
|
|
147
|
+
|
|
148
|
+
img {
|
|
149
|
+
border-style: none;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/* Forms
|
|
153
|
+
========================================================================== */
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* 1. Change the font styles in all browsers.
|
|
157
|
+
* 2. Remove the margin in Firefox and Safari.
|
|
158
|
+
*/
|
|
159
|
+
|
|
160
|
+
button,
|
|
161
|
+
input,
|
|
162
|
+
optgroup,
|
|
163
|
+
select,
|
|
164
|
+
textarea {
|
|
165
|
+
font-family: inherit; /* 1 */
|
|
166
|
+
font-size: 100%; /* 1 */
|
|
167
|
+
line-height: 1.15; /* 1 */
|
|
168
|
+
margin: 0; /* 2 */
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* Show the overflow in IE.
|
|
173
|
+
* 1. Show the overflow in Edge.
|
|
174
|
+
*/
|
|
175
|
+
|
|
176
|
+
button,
|
|
177
|
+
input { /* 1 */
|
|
178
|
+
overflow: visible;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* Remove the inheritance of text transform in Edge, Firefox, and IE.
|
|
183
|
+
* 1. Remove the inheritance of text transform in Firefox.
|
|
184
|
+
*/
|
|
185
|
+
|
|
186
|
+
button,
|
|
187
|
+
select { /* 1 */
|
|
188
|
+
text-transform: none;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* Correct the inability to style clickable types in iOS and Safari.
|
|
193
|
+
*/
|
|
194
|
+
|
|
195
|
+
button,
|
|
196
|
+
[type="button"],
|
|
197
|
+
[type="reset"],
|
|
198
|
+
[type="submit"] {
|
|
199
|
+
-webkit-appearance: button;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* Remove the inner border and padding in Firefox.
|
|
204
|
+
*/
|
|
205
|
+
|
|
206
|
+
button::-moz-focus-inner,
|
|
207
|
+
[type="button"]::-moz-focus-inner,
|
|
208
|
+
[type="reset"]::-moz-focus-inner,
|
|
209
|
+
[type="submit"]::-moz-focus-inner {
|
|
210
|
+
border-style: none;
|
|
211
|
+
padding: 0;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
/**
|
|
215
|
+
* Restore the focus styles unset by the previous rule.
|
|
216
|
+
*/
|
|
217
|
+
|
|
218
|
+
button:-moz-focusring,
|
|
219
|
+
[type="button"]:-moz-focusring,
|
|
220
|
+
[type="reset"]:-moz-focusring,
|
|
221
|
+
[type="submit"]:-moz-focusring {
|
|
222
|
+
outline: 1px dotted ButtonText;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
/**
|
|
226
|
+
* Correct the padding in Firefox.
|
|
227
|
+
*/
|
|
228
|
+
|
|
229
|
+
fieldset {
|
|
230
|
+
padding: 0.35em 0.75em 0.625em;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
/**
|
|
234
|
+
* 1. Correct the text wrapping in Edge and IE.
|
|
235
|
+
* 2. Correct the color inheritance from `fieldset` elements in IE.
|
|
236
|
+
* 3. Remove the padding so developers are not caught out when they zero out
|
|
237
|
+
* `fieldset` elements in all browsers.
|
|
238
|
+
*/
|
|
239
|
+
|
|
240
|
+
legend {
|
|
241
|
+
box-sizing: border-box; /* 1 */
|
|
242
|
+
color: inherit; /* 2 */
|
|
243
|
+
display: table; /* 1 */
|
|
244
|
+
max-width: 100%; /* 1 */
|
|
245
|
+
padding: 0; /* 3 */
|
|
246
|
+
white-space: normal; /* 1 */
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
/**
|
|
250
|
+
* Add the correct vertical alignment in Chrome, Firefox, and Opera.
|
|
251
|
+
*/
|
|
252
|
+
|
|
253
|
+
progress {
|
|
254
|
+
vertical-align: baseline;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
/**
|
|
258
|
+
* Remove the default vertical scrollbar in IE 10+.
|
|
259
|
+
*/
|
|
260
|
+
|
|
261
|
+
textarea {
|
|
262
|
+
overflow: auto;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
/**
|
|
266
|
+
* 1. Add the correct box sizing in IE 10.
|
|
267
|
+
* 2. Remove the padding in IE 10.
|
|
268
|
+
*/
|
|
269
|
+
|
|
270
|
+
[type="checkbox"],
|
|
271
|
+
[type="radio"] {
|
|
272
|
+
box-sizing: border-box; /* 1 */
|
|
273
|
+
padding: 0; /* 2 */
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
/**
|
|
277
|
+
* Correct the cursor style of increment and decrement buttons in Chrome.
|
|
278
|
+
*/
|
|
279
|
+
|
|
280
|
+
[type="number"]::-webkit-inner-spin-button,
|
|
281
|
+
[type="number"]::-webkit-outer-spin-button {
|
|
282
|
+
height: auto;
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
/**
|
|
286
|
+
* 1. Correct the odd appearance in Chrome and Safari.
|
|
287
|
+
* 2. Correct the outline style in Safari.
|
|
288
|
+
*/
|
|
289
|
+
|
|
290
|
+
[type="search"] {
|
|
291
|
+
-webkit-appearance: textfield; /* 1 */
|
|
292
|
+
outline-offset: -2px; /* 2 */
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
/**
|
|
296
|
+
* Remove the inner padding in Chrome and Safari on macOS.
|
|
297
|
+
*/
|
|
298
|
+
|
|
299
|
+
[type="search"]::-webkit-search-decoration {
|
|
300
|
+
-webkit-appearance: none;
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
/**
|
|
304
|
+
* 1. Correct the inability to style clickable types in iOS and Safari.
|
|
305
|
+
* 2. Change font properties to `inherit` in Safari.
|
|
306
|
+
*/
|
|
307
|
+
|
|
308
|
+
::-webkit-file-upload-button {
|
|
309
|
+
-webkit-appearance: button; /* 1 */
|
|
310
|
+
font: inherit; /* 2 */
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
/* Interactive
|
|
314
|
+
========================================================================== */
|
|
315
|
+
|
|
316
|
+
/*
|
|
317
|
+
* Add the correct display in Edge, IE 10+, and Firefox.
|
|
318
|
+
*/
|
|
319
|
+
|
|
320
|
+
details {
|
|
321
|
+
display: block;
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
/*
|
|
325
|
+
* Add the correct display in all browsers.
|
|
326
|
+
*/
|
|
327
|
+
|
|
328
|
+
summary {
|
|
329
|
+
display: list-item;
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
/* Misc
|
|
333
|
+
========================================================================== */
|
|
334
|
+
|
|
335
|
+
/**
|
|
336
|
+
* Add the correct display in IE 10+.
|
|
337
|
+
*/
|
|
338
|
+
|
|
339
|
+
template {
|
|
340
|
+
display: none;
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
/**
|
|
344
|
+
* Add the correct display in IE 10.
|
|
345
|
+
*/
|
|
346
|
+
|
|
347
|
+
[hidden] {
|
|
348
|
+
display: none;
|
|
349
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/*滚动条整体部分*/
|
|
2
|
+
.scrollbar ::-webkit-scrollbar {
|
|
3
|
+
width: 8px;
|
|
4
|
+
height: 6px;
|
|
5
|
+
}
|
|
6
|
+
/*滚动条的轨道*/
|
|
7
|
+
.scrollbar ::-webkit-scrollbar-track {
|
|
8
|
+
background-color: #ffffff;
|
|
9
|
+
}
|
|
10
|
+
/*滚动条里面的小方块,能向上向下移动*/
|
|
11
|
+
.scrollbar ::-webkit-scrollbar-thumb {
|
|
12
|
+
background-color: #bfbfbf;
|
|
13
|
+
border-radius: 5px;
|
|
14
|
+
border: 1px solid #f1f1f1;
|
|
15
|
+
box-shadow: inset 0 0 6px rgba(0, 0, 0, 0.3);
|
|
16
|
+
cursor: pointer;
|
|
17
|
+
}
|
|
18
|
+
.scrollbar ::-webkit-scrollbar-thumb:hover {
|
|
19
|
+
background-color: #a8a8a8;
|
|
20
|
+
}
|
|
21
|
+
.scrollbar ::-webkit-scrollbar-thumb:active {
|
|
22
|
+
background-color: #787878;
|
|
23
|
+
}
|
|
24
|
+
/*边角,即两个滚动条的交汇处*/
|
|
25
|
+
.scrollbar ::-webkit-scrollbar-corner {
|
|
26
|
+
background-color: #ffffff;
|
|
27
|
+
}
|
package/index.css
CHANGED
|
@@ -1,48 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
.
|
|
3
|
-
|
|
4
|
-
overflow: hidden;
|
|
5
|
-
/*禁止换行*/
|
|
6
|
-
white-space: nowrap;
|
|
7
|
-
/*显示省略号*/
|
|
8
|
-
text-overflow: ellipsis;
|
|
9
|
-
}
|
|
10
|
-
/* 三行溢出省略号 */
|
|
11
|
-
.manyWrap {
|
|
12
|
-
/* 必须结合的属性 ,将对象作为弹性伸缩盒子模型显示 。*/
|
|
13
|
-
display: -webkit-box;
|
|
14
|
-
/* 必须结合的属性 ,设置或检索伸缩盒对象的子元素的排列方式 。*/
|
|
15
|
-
-webkit-box-orient: vertical;
|
|
16
|
-
/*要显示的行数*/
|
|
17
|
-
-webkit-line-clamp: 3;
|
|
18
|
-
line-clamp: 3;
|
|
19
|
-
/* 溢出部分隐藏 */
|
|
20
|
-
overflow: hidden;
|
|
21
|
-
}
|
|
22
|
-
/*滚动条整体部分*/
|
|
23
|
-
.scrollbar ::-webkit-scrollbar {
|
|
24
|
-
width: 8px;
|
|
25
|
-
height: 6px;
|
|
26
|
-
}
|
|
27
|
-
/*滚动条的轨道*/
|
|
28
|
-
.scrollbar ::-webkit-scrollbar-track {
|
|
29
|
-
background-color: #ffffff;
|
|
30
|
-
}
|
|
31
|
-
/*滚动条里面的小方块,能向上向下移动*/
|
|
32
|
-
.scrollbar ::-webkit-scrollbar-thumb {
|
|
33
|
-
background-color: #bfbfbf;
|
|
34
|
-
border-radius: 5px;
|
|
35
|
-
border: 1px solid #f1f1f1;
|
|
36
|
-
box-shadow: inset 0 0 6px rgba(0, 0, 0, 0.3);
|
|
37
|
-
cursor: pointer;
|
|
38
|
-
}
|
|
39
|
-
.scrollbar ::-webkit-scrollbar-thumb:hover {
|
|
40
|
-
background-color: #a8a8a8;
|
|
41
|
-
}
|
|
42
|
-
.scrollbar ::-webkit-scrollbar-thumb:active {
|
|
43
|
-
background-color: #787878;
|
|
44
|
-
}
|
|
45
|
-
/*边角,即两个滚动条的交汇处*/
|
|
46
|
-
.scrollbar ::-webkit-scrollbar-corner {
|
|
47
|
-
background-color: #ffffff;
|
|
48
|
-
}
|
|
1
|
+
@import url("./css/normalize.css");
|
|
2
|
+
@import url("./css/scrollbar.css");
|
|
3
|
+
@import url("./css/colorui.css");
|
package/js/ScanUDI.js
CHANGED
|
@@ -107,7 +107,6 @@ export default class ScanUDI {
|
|
|
107
107
|
setDateFormat(date, type, expand) {
|
|
108
108
|
try {
|
|
109
109
|
if (date) {
|
|
110
|
-
date = dayjs(date);
|
|
111
110
|
if (date.length === 8 && date.substr(date.length - 2) == "00") {
|
|
112
111
|
if (type === "expiry") {
|
|
113
112
|
date = dayjs(date).endOf("month");
|
|
@@ -134,6 +133,7 @@ export default class ScanUDI {
|
|
|
134
133
|
}
|
|
135
134
|
date = dayjs("20" + date + "01");
|
|
136
135
|
}
|
|
136
|
+
date = dayjs(date);
|
|
137
137
|
if (date.format("YYYY-MM-DD") == "Invalid Date") {
|
|
138
138
|
this.batch_no = "";
|
|
139
139
|
this.msg = "警告:批次信息解析失败,请手动填写";
|
package/js/index.ts
ADDED
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
import { tel, idCard } from "../utils/validatorRule";
|
|
2
|
+
/**
|
|
3
|
+
* 手机号校验
|
|
4
|
+
* @example isPhone('15093676561') => true
|
|
5
|
+
* @param value 要校验的数据
|
|
6
|
+
* @returns true false 是 否
|
|
7
|
+
*/
|
|
8
|
+
export const isPhone = (value: number | string): boolean => {
|
|
9
|
+
if (typeof value == "number") {
|
|
10
|
+
value = String(value);
|
|
11
|
+
}
|
|
12
|
+
return tel.test(value);
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* 身份证号校验
|
|
16
|
+
* @example isIDCode('410781199909090000') => true
|
|
17
|
+
* @param value 要校验的数据
|
|
18
|
+
* @returns true false 是 否
|
|
19
|
+
*/
|
|
20
|
+
export const isIDCode = (value: number | string): boolean => {
|
|
21
|
+
if (typeof value == "string") {
|
|
22
|
+
return idCard.test(value);
|
|
23
|
+
}
|
|
24
|
+
return false;
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* 对象转url参数
|
|
28
|
+
* @example toUrlQuery({a:1}) => '?a=1'
|
|
29
|
+
* @param query 要转换的对象
|
|
30
|
+
*/
|
|
31
|
+
export const toUrlQuery = (query: object): string => {
|
|
32
|
+
let str = "?";
|
|
33
|
+
Object.keys(query).forEach((key) => {
|
|
34
|
+
str += `${key}=${query[key] ? query[key] : ""}&`;
|
|
35
|
+
});
|
|
36
|
+
return str.slice(0, -1);
|
|
37
|
+
};
|
|
38
|
+
/**
|
|
39
|
+
* url参数转对象
|
|
40
|
+
* @example urlQueryToObject('?a=1') => {a:1}
|
|
41
|
+
* @param str 要转换的url参数
|
|
42
|
+
*/
|
|
43
|
+
export const urlQueryToObject = (str: string): object => {
|
|
44
|
+
const params = new URLSearchParams(str);
|
|
45
|
+
let obj = {};
|
|
46
|
+
params.forEach((item, index) => {
|
|
47
|
+
obj[index] = item;
|
|
48
|
+
});
|
|
49
|
+
return obj;
|
|
50
|
+
};
|
|
51
|
+
/**
|
|
52
|
+
* 将传入的数据转换成千位符
|
|
53
|
+
* @example numberToPrice(1234.12) => '1,234.12'
|
|
54
|
+
* @param number 要转换的数字
|
|
55
|
+
*/
|
|
56
|
+
export const numberToPrice = (number: number | string): string => {
|
|
57
|
+
return Number(number).toLocaleString("zh", {
|
|
58
|
+
minimumFractionDigits: 2,
|
|
59
|
+
maximumFractionDigits: 2,
|
|
60
|
+
style: "decimal",
|
|
61
|
+
});
|
|
62
|
+
};
|
|
63
|
+
/**
|
|
64
|
+
* 千位符格式转换数字
|
|
65
|
+
* @example moneyToNumber('123,456.789') => 123456.789
|
|
66
|
+
* @param data 要转换的数据
|
|
67
|
+
*/
|
|
68
|
+
export const priceToNumber = (data: string): number => {
|
|
69
|
+
return Number(data.replace(/,/gi, ""));
|
|
70
|
+
};
|
|
71
|
+
/**
|
|
72
|
+
* 保留两位小数
|
|
73
|
+
* @example setTwoDecimal(3.144) => '3.14'
|
|
74
|
+
* @param number 要保留两位小数的数字
|
|
75
|
+
* @param isAdjust 是否四舍五入
|
|
76
|
+
*/
|
|
77
|
+
export const setTwoDecimal = (
|
|
78
|
+
number: number | string,
|
|
79
|
+
isAdjust: boolean,
|
|
80
|
+
): string | number => {
|
|
81
|
+
if (isAdjust) {
|
|
82
|
+
return Math.round(Number(number) * Math.pow(10, 2)) / Math.pow(10, 2);
|
|
83
|
+
}
|
|
84
|
+
return (Math.floor(Number(number) * 100) / 100).toFixed(2);
|
|
85
|
+
};
|
|
86
|
+
/**
|
|
87
|
+
* 生成随机数
|
|
88
|
+
* @example getRandomNumber(1,100) => 98
|
|
89
|
+
* @param min 最小值
|
|
90
|
+
* @param max 最大值
|
|
91
|
+
*/
|
|
92
|
+
export const getRandomNumber = (min: number, max: number): number => {
|
|
93
|
+
return Math.floor(Math.random() * (max - min + 1)) + min;
|
|
94
|
+
};
|
|
95
|
+
/**
|
|
96
|
+
* 检测数据格式
|
|
97
|
+
* @example isType({},Object) => true
|
|
98
|
+
* @example isType({}) => Object
|
|
99
|
+
* @param data 要检测的数据
|
|
100
|
+
* @param type 类型 非必填
|
|
101
|
+
* @returns 不传type 返回数据的类型 传type 返回 true false
|
|
102
|
+
*/
|
|
103
|
+
export const isType = (data: any, type: string): boolean | string => {
|
|
104
|
+
const regex = /\[object (\w+)\]/;
|
|
105
|
+
let str = Object.prototype.toString.call(data);
|
|
106
|
+
const match = regex.exec(str);
|
|
107
|
+
return type ? match[1] === type : match[1];
|
|
108
|
+
};
|
|
109
|
+
/**
|
|
110
|
+
* 转换成整数
|
|
111
|
+
* @example toInt(123.123) => 123
|
|
112
|
+
* @param value 要转成整数的数据
|
|
113
|
+
* @returns true false 是 否
|
|
114
|
+
*/
|
|
115
|
+
export const toInt = (value: number | string): number => {
|
|
116
|
+
if (typeof value == "number") {
|
|
117
|
+
return ~~value;
|
|
118
|
+
}
|
|
119
|
+
if (typeof value == "string") {
|
|
120
|
+
return parseInt(value, 10);
|
|
121
|
+
}
|
|
122
|
+
return 0;
|
|
123
|
+
};
|
|
124
|
+
/**
|
|
125
|
+
* 复制
|
|
126
|
+
* @example copyText(123) => Promise
|
|
127
|
+
* @param content 要复制的数据
|
|
128
|
+
* @returns Promise true false 复制成功 失败
|
|
129
|
+
*/
|
|
130
|
+
export const copyText = (content: any): Promise<boolean> => {
|
|
131
|
+
return new Promise((resolve, reject) => {
|
|
132
|
+
try {
|
|
133
|
+
// 创建输入框元素
|
|
134
|
+
const input = document.createElement("input"); //不会保留文本格式
|
|
135
|
+
//如果要保留文本格式,比如保留换行符,或者多行文本,可以使用 textarea 标签,再配和模板字符串 ` `
|
|
136
|
+
//const input = document.createElement('textarea')
|
|
137
|
+
// 将想要复制的值
|
|
138
|
+
input.value = content;
|
|
139
|
+
// 页面底部追加输入框
|
|
140
|
+
document.body.appendChild(input);
|
|
141
|
+
// 选中输入框
|
|
142
|
+
input.select();
|
|
143
|
+
// 执行浏览器复制命令
|
|
144
|
+
document.execCommand("Copy");
|
|
145
|
+
// 弹出复制成功信息
|
|
146
|
+
//this.$message.success('复制成功');
|
|
147
|
+
// 复制后移除输入框
|
|
148
|
+
input.remove();
|
|
149
|
+
resolve(true);
|
|
150
|
+
} catch (err) {
|
|
151
|
+
reject(false);
|
|
152
|
+
console.log("复制失败", err);
|
|
153
|
+
}
|
|
154
|
+
});
|
|
155
|
+
};
|
|
156
|
+
/**
|
|
157
|
+
* 下载文件
|
|
158
|
+
* @example downloadFile('www.baidu.com','文件名称')
|
|
159
|
+
* @param url 要下载的文件 地址
|
|
160
|
+
* @param name 要下载的文件名称
|
|
161
|
+
*/
|
|
162
|
+
export const downloadFile = (url: string, name: string) => {
|
|
163
|
+
let a = document.createElement("a");
|
|
164
|
+
a.href = url;
|
|
165
|
+
a.download = name;
|
|
166
|
+
a.target = "_blank";
|
|
167
|
+
a.style.display = "none";
|
|
168
|
+
document.body.appendChild(a);
|
|
169
|
+
a.click();
|
|
170
|
+
a.remove();
|
|
171
|
+
};
|
|
172
|
+
/**
|
|
173
|
+
* 防抖
|
|
174
|
+
* @example debounce(() => {}, 250) => Function
|
|
175
|
+
* @param fn 防抖的函数
|
|
176
|
+
* @param wait 防抖时间 毫秒
|
|
177
|
+
*/
|
|
178
|
+
export const debounce = (fn: Function, wait: number = 250) => {
|
|
179
|
+
let timeout: any = null;
|
|
180
|
+
return function () {
|
|
181
|
+
let args = arguments;
|
|
182
|
+
if (timeout) clearTimeout(timeout);
|
|
183
|
+
let callNow = !timeout;
|
|
184
|
+
timeout = setTimeout(() => {
|
|
185
|
+
timeout = null;
|
|
186
|
+
}, wait);
|
|
187
|
+
if (callNow) fn.apply(this, args);
|
|
188
|
+
};
|
|
189
|
+
};
|
|
190
|
+
/**
|
|
191
|
+
* 节流
|
|
192
|
+
* @example throttle(()=>{}) => Function
|
|
193
|
+
* @param fn 节流的函数
|
|
194
|
+
* @param threshhold 节流时间
|
|
195
|
+
* @param scope this
|
|
196
|
+
*/
|
|
197
|
+
export const throttle = (
|
|
198
|
+
fn: Function,
|
|
199
|
+
threshhold: number = 250,
|
|
200
|
+
scope: object,
|
|
201
|
+
): Function => {
|
|
202
|
+
let last: any, timer: any;
|
|
203
|
+
return function () {
|
|
204
|
+
let context = scope || this;
|
|
205
|
+
let now = +new Date(),
|
|
206
|
+
args = arguments;
|
|
207
|
+
if (last && now < last + threshhold) {
|
|
208
|
+
// 如果在节流时间内,则取消之前的延迟调用
|
|
209
|
+
clearTimeout(timer);
|
|
210
|
+
// 设定一个新的延迟调用
|
|
211
|
+
timer = setTimeout(function () {
|
|
212
|
+
last = now;
|
|
213
|
+
fn.apply(context, args);
|
|
214
|
+
}, threshhold);
|
|
215
|
+
} else {
|
|
216
|
+
last = now;
|
|
217
|
+
fn.apply(context, args);
|
|
218
|
+
}
|
|
219
|
+
};
|
|
220
|
+
};
|
package/package.json
CHANGED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// 手机号
|
|
2
|
+
export const tel = /^1[3456789]\d{9}$/;
|
|
3
|
+
// 固话/手机号
|
|
4
|
+
export const allTel = /^((0\d{2,3})-)(\d{7,8})(-(\d{3,}))?$/;
|
|
5
|
+
// 校验手机或者座机
|
|
6
|
+
export const landline = /^((0\d{2,3}-\d{7,8})|(1[23456789]\d{9}))$/;
|
|
7
|
+
// 银行卡
|
|
8
|
+
export const bank = /^([1-9]{1})(\d{11,23})$/;
|
|
9
|
+
// 整数
|
|
10
|
+
export const digits = /^\d+$/;
|
|
11
|
+
// 身份证
|
|
12
|
+
export const idCard =
|
|
13
|
+
/^[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)$/;
|
|
14
|
+
// 正整数
|
|
15
|
+
export const integer = /^[0-9]+$/;
|
|
16
|
+
// 数字、字母
|
|
17
|
+
export const alphanumeric = /^[0-9a-zA-Z]+$/;
|
|
18
|
+
//货架码
|
|
19
|
+
export const shelf_code = /^([A-Z]{1})([0-9]{3})$/;
|
|
20
|
+
//汉字和数字
|
|
21
|
+
export const expiry = /^([0-9]{1,2})[\u4e00-\u9fa5]$/;
|
|
22
|
+
//产品码
|
|
23
|
+
export const product_code = /^([A-Z]{1})([0-9]{3})$/;
|
|
24
|
+
// 邮箱
|
|
25
|
+
export const email_code = /^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)*$/;
|
package/index.js
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import jsMethods from "./js";
|
|
2
|
-
import ScanUDI from "./js/ScanUDI";
|
|
3
|
-
import hooks from "./vue3/hook";
|
|
4
|
-
import wxMethods from "./wx";
|
|
5
|
-
|
|
6
|
-
const defaultMethods = {
|
|
7
|
-
...jsMethods,
|
|
8
|
-
...wxMethods,
|
|
9
|
-
ScanUDI,
|
|
10
|
-
...hooks,
|
|
11
|
-
copyText: (val) => {
|
|
12
|
-
if (window) {
|
|
13
|
-
return jsMethods.copyText(val);
|
|
14
|
-
}
|
|
15
|
-
if (uni || wx) {
|
|
16
|
-
return wxMethods.copyText(val);
|
|
17
|
-
}
|
|
18
|
-
},
|
|
19
|
-
};
|
|
20
|
-
export default defaultMethods;
|