ztxkutils 2.2.3 → 2.2.7

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/dist/index.js CHANGED
@@ -1,9 +1,9 @@
1
1
  export { c as authority } from './authority-17b7fde2.js';
2
2
  export { d as dataModel } from './dataModel-1fbaff40.js';
3
- export { t as tools } from './tools-e1b35b23.js';
3
+ export { t as tools } from './tools-2876d65c.js';
4
4
  export { v as validate } from './validate-01242f5f.js';
5
5
  export { r as request } from './request-74ca7860.js';
6
- export { r as reqUrl } from './reqUrl-68c864fb.js';
6
+ export { r as reqUrl } from './reqUrl-cf7d6223.js';
7
7
  import './tslib.es6-b9033aad.js';
8
8
  import 'dayjs';
9
9
  import 'number-precision';
@@ -0,0 +1,51 @@
1
+ /**
2
+ * @file 项目基本配置,包括各个环境的请求地址
3
+ */
4
+ // 环境变量
5
+ function getReqUrl(processObj) {
6
+ var ENV = processObj.REACT_APP_ENV;
7
+ // api服务器各个环境地址
8
+ var ZT_API_DEV = processObj.REACT_APP_ZT_API_DEV || 'http://192.168.0.83:8000'; // 开发环境
9
+ var ZT_API_TEST = processObj.REACT_APP_ZT_API_TEST || 'http://192.168.0.135:8000'; // 测试环境
10
+ var ZT_API_STAGE = processObj.REACT_APP_ZT_API_STAGE || 'http://192.168.0.134:8000'; // 阶段性环境
11
+ var ZT_API_PRODUCT = processObj.REACT_APP_ZT_API_PRODUCT || 'http://dz.zmd.com.cn'; // 生产环境
12
+ var ZT_API_PUBLIC_PRODUCT = processObj.REACT_ZT_API_PUBLIC_PRODUCT || 'http://dz.zmd.com.cn:8000'; // 生产环境外网api地址
13
+ // 文件服务器
14
+ var ZT_FILE_PREVIEW_DEV = processObj.REACT_APP_ZT_FILE_PREVIEW_DEV || 'http://192.168.0.83:88'; // 开发环境
15
+ var ZT_FILE_PREVIEW_TEST = processObj.REACT_APP_ZT_FILE_PREVIEW_TEST || 'http://192.168.0.135:8012'; // 测试环境
16
+ var ZT_FILE_PREVIEW_STAGE = processObj.REACT_APP_ZT_FILE_PREVIEW_STAGE || 'http://192.168.0.134:8012'; // 阶段性环境
17
+ var ZT_FILE_PREVIEW_PRODUCT = processObj.REACT_ZT_FILE_PREVIEW_PRODUCT || 'http://dzfile.zmd.com.cn:8012'; // 生产环境
18
+ // 实际api请求地址
19
+ var ZT_API_BASEURL = ZT_API_DEV;
20
+ var ZT_API_PUBLICURL = ZT_API_PUBLIC_PRODUCT;
21
+ var ZT_FILE_BASEURL = ZT_FILE_PREVIEW_DEV;
22
+ if (ENV) {
23
+ switch (ENV.toLowerCase()) {
24
+ case 'zt-dev':
25
+ ZT_API_BASEURL = ZT_API_DEV;
26
+ ZT_FILE_BASEURL = ZT_FILE_PREVIEW_DEV;
27
+ break;
28
+ case 'zt-test':
29
+ ZT_API_BASEURL = ZT_API_TEST;
30
+ ZT_FILE_BASEURL = ZT_FILE_PREVIEW_TEST;
31
+ break;
32
+ case 'zt-stage':
33
+ ZT_API_BASEURL = ZT_API_STAGE;
34
+ ZT_FILE_BASEURL = ZT_FILE_PREVIEW_STAGE;
35
+ break;
36
+ case 'zt-product':
37
+ ZT_API_BASEURL = ZT_API_PRODUCT;
38
+ ZT_FILE_BASEURL = ZT_FILE_PREVIEW_PRODUCT;
39
+ ZT_API_PUBLICURL = ZT_API_PUBLICURL;
40
+ break;
41
+ }
42
+ }
43
+ return { ZT_API_BASEURL: ZT_API_BASEURL, ZT_FILE_BASEURL: ZT_FILE_BASEURL, ZT_API_PUBLICURL: ZT_API_PUBLICURL };
44
+ }
45
+
46
+ var reqUrl = /*#__PURE__*/Object.freeze({
47
+ __proto__: null,
48
+ getReqUrl: getReqUrl
49
+ });
50
+
51
+ export { getReqUrl as g, reqUrl as r };
package/dist/reqUrl.d.ts CHANGED
@@ -4,4 +4,5 @@
4
4
  export declare function getReqUrl(processObj: any): {
5
5
  ZT_API_BASEURL: any;
6
6
  ZT_FILE_BASEURL: any;
7
+ ZT_API_PUBLICURL: any;
7
8
  };
package/dist/reqUrl.js CHANGED
@@ -1 +1 @@
1
- export { g as getReqUrl } from './reqUrl-68c864fb.js';
1
+ export { g as getReqUrl } from './reqUrl-cf7d6223.js';
@@ -0,0 +1,217 @@
1
+ import { _ as __assign, a as __spreadArray } from './tslib.es6-b9033aad.js';
2
+ import dayjs from 'dayjs';
3
+ import { divide as divide$1, round, plus, minus, times } from 'number-precision';
4
+
5
+ /**
6
+ * @description 时间格式转换
7
+ */
8
+ function timeTransfrom(timeParams) {
9
+ var _a, _b, _c, _d, _e;
10
+ var params = timeParams.params, fromKey = timeParams.fromKey, toKey = timeParams.toKey, _f = timeParams.type, type = _f === void 0 ? 'string' : _f, format = timeParams.format;
11
+ var copyParams = __assign({}, params);
12
+ for (var i = 0; i < fromKey.length; i++) {
13
+ var fromKeyItem = fromKey[i];
14
+ var toKeyItem = toKey[i];
15
+ var formatItem = Array.isArray(format)
16
+ ? format[i]
17
+ ? format[i]
18
+ : 'YYYY-MM-DD'
19
+ : format
20
+ ? format
21
+ : 'YYYY-MM-DD';
22
+ // 从一个键转换成两个键
23
+ if (typeof fromKeyItem === 'string' && typeof toKeyItem === 'object') {
24
+ if (type === 'string' && copyParams[fromKeyItem]) {
25
+ var _g = copyParams[fromKeyItem], startMoment = _g[0], endMoment = _g[1];
26
+ var start = void 0, end = void 0;
27
+ if (dayjs.isDayjs(startMoment)) {
28
+ start = startMoment.format(formatItem);
29
+ }
30
+ if (dayjs.isDayjs(endMoment)) {
31
+ end = endMoment.format(formatItem);
32
+ }
33
+ if (formatItem === 'YYYY-MM-DD HH:mm:ss') {
34
+ start = start.substr(0, 10) + ' 00:00:00';
35
+ end = end.substr(0, 10) + ' 23:59:59';
36
+ }
37
+ delete copyParams[fromKeyItem];
38
+ copyParams = __assign(__assign({}, copyParams), (_a = {}, _a[toKeyItem[0]] = start, _a[toKeyItem[1]] = end, _a));
39
+ }
40
+ else {
41
+ copyParams = __assign(__assign({}, copyParams), (_b = {}, _b[toKeyItem[0]] = undefined, _b[toKeyItem[1]] = undefined, _b));
42
+ }
43
+ }
44
+ // 从一个键转换成一个键
45
+ if (typeof fromKeyItem === 'string' && typeof toKeyItem === 'string') {
46
+ if (type === 'string') {
47
+ var _dayjsObj = copyParams[fromKeyItem];
48
+ var start = void 0;
49
+ if (dayjs.isDayjs(_dayjsObj)) {
50
+ start = _dayjsObj.format(formatItem);
51
+ }
52
+ if (formatItem === 'startTime') {
53
+ start = start.substr(0, 10) + ' 00:00:00';
54
+ }
55
+ if (formatItem === 'endTime') {
56
+ start = start.substr(0, 10) + ' 23:59:59';
57
+ }
58
+ delete copyParams[fromKeyItem];
59
+ copyParams = __assign(__assign({}, copyParams), (_c = {}, _c[toKeyItem] = start, _c));
60
+ }
61
+ if (type === 'object') {
62
+ var start = copyParams[fromKeyItem]
63
+ ? dayjs(copyParams[fromKeyItem])
64
+ : undefined;
65
+ delete copyParams[fromKeyItem];
66
+ copyParams = __assign(__assign({}, copyParams), (_d = {}, _d[toKeyItem] = start, _d));
67
+ }
68
+ }
69
+ // 从两个键转换成一个键
70
+ if (typeof fromKeyItem === 'object' && typeof toKeyItem === 'string') {
71
+ if (type === 'object') {
72
+ var startMoment = fromKeyItem[0], endMoment = fromKeyItem[1];
73
+ var intime = copyParams[toKeyItem] || [null, null];
74
+ if (copyParams[startMoment]) {
75
+ intime[0] = dayjs(copyParams[startMoment]);
76
+ delete copyParams[startMoment];
77
+ }
78
+ if (copyParams[endMoment]) {
79
+ intime[1] = dayjs(copyParams[endMoment]);
80
+ delete copyParams[endMoment];
81
+ }
82
+ if (intime[0] == null || intime[1] == null) {
83
+ intime = null;
84
+ }
85
+ copyParams = __assign(__assign({}, copyParams), (_e = {}, _e[toKeyItem] = intime, _e));
86
+ }
87
+ }
88
+ }
89
+ return copyParams;
90
+ }
91
+ function divide(num1, num2) {
92
+ var others = [];
93
+ for (var _i = 2; _i < arguments.length; _i++) {
94
+ others[_i - 2] = arguments[_i];
95
+ }
96
+ try {
97
+ return divide$1.apply(void 0, __spreadArray([num1, num2], others));
98
+ }
99
+ catch (err) {
100
+ console.log(err);
101
+ return 0;
102
+ }
103
+ }
104
+ /**
105
+ * @description 精确四舍五入后保留几位小数
106
+ */
107
+ function exactRound(num, ratio) {
108
+ var typeNum = typeof num;
109
+ if (typeNum !== 'number' && typeNum !== 'string') {
110
+ return num;
111
+ }
112
+ try {
113
+ return round(num, ratio).toFixed(ratio);
114
+ }
115
+ catch (err) {
116
+ console.error(err);
117
+ return num;
118
+ }
119
+ }
120
+ /**
121
+ * @description 添加千分符符号
122
+ */
123
+ function toThousand(num) {
124
+ var typeNum = typeof num;
125
+ if (typeNum !== 'number' && typeNum !== 'string') {
126
+ return num;
127
+ }
128
+ var str = (num + '').replace(/(\d{1,3})(?=(\d{3})+(?:$|\.))/g, '$1,');
129
+ return str;
130
+ }
131
+ /**
132
+ * @description 去除指定字符串
133
+ */
134
+ function clearAssignStr(str, originalStr) {
135
+ if (!originalStr) {
136
+ return originalStr;
137
+ }
138
+ if (originalStr.startsWith(str)) {
139
+ return originalStr.replace(str, '');
140
+ }
141
+ return originalStr;
142
+ }
143
+ /**
144
+ * @description 下载重命名
145
+ */
146
+ function loadFileRename(fileUrl, fileName) {
147
+ var xhr = new XMLHttpRequest();
148
+ xhr.open('GET', fileUrl, true);
149
+ xhr.responseType = 'blob';
150
+ xhr.onload = function () {
151
+ if (xhr.status === 200) {
152
+ var link = document.createElement('a');
153
+ var body = document.querySelector('body');
154
+ link.href = window.URL.createObjectURL(xhr.response);
155
+ link.download = fileName;
156
+ // fix Firefox
157
+ link.style.display = 'none';
158
+ body.appendChild(link);
159
+ link.click();
160
+ body.removeChild(link);
161
+ window.URL.revokeObjectURL(link.href);
162
+ }
163
+ };
164
+ xhr.send();
165
+ }
166
+ /**
167
+ * @description 文件大小提示转换
168
+ */
169
+ function transformFileSize(value) {
170
+ if (value < 1024) {
171
+ return round(value, 2).toFixed(2) + 'B';
172
+ }
173
+ else if (value < 1024 * 1024) {
174
+ return round(divide(value, 1024), 2).toFixed(2) + 'KB';
175
+ }
176
+ return round(divide(value, 1024, 1024), 2).toFixed(2) + 'MB';
177
+ }
178
+ /**
179
+ * @description 更具key判断前后值是否一致
180
+ */
181
+ function isEqualByKey(keys, record, preRecord) {
182
+ var isEqual = false; // 是否相等
183
+ if (!record || !preRecord) {
184
+ isEqual = true;
185
+ return isEqual;
186
+ }
187
+ // 如果数据源相同的话,那么判断是初次更改,应该更新
188
+ if (record === preRecord) {
189
+ isEqual = true;
190
+ return isEqual;
191
+ }
192
+ for (var i = 0; i < keys.length; i++) {
193
+ var key = keys[i];
194
+ if (record[key] !== preRecord[key]) {
195
+ isEqual = true;
196
+ break;
197
+ }
198
+ }
199
+ return isEqual;
200
+ }
201
+
202
+ var tools = /*#__PURE__*/Object.freeze({
203
+ __proto__: null,
204
+ timeTransfrom: timeTransfrom,
205
+ plus: plus,
206
+ minus: minus,
207
+ times: times,
208
+ divide: divide,
209
+ exactRound: exactRound,
210
+ toThousand: toThousand,
211
+ clearAssignStr: clearAssignStr,
212
+ loadFileRename: loadFileRename,
213
+ transformFileSize: transformFileSize,
214
+ isEqualByKey: isEqualByKey
215
+ });
216
+
217
+ export { timeTransfrom as a, toThousand as b, clearAssignStr as c, divide as d, exactRound as e, transformFileSize as f, isEqualByKey as i, loadFileRename as l, tools as t };
@@ -0,0 +1,215 @@
1
+ import { _ as __assign, a as __spreadArray } from './tslib.es6-b9033aad.js';
2
+ import dayjs from 'dayjs';
3
+ import { divide as divide$1, round, plus, minus, times } from 'number-precision';
4
+
5
+ /**
6
+ * @description 时间格式转换
7
+ */
8
+ function timeTransfrom(timeParams) {
9
+ var _a, _b, _c, _d, _e;
10
+ var params = timeParams.params, fromKey = timeParams.fromKey, toKey = timeParams.toKey, _f = timeParams.type, type = _f === void 0 ? 'string' : _f, format = timeParams.format;
11
+ var copyParams = __assign({}, params);
12
+ for (var i = 0; i < fromKey.length; i++) {
13
+ var fromKeyItem = fromKey[i];
14
+ var toKeyItem = toKey[i];
15
+ var formatItem = Array.isArray(format)
16
+ ? format[i]
17
+ : format
18
+ ? format
19
+ : 'YYYY-MM-DD';
20
+ // 从一个键转换成两个键
21
+ if (typeof fromKeyItem === 'string' && typeof toKeyItem === 'object') {
22
+ if (type === 'string' && copyParams[fromKeyItem]) {
23
+ var _g = copyParams[fromKeyItem], startMoment = _g[0], endMoment = _g[1];
24
+ var start = void 0, end = void 0;
25
+ if (dayjs.isDayjs(startMoment)) {
26
+ start = startMoment.format(formatItem);
27
+ }
28
+ if (dayjs.isDayjs(endMoment)) {
29
+ end = endMoment.format(formatItem);
30
+ }
31
+ if (formatItem === 'YYYY-MM-DD HH:mm:ss') {
32
+ start = start.substr(0, 10) + ' 00:00:00';
33
+ end = end.substr(0, 10) + ' 23:59:59';
34
+ }
35
+ delete copyParams[fromKeyItem];
36
+ copyParams = __assign(__assign({}, copyParams), (_a = {}, _a[toKeyItem[0]] = start, _a[toKeyItem[1]] = end, _a));
37
+ }
38
+ else {
39
+ copyParams = __assign(__assign({}, copyParams), (_b = {}, _b[toKeyItem[0]] = undefined, _b[toKeyItem[1]] = undefined, _b));
40
+ }
41
+ }
42
+ // 从一个键转换成一个键
43
+ if (typeof fromKeyItem === 'string' && typeof toKeyItem === 'string') {
44
+ if (type === 'string') {
45
+ var _dayjsObj = copyParams[fromKeyItem];
46
+ var start = void 0;
47
+ if (dayjs.isDayjs(_dayjsObj)) {
48
+ start = _dayjsObj.format(formatItem);
49
+ }
50
+ if (formatItem === 'startTime') {
51
+ start = start.substr(0, 10) + ' 00:00:00';
52
+ }
53
+ if (formatItem === 'endTime') {
54
+ start = start.substr(0, 10) + ' 23:59:59';
55
+ }
56
+ delete copyParams[fromKeyItem];
57
+ copyParams = __assign(__assign({}, copyParams), (_c = {}, _c[toKeyItem] = start, _c));
58
+ }
59
+ if (type === 'object') {
60
+ var start = copyParams[fromKeyItem]
61
+ ? dayjs(copyParams[fromKeyItem])
62
+ : undefined;
63
+ delete copyParams[fromKeyItem];
64
+ copyParams = __assign(__assign({}, copyParams), (_d = {}, _d[toKeyItem] = start, _d));
65
+ }
66
+ }
67
+ // 从两个键转换成一个键
68
+ if (typeof fromKeyItem === 'object' && typeof toKeyItem === 'string') {
69
+ if (type === 'object') {
70
+ var startMoment = fromKeyItem[0], endMoment = fromKeyItem[1];
71
+ var intime = copyParams[toKeyItem] || [null, null];
72
+ if (copyParams[startMoment]) {
73
+ intime[0] = dayjs(copyParams[startMoment]);
74
+ delete copyParams[startMoment];
75
+ }
76
+ if (copyParams[endMoment]) {
77
+ intime[1] = dayjs(copyParams[endMoment]);
78
+ delete copyParams[endMoment];
79
+ }
80
+ if (intime[0] == null || intime[1] == null) {
81
+ intime = null;
82
+ }
83
+ copyParams = __assign(__assign({}, copyParams), (_e = {}, _e[toKeyItem] = intime, _e));
84
+ }
85
+ }
86
+ }
87
+ return copyParams;
88
+ }
89
+ function divide(num1, num2) {
90
+ var others = [];
91
+ for (var _i = 2; _i < arguments.length; _i++) {
92
+ others[_i - 2] = arguments[_i];
93
+ }
94
+ try {
95
+ return divide$1.apply(void 0, __spreadArray([num1, num2], others));
96
+ }
97
+ catch (err) {
98
+ console.log(err);
99
+ return 0;
100
+ }
101
+ }
102
+ /**
103
+ * @description 精确四舍五入后保留几位小数
104
+ */
105
+ function exactRound(num, ratio) {
106
+ var typeNum = typeof num;
107
+ if (typeNum !== 'number' && typeNum !== 'string') {
108
+ return num;
109
+ }
110
+ try {
111
+ return round(num, ratio).toFixed(ratio);
112
+ }
113
+ catch (err) {
114
+ console.error(err);
115
+ return num;
116
+ }
117
+ }
118
+ /**
119
+ * @description 添加千分符符号
120
+ */
121
+ function toThousand(num) {
122
+ var typeNum = typeof num;
123
+ if (typeNum !== 'number' && typeNum !== 'string') {
124
+ return num;
125
+ }
126
+ var str = (num + '').replace(/(\d{1,3})(?=(\d{3})+(?:$|\.))/g, '$1,');
127
+ return str;
128
+ }
129
+ /**
130
+ * @description 去除指定字符串
131
+ */
132
+ function clearAssignStr(str, originalStr) {
133
+ if (!originalStr) {
134
+ return originalStr;
135
+ }
136
+ if (originalStr.startsWith(str)) {
137
+ return originalStr.replace(str, '');
138
+ }
139
+ return originalStr;
140
+ }
141
+ /**
142
+ * @description 下载重命名
143
+ */
144
+ function loadFileRename(fileUrl, fileName) {
145
+ var xhr = new XMLHttpRequest();
146
+ xhr.open('GET', fileUrl, true);
147
+ xhr.responseType = 'blob';
148
+ xhr.onload = function () {
149
+ if (xhr.status === 200) {
150
+ var link = document.createElement('a');
151
+ var body = document.querySelector('body');
152
+ link.href = window.URL.createObjectURL(xhr.response);
153
+ link.download = fileName;
154
+ // fix Firefox
155
+ link.style.display = 'none';
156
+ body.appendChild(link);
157
+ link.click();
158
+ body.removeChild(link);
159
+ window.URL.revokeObjectURL(link.href);
160
+ }
161
+ };
162
+ xhr.send();
163
+ }
164
+ /**
165
+ * @description 文件大小提示转换
166
+ */
167
+ function transformFileSize(value) {
168
+ if (value < 1024) {
169
+ return round(value, 2).toFixed(2) + 'B';
170
+ }
171
+ else if (value < 1024 * 1024) {
172
+ return round(divide(value, 1024), 2).toFixed(2) + 'KB';
173
+ }
174
+ return round(divide(value, 1024, 1024), 2).toFixed(2) + 'MB';
175
+ }
176
+ /**
177
+ * @description 更具key判断前后值是否一致
178
+ */
179
+ function isEqualByKey(keys, record, preRecord) {
180
+ var isEqual = false; // 是否相等
181
+ if (!record || !preRecord) {
182
+ isEqual = true;
183
+ return isEqual;
184
+ }
185
+ // 如果数据源相同的话,那么判断是初次更改,应该更新
186
+ if (record === preRecord) {
187
+ isEqual = true;
188
+ return isEqual;
189
+ }
190
+ for (var i = 0; i < keys.length; i++) {
191
+ var key = keys[i];
192
+ if (record[key] !== preRecord[key]) {
193
+ isEqual = true;
194
+ break;
195
+ }
196
+ }
197
+ return isEqual;
198
+ }
199
+
200
+ var tools = /*#__PURE__*/Object.freeze({
201
+ __proto__: null,
202
+ timeTransfrom: timeTransfrom,
203
+ plus: plus,
204
+ minus: minus,
205
+ times: times,
206
+ divide: divide,
207
+ exactRound: exactRound,
208
+ toThousand: toThousand,
209
+ clearAssignStr: clearAssignStr,
210
+ loadFileRename: loadFileRename,
211
+ transformFileSize: transformFileSize,
212
+ isEqualByKey: isEqualByKey
213
+ });
214
+
215
+ export { timeTransfrom as a, toThousand as b, clearAssignStr as c, divide as d, exactRound as e, transformFileSize as f, isEqualByKey as i, loadFileRename as l, tools as t };
@@ -0,0 +1,209 @@
1
+ import { _ as __assign, a as __spreadArray } from './tslib.es6-b9033aad.js';
2
+ import dayjs from 'dayjs';
3
+ import { divide as divide$1, round, plus, minus, times } from 'number-precision';
4
+
5
+ /**
6
+ * @description 时间格式转换
7
+ */
8
+ function timeTransfrom(timeParams) {
9
+ var _a, _b, _c, _d, _e;
10
+ var params = timeParams.params, fromKey = timeParams.fromKey, toKey = timeParams.toKey, _f = timeParams.type, type = _f === void 0 ? 'string' : _f, format = timeParams.format;
11
+ var copyParams = __assign({}, params);
12
+ for (var i = 0; i < fromKey.length; i++) {
13
+ var fromKeyItem = fromKey[i];
14
+ var toKeyItem = toKey[i];
15
+ var formatItem = Array.isArray(format)
16
+ ? format[i]
17
+ : format
18
+ ? format
19
+ : 'YYYY-MM-DD';
20
+ // 从一个键转换成两个键
21
+ if (typeof fromKeyItem === 'string' && typeof toKeyItem === 'object') {
22
+ if (type === 'string' && copyParams[fromKeyItem]) {
23
+ var _g = copyParams[fromKeyItem], startMoment = _g[0], endMoment = _g[1];
24
+ var start = void 0, end = void 0;
25
+ if (dayjs.isDayjs(startMoment)) {
26
+ start = startMoment.format(formatItem);
27
+ }
28
+ if (dayjs.isDayjs(endMoment)) {
29
+ end = endMoment.format(formatItem);
30
+ }
31
+ if (formatItem === 'YYYY-MM-DD HH:mm:ss') {
32
+ start = start.substr(0, 10) + ' 00:00:00';
33
+ end = end.substr(0, 10) + ' 23:59:59';
34
+ }
35
+ delete copyParams[fromKeyItem];
36
+ copyParams = __assign(__assign({}, copyParams), (_a = {}, _a[toKeyItem[0]] = start, _a[toKeyItem[1]] = end, _a));
37
+ }
38
+ else {
39
+ copyParams = __assign(__assign({}, copyParams), (_b = {}, _b[toKeyItem[0]] = undefined, _b[toKeyItem[1]] = undefined, _b));
40
+ }
41
+ }
42
+ // 从一个键转换成一个键
43
+ if (typeof fromKeyItem === 'string' && typeof toKeyItem === 'string') {
44
+ if (type === 'string') {
45
+ var _dayjsObj = copyParams[fromKeyItem];
46
+ var start = void 0;
47
+ if (dayjs.isDayjs(_dayjsObj)) {
48
+ start = _dayjsObj.format(formatItem);
49
+ }
50
+ delete copyParams[fromKeyItem];
51
+ copyParams = __assign(__assign({}, copyParams), (_c = {}, _c[toKeyItem] = start, _c));
52
+ }
53
+ if (type === 'object') {
54
+ var start = copyParams[fromKeyItem]
55
+ ? dayjs(copyParams[fromKeyItem])
56
+ : undefined;
57
+ delete copyParams[fromKeyItem];
58
+ copyParams = __assign(__assign({}, copyParams), (_d = {}, _d[toKeyItem] = start, _d));
59
+ }
60
+ }
61
+ // 从两个键转换成一个键
62
+ if (typeof fromKeyItem === 'object' && typeof toKeyItem === 'string') {
63
+ if (type === 'object') {
64
+ var startMoment = fromKeyItem[0], endMoment = fromKeyItem[1];
65
+ var intime = copyParams[toKeyItem] || [null, null];
66
+ if (copyParams[startMoment]) {
67
+ intime[0] = dayjs(copyParams[startMoment]);
68
+ delete copyParams[startMoment];
69
+ }
70
+ if (copyParams[endMoment]) {
71
+ intime[1] = dayjs(copyParams[endMoment]);
72
+ delete copyParams[endMoment];
73
+ }
74
+ if (intime[0] == null || intime[1] == null) {
75
+ intime = null;
76
+ }
77
+ copyParams = __assign(__assign({}, copyParams), (_e = {}, _e[toKeyItem] = intime, _e));
78
+ }
79
+ }
80
+ }
81
+ return copyParams;
82
+ }
83
+ function divide(num1, num2) {
84
+ var others = [];
85
+ for (var _i = 2; _i < arguments.length; _i++) {
86
+ others[_i - 2] = arguments[_i];
87
+ }
88
+ try {
89
+ return divide$1.apply(void 0, __spreadArray([num1, num2], others));
90
+ }
91
+ catch (err) {
92
+ console.log(err);
93
+ return 0;
94
+ }
95
+ }
96
+ /**
97
+ * @description 精确四舍五入后保留几位小数
98
+ */
99
+ function exactRound(num, ratio) {
100
+ var typeNum = typeof num;
101
+ if (typeNum !== 'number' && typeNum !== 'string') {
102
+ return num;
103
+ }
104
+ try {
105
+ return round(num, ratio).toFixed(ratio);
106
+ }
107
+ catch (err) {
108
+ console.error(err);
109
+ return num;
110
+ }
111
+ }
112
+ /**
113
+ * @description 添加千分符符号
114
+ */
115
+ function toThousand(num) {
116
+ var typeNum = typeof num;
117
+ if (typeNum !== 'number' && typeNum !== 'string') {
118
+ return num;
119
+ }
120
+ var str = (num + '').replace(/(\d{1,3})(?=(\d{3})+(?:$|\.))/g, '$1,');
121
+ return str;
122
+ }
123
+ /**
124
+ * @description 去除指定字符串
125
+ */
126
+ function clearAssignStr(str, originalStr) {
127
+ if (!originalStr) {
128
+ return originalStr;
129
+ }
130
+ if (originalStr.startsWith(str)) {
131
+ return originalStr.replace(str, '');
132
+ }
133
+ return originalStr;
134
+ }
135
+ /**
136
+ * @description 下载重命名
137
+ */
138
+ function loadFileRename(fileUrl, fileName) {
139
+ var xhr = new XMLHttpRequest();
140
+ xhr.open('GET', fileUrl, true);
141
+ xhr.responseType = 'blob';
142
+ xhr.onload = function () {
143
+ if (xhr.status === 200) {
144
+ var link = document.createElement('a');
145
+ var body = document.querySelector('body');
146
+ link.href = window.URL.createObjectURL(xhr.response);
147
+ link.download = fileName;
148
+ // fix Firefox
149
+ link.style.display = 'none';
150
+ body.appendChild(link);
151
+ link.click();
152
+ body.removeChild(link);
153
+ window.URL.revokeObjectURL(link.href);
154
+ }
155
+ };
156
+ xhr.send();
157
+ }
158
+ /**
159
+ * @description 文件大小提示转换
160
+ */
161
+ function transformFileSize(value) {
162
+ if (value < 1024) {
163
+ return round(value, 2).toFixed(2) + 'B';
164
+ }
165
+ else if (value < 1024 * 1024) {
166
+ return round(divide(value, 1024), 2).toFixed(2) + 'KB';
167
+ }
168
+ return round(divide(value, 1024, 1024), 2).toFixed(2) + 'MB';
169
+ }
170
+ /**
171
+ * @description 更具key判断前后值是否一致
172
+ */
173
+ function isEqualByKey(keys, record, preRecord) {
174
+ var isEqual = false; // 是否相等
175
+ if (!record || !preRecord) {
176
+ isEqual = true;
177
+ return isEqual;
178
+ }
179
+ // 如果数据源相同的话,那么判断是初次更改,应该更新
180
+ if (record === preRecord) {
181
+ isEqual = true;
182
+ return isEqual;
183
+ }
184
+ for (var i = 0; i < keys.length; i++) {
185
+ var key = keys[i];
186
+ if (record[key] !== preRecord[key]) {
187
+ isEqual = true;
188
+ break;
189
+ }
190
+ }
191
+ return isEqual;
192
+ }
193
+
194
+ var tools = /*#__PURE__*/Object.freeze({
195
+ __proto__: null,
196
+ timeTransfrom: timeTransfrom,
197
+ plus: plus,
198
+ minus: minus,
199
+ times: times,
200
+ divide: divide,
201
+ exactRound: exactRound,
202
+ toThousand: toThousand,
203
+ clearAssignStr: clearAssignStr,
204
+ loadFileRename: loadFileRename,
205
+ transformFileSize: transformFileSize,
206
+ isEqualByKey: isEqualByKey
207
+ });
208
+
209
+ export { timeTransfrom as a, toThousand as b, clearAssignStr as c, divide as d, exactRound as e, transformFileSize as f, isEqualByKey as i, loadFileRename as l, tools as t };
package/dist/tools.js CHANGED
@@ -1,4 +1,4 @@
1
1
  import './tslib.es6-b9033aad.js';
2
2
  import 'dayjs';
3
3
  export { minus, plus, times } from 'number-precision';
4
- export { c as clearAssignStr, d as divide, e as exactRound, i as isEqualByKey, l as loadFileRename, a as timeTransfrom, b as toThousand, f as transformFileSize } from './tools-e1b35b23.js';
4
+ export { c as clearAssignStr, d as divide, e as exactRound, i as isEqualByKey, l as loadFileRename, a as timeTransfrom, b as toThousand, f as transformFileSize } from './tools-2876d65c.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ztxkutils",
3
- "version": "2.2.3",
3
+ "version": "2.2.7",
4
4
  "description": "",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",