zhl-methods 1.1.12 → 1.1.15

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,6 +2,15 @@
2
2
 
3
3
  版本更新日志
4
4
 
5
+ ### 1.1.14
6
+
7
+ - ScanUDI 方法优化 生产日期到期日期 单独解析 单个解析失败不会影响另外的
8
+
9
+ ### 1.1.13
10
+
11
+ - useRequest 方法 请求接口
12
+ - usePageRequest 方法 请求接口-分页
13
+
5
14
  ### 1.1.12
6
15
 
7
16
  - ScanUDI 方法 增加检测 日期是否正确 错误返回 msg
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 && data.substr(data.length - 2) == "00") {
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
- date = date + "01";
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/js/index.js CHANGED
@@ -30,7 +30,7 @@ export const isIDCode = (value) => {
30
30
  /**
31
31
  * 对象转url参数
32
32
  * @example toUrlQuery({a:1}) => '?a=1'
33
- * @param {value} 要转换的对象
33
+ * @param {Object} 要转换的对象
34
34
  * @returns {String} '?a=1'
35
35
  */
36
36
  export const toUrlQuery = (query) => {
@@ -44,6 +44,29 @@ export const toUrlQuery = (query) => {
44
44
  console.log(error, "toUrlQuery");
45
45
  }
46
46
  };
47
+ /**
48
+ * url参数转对象
49
+ * @example urlQueryToObject('?a=1') => {a:1}
50
+ * @param {String} 要转换的url参数
51
+ * @returns {Object} {a:1}
52
+ */
53
+ export const urlQueryToObject = (str) => {
54
+ try {
55
+ if (str) {
56
+ const params = new URLSearchParams(str);
57
+ let obj = {};
58
+ params.forEach((item, index) => {
59
+ obj[index] = item;
60
+ });
61
+ return obj;
62
+ } else {
63
+ return {};
64
+ }
65
+ } catch (error) {
66
+ console.log(error);
67
+ return {};
68
+ }
69
+ };
47
70
  /**
48
71
  * 将传入的数据转换成千位符
49
72
  * @example numberToPrice(1234.12) => '1,234.12'
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zhl-methods",
3
- "version": "1.1.12",
3
+ "version": "1.1.15",
4
4
  "license": "ISC",
5
5
  "dependencies": {
6
6
  "dayjs": "^1.11.15",
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 };
package/vue3/index.js DELETED
@@ -1,7 +0,0 @@
1
- import { getCurrentInstance } from "vue";
2
-
3
- export function useEmitter() {
4
- const internalInstance = getCurrentInstance();
5
- const emitter = internalInstance.appContext.config.globalProperties.emitter;
6
- return emitter;
7
- }