zhl-methods 1.1.11 → 1.1.14
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 +13 -0
- package/index copy.js +58 -0
- package/index.js +20 -0
- package/js/ScanUDI.js +60 -36
- package/package.json +1 -1
- package/vue3/hook.js +77 -0
- package/vue3/index.js +0 -7
package/VERSION.md
CHANGED
|
@@ -2,6 +2,19 @@
|
|
|
2
2
|
|
|
3
3
|
版本更新日志
|
|
4
4
|
|
|
5
|
+
### 1.1.14
|
|
6
|
+
|
|
7
|
+
- ScanUDI 方法优化 生产日期到期日期 单独解析 单个解析失败不会影响另外的
|
|
8
|
+
|
|
9
|
+
### 1.1.13
|
|
10
|
+
|
|
11
|
+
- useRequest 方法 请求接口
|
|
12
|
+
- usePageRequest 方法 请求接口-分页
|
|
13
|
+
|
|
14
|
+
### 1.1.12
|
|
15
|
+
|
|
16
|
+
- ScanUDI 方法 增加检测 日期是否正确 错误返回 msg
|
|
17
|
+
|
|
5
18
|
### 1.1.11
|
|
6
19
|
|
|
7
20
|
- numberToPrice 方法 增加支持 字符串
|
package/index copy.js
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import jsMethods, {
|
|
2
|
+
isPhone,
|
|
3
|
+
isIDCode,
|
|
4
|
+
toUrlQuery,
|
|
5
|
+
numberToPrice,
|
|
6
|
+
priceToNumber,
|
|
7
|
+
setTwoDecimal,
|
|
8
|
+
getRandomNumber,
|
|
9
|
+
isType,
|
|
10
|
+
toTypeDate,
|
|
11
|
+
toInt,
|
|
12
|
+
copyText,
|
|
13
|
+
downloadFile,
|
|
14
|
+
debounce,
|
|
15
|
+
throttle,
|
|
16
|
+
} from "./js";
|
|
17
|
+
import ScanUDI from "./js/ScanUDI";
|
|
18
|
+
import { useEmitter, useRequest, usePageRequest } from "./vue3";
|
|
19
|
+
import wxMethods, {
|
|
20
|
+
getNavBarHeight,
|
|
21
|
+
confirmModal,
|
|
22
|
+
getEnv,
|
|
23
|
+
getAppId,
|
|
24
|
+
getSafeBottom,
|
|
25
|
+
} from "./wx";
|
|
26
|
+
const copyText = (val) => {
|
|
27
|
+
if (window) {
|
|
28
|
+
return jsMethods.copyText(val);
|
|
29
|
+
}
|
|
30
|
+
if (uni || wx) {
|
|
31
|
+
return wxMethods.copyText(val);
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
export {
|
|
35
|
+
isPhone,
|
|
36
|
+
isIDCode,
|
|
37
|
+
toUrlQuery,
|
|
38
|
+
numberToPrice,
|
|
39
|
+
priceToNumber,
|
|
40
|
+
setTwoDecimal,
|
|
41
|
+
getRandomNumber,
|
|
42
|
+
isType,
|
|
43
|
+
toTypeDate,
|
|
44
|
+
toInt,
|
|
45
|
+
downloadFile,
|
|
46
|
+
debounce,
|
|
47
|
+
throttle,
|
|
48
|
+
ScanUDI,
|
|
49
|
+
copyText,
|
|
50
|
+
useEmitter,
|
|
51
|
+
useRequest,
|
|
52
|
+
usePageRequest,
|
|
53
|
+
getNavBarHeight,
|
|
54
|
+
confirmModal,
|
|
55
|
+
getEnv,
|
|
56
|
+
getAppId,
|
|
57
|
+
getSafeBottom,
|
|
58
|
+
};
|
package/index.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
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;
|
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
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
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
|
-
|
|
32
|
-
|
|
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(
|
|
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(
|
|
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,52 +85,67 @@ 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
|
-
|
|
84
|
-
|
|
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
|
}
|
|
90
107
|
setDateFormat(date, type, expand) {
|
|
91
108
|
try {
|
|
92
109
|
if (date) {
|
|
93
|
-
if (date.length === 8 &&
|
|
110
|
+
if (date.length === 8 && date.substr(date.length - 2) == "00") {
|
|
94
111
|
if (type === "expiry") {
|
|
95
112
|
date = dayjs(date).endOf("month");
|
|
96
113
|
}
|
|
97
|
-
date = dayjs(date).startOf("month");
|
|
114
|
+
date = dayjs(date).startOf("month").add(1, "month");
|
|
98
115
|
}
|
|
99
116
|
if (date.length === 6) {
|
|
100
117
|
if (date.substring(0, 2) === expand.substring(0, 2)) {
|
|
101
118
|
// 年月(6位) - 202507
|
|
102
|
-
|
|
119
|
+
if (type === "expiry") {
|
|
120
|
+
date = dayjs(date + "00").endOf("month");
|
|
121
|
+
} else {
|
|
122
|
+
date = dayjs(date + "01");
|
|
123
|
+
}
|
|
103
124
|
} else {
|
|
104
125
|
// 年后两位月日(6位) - 250708
|
|
105
|
-
date = "20" + date;
|
|
126
|
+
date = dayjs("20" + date);
|
|
106
127
|
}
|
|
107
128
|
}
|
|
108
129
|
// 年后两位月(4位) - 2507
|
|
109
130
|
if (date.length === 4) {
|
|
110
131
|
if (type === "expiry") {
|
|
111
|
-
date = dayjs("20" + date).endOf("month");
|
|
132
|
+
date = dayjs("20" + date + "00").endOf("month");
|
|
112
133
|
}
|
|
113
|
-
date = "20" + date + "01";
|
|
134
|
+
date = dayjs("20" + date + "01");
|
|
135
|
+
}
|
|
136
|
+
if (date.format("YYYY-MM-DD") == "Invalid Date") {
|
|
137
|
+
this.batch_no = "";
|
|
138
|
+
this.msg = "警告:批次信息解析失败,请手动填写";
|
|
139
|
+
return "";
|
|
114
140
|
}
|
|
115
|
-
return
|
|
141
|
+
return date.format("YYYY-MM-DD");
|
|
116
142
|
} else {
|
|
117
143
|
return "";
|
|
118
144
|
}
|
|
119
145
|
} catch (error) {
|
|
146
|
+
this.msg = "警告:解析失败,请联系技术人员处理";
|
|
120
147
|
console.log(error, "setDateFormat error");
|
|
121
|
-
return
|
|
148
|
+
return "";
|
|
122
149
|
}
|
|
123
150
|
}
|
|
124
151
|
removeFrontZeros(str) {
|
|
@@ -130,6 +157,3 @@ export default class ScanUDI {
|
|
|
130
157
|
}
|
|
131
158
|
}
|
|
132
159
|
}
|
|
133
|
-
const scanudi = new ScanUDI({ rules: [] });
|
|
134
|
-
|
|
135
|
-
console.log(scanudi.parse("(01)00047144050546(17)261002(11)241003(10)GJ24117"));
|
package/package.json
CHANGED
package/vue3/hook.js
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
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 };
|