zhl-methods 1.1.12 → 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 +9 -0
- package/index copy.js +58 -0
- package/index.js +20 -0
- package/js/ScanUDI.js +13 -12
- package/package.json +1 -1
- package/vue3/hook.js +77 -0
- package/vue3/index.js +0 -7
package/VERSION.md
CHANGED
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
|
@@ -107,42 +107,43 @@ export default class ScanUDI {
|
|
|
107
107
|
setDateFormat(date, type, expand) {
|
|
108
108
|
try {
|
|
109
109
|
if (date) {
|
|
110
|
-
if (date.length === 8 &&
|
|
110
|
+
if (date.length === 8 && date.substr(date.length - 2) == "00") {
|
|
111
111
|
if (type === "expiry") {
|
|
112
112
|
date = dayjs(date).endOf("month");
|
|
113
113
|
}
|
|
114
|
-
date = dayjs(date).startOf("month");
|
|
114
|
+
date = dayjs(date).startOf("month").add(1, "month");
|
|
115
115
|
}
|
|
116
116
|
if (date.length === 6) {
|
|
117
117
|
if (date.substring(0, 2) === expand.substring(0, 2)) {
|
|
118
118
|
// 年月(6位) - 202507
|
|
119
|
-
|
|
119
|
+
if (type === "expiry") {
|
|
120
|
+
date = dayjs(date + "00").endOf("month");
|
|
121
|
+
} else {
|
|
122
|
+
date = dayjs(date + "01");
|
|
123
|
+
}
|
|
120
124
|
} else {
|
|
121
125
|
// 年后两位月日(6位) - 250708
|
|
122
|
-
date = "20" + date;
|
|
126
|
+
date = dayjs("20" + date);
|
|
123
127
|
}
|
|
124
128
|
}
|
|
125
129
|
// 年后两位月(4位) - 2507
|
|
126
130
|
if (date.length === 4) {
|
|
127
131
|
if (type === "expiry") {
|
|
128
|
-
date = dayjs("20" + date).endOf("month");
|
|
132
|
+
date = dayjs("20" + date + "00").endOf("month");
|
|
129
133
|
}
|
|
130
|
-
date = "20" + date + "01";
|
|
134
|
+
date = dayjs("20" + date + "01");
|
|
131
135
|
}
|
|
132
|
-
if (
|
|
133
|
-
dayjs(date).format("YYYY-MM-DD") == "Invalid Date" ||
|
|
134
|
-
dayjs(expand).format("YYYY-MM-DD") == "Invalid Date"
|
|
135
|
-
) {
|
|
136
|
+
if (date.format("YYYY-MM-DD") == "Invalid Date") {
|
|
136
137
|
this.batch_no = "";
|
|
137
138
|
this.msg = "警告:批次信息解析失败,请手动填写";
|
|
138
139
|
return "";
|
|
139
140
|
}
|
|
140
|
-
|
|
141
|
-
return dayjs(date).format("YYYY-MM-DD");
|
|
141
|
+
return date.format("YYYY-MM-DD");
|
|
142
142
|
} else {
|
|
143
143
|
return "";
|
|
144
144
|
}
|
|
145
145
|
} catch (error) {
|
|
146
|
+
this.msg = "警告:解析失败,请联系技术人员处理";
|
|
146
147
|
console.log(error, "setDateFormat error");
|
|
147
148
|
return "";
|
|
148
149
|
}
|
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 };
|