zhl-methods 1.1.1 → 1.1.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/VERSION.md +10 -6
- package/js/ScanUDI.js +124 -0
- package/js/index.js +3 -3
- package/package.json +2 -1
package/VERSION.md
CHANGED
|
@@ -2,16 +2,20 @@
|
|
|
2
2
|
|
|
3
3
|
版本更新日志
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
### 1.1.2
|
|
6
6
|
|
|
7
|
-
- 增加
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
- 增加 /js/ScanUDI.js 文件 扫描 净里镜规则 括号规则 自定义规则
|
|
8
|
+
|
|
9
|
+
### 1.1.1
|
|
10
|
+
|
|
11
|
+
- 删除 wx 'requestApi' 方法 使用 'confirmModal' 代替
|
|
10
12
|
|
|
11
13
|
### 1.1.0
|
|
12
14
|
|
|
13
15
|
- 小程序 兼容 uin 和 wx 方法
|
|
14
16
|
|
|
15
|
-
|
|
17
|
+
#### 1.0.5
|
|
16
18
|
|
|
17
|
-
-
|
|
19
|
+
- 增加 css 文件
|
|
20
|
+
- 单/多行文本溢出省略号 nowrap/manyWrap
|
|
21
|
+
- 滚动条样式 scrollbar
|
package/js/ScanUDI.js
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import dayjs from "dayjs";
|
|
2
|
+
|
|
3
|
+
export default class ScanUDI {
|
|
4
|
+
constructor({ rules }) {
|
|
5
|
+
this.rules = rules;
|
|
6
|
+
// if (str) {
|
|
7
|
+
// return this.parse(str);
|
|
8
|
+
// } else {
|
|
9
|
+
// return this;
|
|
10
|
+
// }
|
|
11
|
+
}
|
|
12
|
+
UDIMap = {
|
|
13
|
+
"01": "upc",
|
|
14
|
+
11: "manufacture_time",
|
|
15
|
+
17: "expiry_time",
|
|
16
|
+
10: "batch_no",
|
|
17
|
+
21: "serial_no",
|
|
18
|
+
};
|
|
19
|
+
parse(str) {
|
|
20
|
+
if ((str && str.length < 8) || !str) {
|
|
21
|
+
return `请输入正确的条形码${str}`;
|
|
22
|
+
}
|
|
23
|
+
let upc = "",
|
|
24
|
+
sku_number = "",
|
|
25
|
+
manufacture_time = "",
|
|
26
|
+
expiry_time = "",
|
|
27
|
+
batch_no = "",
|
|
28
|
+
serial_no = "";
|
|
29
|
+
// 净里镜内部编码
|
|
30
|
+
if (str.includes("/")) {
|
|
31
|
+
[upc, sku_number, manufacture_time, expiry_time, batch_no, serial_no] =
|
|
32
|
+
str.split("/");
|
|
33
|
+
} else if (str.includes("(")) {
|
|
34
|
+
const regex = /\((\d{2})\)([^($$)]+)/g;
|
|
35
|
+
let match;
|
|
36
|
+
while ((match = regex.exec(str)) !== null) {
|
|
37
|
+
if (match[1] == "01") {
|
|
38
|
+
upc = match[2];
|
|
39
|
+
}
|
|
40
|
+
if (match[1] == "11") {
|
|
41
|
+
manufacture_time = match[2];
|
|
42
|
+
}
|
|
43
|
+
if (match[1] == "17") {
|
|
44
|
+
expiry_time = match[2];
|
|
45
|
+
}
|
|
46
|
+
if (match[1] == "10") {
|
|
47
|
+
batch_no = match[2];
|
|
48
|
+
}
|
|
49
|
+
if (match[1] == "21") {
|
|
50
|
+
serial_no = match[2];
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
} else {
|
|
54
|
+
// let re = /[^\u4e00-\u9fa5a-zA-Z0-9]/g;
|
|
55
|
+
// str = str.replace(re, "");
|
|
56
|
+
if (
|
|
57
|
+
this.rules.every(
|
|
58
|
+
(v) => str.length != v.length || str.substring(0, 2) != v.start_value
|
|
59
|
+
)
|
|
60
|
+
) {
|
|
61
|
+
return `${str}条码或二维码解析失败,请联系技术人员处理`;
|
|
62
|
+
}
|
|
63
|
+
this.rules.forEach((v) => {
|
|
64
|
+
if (str.length == v.length && str.substring(0, 2) == v.start_value) {
|
|
65
|
+
upc = str.substr(v.upc_rule.start, v.upc_rule.length);
|
|
66
|
+
batch_no = str.substr(v.batch_no_rule.start, v.batch_no_rule.length);
|
|
67
|
+
if (v.manufacture_rule) {
|
|
68
|
+
manufacture_time = str.substr(
|
|
69
|
+
v.manufacture_rule.start,
|
|
70
|
+
v.manufacture_rule.length
|
|
71
|
+
);
|
|
72
|
+
}
|
|
73
|
+
if (v.expiry_rule) {
|
|
74
|
+
expiry_time = str.substr(v.expiry_rule.start, v.expiry_rule.length);
|
|
75
|
+
}
|
|
76
|
+
if (v.serial_no_rule) {
|
|
77
|
+
serial_no = str.substr(
|
|
78
|
+
v.serial_no_rule.start,
|
|
79
|
+
v.serial_no_rule.length
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
return {
|
|
86
|
+
upc: this.removeFrontZeros(upc),
|
|
87
|
+
sku_number,
|
|
88
|
+
manufacture_time: this.setDateFormat(manufacture_time, "manufacture"),
|
|
89
|
+
expiry_time: this.setDateFormat(expiry_time, "expiry"),
|
|
90
|
+
batch_no,
|
|
91
|
+
serial_no,
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
setDateFormat(date, type) {
|
|
95
|
+
if (date.length === 6) {
|
|
96
|
+
// 年月(6位) - 202507
|
|
97
|
+
if (date.substring(0, 2) === "20") {
|
|
98
|
+
return date + "01";
|
|
99
|
+
}
|
|
100
|
+
// 年后两位月日(6位) - 250708
|
|
101
|
+
if (date.substring(0, 2) !== "20") {
|
|
102
|
+
return "20" + date;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
// 年后两位月(4位) - 2507
|
|
106
|
+
if (date.length === 4) {
|
|
107
|
+
if (type === "expiry") {
|
|
108
|
+
return dayjs("20" + date)
|
|
109
|
+
.endOf("month")
|
|
110
|
+
.format("YYYYMMDD");
|
|
111
|
+
}
|
|
112
|
+
return "20" + date + "01";
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
return date;
|
|
116
|
+
}
|
|
117
|
+
removeFrontZeros(str) {
|
|
118
|
+
try {
|
|
119
|
+
return str.replace(/^0+/, "");
|
|
120
|
+
} catch (error) {
|
|
121
|
+
return str;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
package/js/index.js
CHANGED
|
@@ -248,10 +248,10 @@ export const debounce = (fn, wait = 250) => {
|
|
|
248
248
|
*/
|
|
249
249
|
export const throttle = (fn, threshhold, scope) => {
|
|
250
250
|
threshhold || (threshhold = 250);
|
|
251
|
-
|
|
251
|
+
let last, timer;
|
|
252
252
|
return function () {
|
|
253
|
-
|
|
254
|
-
|
|
253
|
+
let context = scope || this;
|
|
254
|
+
let now = +new Date(),
|
|
255
255
|
args = arguments;
|
|
256
256
|
if (last && now < last + threshhold) {
|
|
257
257
|
// 如果在节流时间内,则取消之前的延迟调用
|