zhl-methods 1.1.10 → 1.1.12

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 CHANGED
@@ -2,7 +2,11 @@
2
2
 
3
3
  版本更新日志
4
4
 
5
- ### 1.1.9
5
+ ### 1.1.12
6
+
7
+ - ScanUDI 方法 增加检测 日期是否正确 错误返回 msg
8
+
9
+ ### 1.1.11
6
10
 
7
11
  - numberToPrice 方法 增加支持 字符串
8
12
 
package/js/ScanUDI.js CHANGED
@@ -20,16 +20,22 @@ export default class ScanUDI {
20
20
  if ((str && str.length < 8) || !str) {
21
21
  return `请输入正确的条形码${str}`;
22
22
  }
23
- let upc = "",
24
- sku_number = "",
25
- manufacture_time = "",
26
- expiry_time = "",
27
- batch_no = "",
28
- serial_no = "";
23
+ this.upc = "";
24
+ this.sku_number = "";
25
+ this.manufacture_time = "";
26
+ this.expiry_time = "";
27
+ this.batch_no = "";
28
+ this.serial_no = "";
29
+ this.msg = "";
29
30
  // 净里镜内部编码
30
31
  if (str.includes("/")) {
31
- [upc, sku_number, manufacture_time, expiry_time, batch_no, serial_no] =
32
- str.split("/");
32
+ let arr = str.split("/");
33
+ this.upc = arr[0];
34
+ this.sku_number = arr[1];
35
+ this.manufacture_time = arr[2];
36
+ this.expiry_time = arr[3];
37
+ this.batch_no = arr[4];
38
+ this.serial_no = arr[5];
33
39
  } else if (str.includes("(")) {
34
40
  const regex = /\((\d{2})\)([^($$)]+)/g;
35
41
  let match;
@@ -37,11 +43,11 @@ export default class ScanUDI {
37
43
  while ((match = regex.exec(str)) !== null) {
38
44
  obj[match[1]] = match[2];
39
45
  }
40
- upc = obj["01"];
41
- manufacture_time = obj["11"];
42
- expiry_time = obj["17"];
43
- batch_no = obj["10"];
44
- serial_no = obj["21"];
46
+ this.upc = obj["01"];
47
+ this.manufacture_time = obj["11"];
48
+ this.expiry_time = obj["17"];
49
+ this.batch_no = obj["10"];
50
+ this.serial_no = obj["21"];
45
51
  } else {
46
52
  if (
47
53
  this.rules.every(
@@ -52,19 +58,25 @@ export default class ScanUDI {
52
58
  }
53
59
  this.rules.forEach((v) => {
54
60
  if (str.length == v.length && str.substring(0, 2) == v.start_value) {
55
- upc = str.substr(v.upc_rule.start, v.upc_rule.length);
56
- batch_no = str.substr(v.batch_no_rule.start, v.batch_no_rule.length);
61
+ this.upc = str.substr(v.upc_rule.start, v.upc_rule.length);
62
+ this.batch_no = str.substr(
63
+ v.batch_no_rule.start,
64
+ v.batch_no_rule.length
65
+ );
57
66
  if (v.manufacture_rule) {
58
- manufacture_time = str.substr(
67
+ this.manufacture_time = str.substr(
59
68
  v.manufacture_rule.start,
60
69
  v.manufacture_rule.length
61
70
  );
62
71
  }
63
72
  if (v.expiry_rule) {
64
- expiry_time = str.substr(v.expiry_rule.start, v.expiry_rule.length);
73
+ this.expiry_time = str.substr(
74
+ v.expiry_rule.start,
75
+ v.expiry_rule.length
76
+ );
65
77
  }
66
78
  if (v.serial_no_rule) {
67
- serial_no = str.substr(
79
+ this.serial_no = str.substr(
68
80
  v.serial_no_rule.start,
69
81
  v.serial_no_rule.length
70
82
  );
@@ -73,17 +85,22 @@ export default class ScanUDI {
73
85
  });
74
86
  }
75
87
  let obj = {
76
- upc: this.removeFrontZeros(upc),
77
- sku_number,
88
+ upc: this.removeFrontZeros(this.upc),
89
+ sku_number: this.sku_number,
78
90
  manufacture_time: this.setDateFormat(
79
- manufacture_time,
91
+ this.manufacture_time,
80
92
  "manufacture",
81
- expiry_time
93
+ this.expiry_time
94
+ ),
95
+ expiry_time: this.setDateFormat(
96
+ this.expiry_time,
97
+ "expiry",
98
+ this.manufacture_time
82
99
  ),
83
- expiry_time: this.setDateFormat(expiry_time, "expiry", manufacture_time),
84
- batch_no: batch_no.toUpperCase(),
85
- serial_no,
100
+ batch_no: this.batch_no.toUpperCase(),
101
+ serial_no: this.serial_no,
86
102
  udi: str.replace(/[^a-zA-Z0-9]/g, ""),
103
+ msg: this.msg,
87
104
  };
88
105
  return obj;
89
106
  }
@@ -112,13 +129,22 @@ export default class ScanUDI {
112
129
  }
113
130
  date = "20" + date + "01";
114
131
  }
132
+ if (
133
+ dayjs(date).format("YYYY-MM-DD") == "Invalid Date" ||
134
+ dayjs(expand).format("YYYY-MM-DD") == "Invalid Date"
135
+ ) {
136
+ this.batch_no = "";
137
+ this.msg = "警告:批次信息解析失败,请手动填写";
138
+ return "";
139
+ }
140
+
115
141
  return dayjs(date).format("YYYY-MM-DD");
116
142
  } else {
117
143
  return "";
118
144
  }
119
145
  } catch (error) {
120
146
  console.log(error, "setDateFormat error");
121
- return date;
147
+ return "";
122
148
  }
123
149
  }
124
150
  removeFrontZeros(str) {
@@ -130,6 +156,3 @@ export default class ScanUDI {
130
156
  }
131
157
  }
132
158
  }
133
- const scanudi = new ScanUDI({ rules: [] });
134
-
135
- console.log(scanudi.parse("(01)00047144050546(17)261002(11)241003(10)GJ24117"));
package/js/index.js CHANGED
@@ -52,7 +52,7 @@ export const toUrlQuery = (query) => {
52
52
  */
53
53
  export const numberToPrice = (number) => {
54
54
  try {
55
- return number.toLocaleString("zh", {
55
+ return Number(number).toLocaleString("zh", {
56
56
  minimumFractionDigits: 2,
57
57
  maximumFractionDigits: 2,
58
58
  style: "decimal",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zhl-methods",
3
- "version": "1.1.10",
3
+ "version": "1.1.12",
4
4
  "license": "ISC",
5
5
  "dependencies": {
6
6
  "dayjs": "^1.11.15",