ztxkutils 2.2.5 → 2.2.9

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.
@@ -1,197 +0,0 @@
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;
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
- // 从一个键转换成两个键
16
- if (typeof fromKeyItem === 'string' && typeof toKeyItem === 'object') {
17
- if (type === 'string' && copyParams[fromKeyItem]) {
18
- var _g = copyParams[fromKeyItem], startMoment = _g[0], endMoment = _g[1];
19
- var start = void 0, end = void 0;
20
- if (dayjs.isDayjs(startMoment)) {
21
- start = startMoment.format('YYYY-MM-DD');
22
- }
23
- if (dayjs.isDayjs(endMoment)) {
24
- end = endMoment.format('YYYY-MM-DD');
25
- }
26
- delete copyParams[fromKeyItem];
27
- copyParams = __assign(__assign({}, copyParams), (_a = {}, _a[toKeyItem[0]] = start, _a[toKeyItem[1]] = end, _a));
28
- }
29
- else {
30
- copyParams = __assign(__assign({}, copyParams), (_b = {}, _b[toKeyItem[0]] = undefined, _b[toKeyItem[1]] = undefined, _b));
31
- }
32
- }
33
- // 从一个键转换成一个键
34
- if (typeof fromKeyItem === 'string' && typeof toKeyItem === 'string') {
35
- if (type === 'string') {
36
- var _dayjsObj = copyParams[fromKeyItem];
37
- var start = void 0;
38
- if (dayjs.isDayjs(_dayjsObj)) {
39
- start = _dayjsObj.format('YYYY-MM-DD');
40
- }
41
- delete copyParams[fromKeyItem];
42
- copyParams = __assign(__assign({}, copyParams), (_c = {}, _c[toKeyItem] = start, _c));
43
- }
44
- if (type === 'object') {
45
- var start = copyParams[fromKeyItem]
46
- ? dayjs(copyParams[fromKeyItem])
47
- : undefined;
48
- delete copyParams[fromKeyItem];
49
- copyParams = __assign(__assign({}, copyParams), (_d = {}, _d[toKeyItem] = start, _d));
50
- }
51
- }
52
- // 从两个键转换成一个键
53
- if (typeof fromKeyItem === 'object' && typeof toKeyItem === 'string') {
54
- if (type === 'object') {
55
- var startMoment = fromKeyItem[0], endMoment = fromKeyItem[1];
56
- var intime = copyParams[toKeyItem] || [null, null];
57
- if (copyParams[startMoment]) {
58
- intime[0] = dayjs(copyParams[startMoment]);
59
- delete copyParams[startMoment];
60
- }
61
- if (copyParams[endMoment]) {
62
- intime[1] = dayjs(copyParams[endMoment]);
63
- delete copyParams[endMoment];
64
- }
65
- copyParams = __assign(__assign({}, copyParams), (_e = {}, _e[toKeyItem] = intime, _e));
66
- }
67
- }
68
- }
69
- return copyParams;
70
- }
71
- function divide(num1, num2) {
72
- var others = [];
73
- for (var _i = 2; _i < arguments.length; _i++) {
74
- others[_i - 2] = arguments[_i];
75
- }
76
- try {
77
- return divide$1.apply(void 0, __spreadArray([num1, num2], others));
78
- }
79
- catch (err) {
80
- console.log(err);
81
- return 0;
82
- }
83
- }
84
- /**
85
- * @description 精确四舍五入后保留几位小数
86
- */
87
- function exactRound(num, ratio) {
88
- var typeNum = typeof num;
89
- if (typeNum !== 'number' && typeNum !== 'string') {
90
- return num;
91
- }
92
- try {
93
- return round(num, ratio).toFixed(ratio);
94
- }
95
- catch (err) {
96
- console.error(err);
97
- return num;
98
- }
99
- }
100
- /**
101
- * @description 添加千分符符号
102
- */
103
- function toThousand(num) {
104
- var typeNum = typeof num;
105
- if (typeNum !== 'number' && typeNum !== 'string') {
106
- return num;
107
- }
108
- var str = (num + '').replace(/(\d{1,3})(?=(\d{3})+(?:$|\.))/g, '$1,');
109
- return str;
110
- }
111
- /**
112
- * @description 去除指定字符串
113
- */
114
- function clearAssignStr(str, originalStr) {
115
- if (!originalStr) {
116
- return originalStr;
117
- }
118
- if (originalStr.startsWith(str)) {
119
- return originalStr.replace(str, '');
120
- }
121
- return originalStr;
122
- }
123
- /**
124
- * @description 下载重命名
125
- */
126
- function loadFileRename(fileUrl, fileName) {
127
- var xhr = new XMLHttpRequest();
128
- xhr.open('GET', fileUrl, true);
129
- xhr.responseType = 'blob';
130
- xhr.onload = function () {
131
- if (xhr.status === 200) {
132
- var link = document.createElement('a');
133
- var body = document.querySelector('body');
134
- link.href = window.URL.createObjectURL(xhr.response);
135
- link.download = fileName;
136
- // fix Firefox
137
- link.style.display = 'none';
138
- body.appendChild(link);
139
- link.click();
140
- body.removeChild(link);
141
- window.URL.revokeObjectURL(link.href);
142
- }
143
- };
144
- xhr.send();
145
- }
146
- /**
147
- * @description 文件大小提示转换
148
- */
149
- function transformFileSize(value) {
150
- if (value < 1024) {
151
- return round(value, 2).toFixed(2) + 'B';
152
- }
153
- else if (value < 1024 * 1024) {
154
- return round(divide(value, 1024), 2).toFixed(2) + 'KB';
155
- }
156
- return round(divide(value, 1024, 1024), 2).toFixed(2) + 'MB';
157
- }
158
- /**
159
- * @description 更具key判断前后值是否一致
160
- */
161
- function isEqualByKey(keys, record, preRecord) {
162
- var isEqual = false; // 是否相等
163
- if (!record || !preRecord) {
164
- isEqual = true;
165
- return isEqual;
166
- }
167
- // 如果数据源相同的话,那么判断是初次更改,应该更新
168
- if (record === preRecord) {
169
- isEqual = true;
170
- return isEqual;
171
- }
172
- for (var i = 0; i < keys.length; i++) {
173
- var key = keys[i];
174
- if (record[key] !== preRecord[key]) {
175
- isEqual = true;
176
- break;
177
- }
178
- }
179
- return isEqual;
180
- }
181
-
182
- var tools = /*#__PURE__*/Object.freeze({
183
- __proto__: null,
184
- timeTransfrom: timeTransfrom,
185
- plus: plus,
186
- minus: minus,
187
- times: times,
188
- divide: divide,
189
- exactRound: exactRound,
190
- toThousand: toThousand,
191
- clearAssignStr: clearAssignStr,
192
- loadFileRename: loadFileRename,
193
- transformFileSize: transformFileSize,
194
- isEqualByKey: isEqualByKey
195
- });
196
-
197
- 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 };
@@ -1,209 +0,0 @@
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 };
@@ -1,205 +0,0 @@
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
- delete copyParams[fromKeyItem];
32
- copyParams = __assign(__assign({}, copyParams), (_a = {}, _a[toKeyItem[0]] = start, _a[toKeyItem[1]] = end, _a));
33
- }
34
- else {
35
- copyParams = __assign(__assign({}, copyParams), (_b = {}, _b[toKeyItem[0]] = undefined, _b[toKeyItem[1]] = undefined, _b));
36
- }
37
- }
38
- // 从一个键转换成一个键
39
- if (typeof fromKeyItem === 'string' && typeof toKeyItem === 'string') {
40
- if (type === 'string') {
41
- var _dayjsObj = copyParams[fromKeyItem];
42
- var start = void 0;
43
- if (dayjs.isDayjs(_dayjsObj)) {
44
- start = _dayjsObj.format(formatItem);
45
- }
46
- delete copyParams[fromKeyItem];
47
- copyParams = __assign(__assign({}, copyParams), (_c = {}, _c[toKeyItem] = start, _c));
48
- }
49
- if (type === 'object') {
50
- var start = copyParams[fromKeyItem]
51
- ? dayjs(copyParams[fromKeyItem])
52
- : undefined;
53
- delete copyParams[fromKeyItem];
54
- copyParams = __assign(__assign({}, copyParams), (_d = {}, _d[toKeyItem] = start, _d));
55
- }
56
- }
57
- // 从两个键转换成一个键
58
- if (typeof fromKeyItem === 'object' && typeof toKeyItem === 'string') {
59
- if (type === 'object') {
60
- var startMoment = fromKeyItem[0], endMoment = fromKeyItem[1];
61
- var intime = copyParams[toKeyItem] || [null, null];
62
- if (copyParams[startMoment]) {
63
- intime[0] = dayjs(copyParams[startMoment]);
64
- delete copyParams[startMoment];
65
- }
66
- if (copyParams[endMoment]) {
67
- intime[1] = dayjs(copyParams[endMoment]);
68
- delete copyParams[endMoment];
69
- }
70
- if (intime[0] == null || intime[1] == null) {
71
- intime = null;
72
- }
73
- copyParams = __assign(__assign({}, copyParams), (_e = {}, _e[toKeyItem] = intime, _e));
74
- }
75
- }
76
- }
77
- return copyParams;
78
- }
79
- function divide(num1, num2) {
80
- var others = [];
81
- for (var _i = 2; _i < arguments.length; _i++) {
82
- others[_i - 2] = arguments[_i];
83
- }
84
- try {
85
- return divide$1.apply(void 0, __spreadArray([num1, num2], others));
86
- }
87
- catch (err) {
88
- console.log(err);
89
- return 0;
90
- }
91
- }
92
- /**
93
- * @description 精确四舍五入后保留几位小数
94
- */
95
- function exactRound(num, ratio) {
96
- var typeNum = typeof num;
97
- if (typeNum !== 'number' && typeNum !== 'string') {
98
- return num;
99
- }
100
- try {
101
- return round(num, ratio).toFixed(ratio);
102
- }
103
- catch (err) {
104
- console.error(err);
105
- return num;
106
- }
107
- }
108
- /**
109
- * @description 添加千分符符号
110
- */
111
- function toThousand(num) {
112
- var typeNum = typeof num;
113
- if (typeNum !== 'number' && typeNum !== 'string') {
114
- return num;
115
- }
116
- var str = (num + '').replace(/(\d{1,3})(?=(\d{3})+(?:$|\.))/g, '$1,');
117
- return str;
118
- }
119
- /**
120
- * @description 去除指定字符串
121
- */
122
- function clearAssignStr(str, originalStr) {
123
- if (!originalStr) {
124
- return originalStr;
125
- }
126
- if (originalStr.startsWith(str)) {
127
- return originalStr.replace(str, '');
128
- }
129
- return originalStr;
130
- }
131
- /**
132
- * @description 下载重命名
133
- */
134
- function loadFileRename(fileUrl, fileName) {
135
- var xhr = new XMLHttpRequest();
136
- xhr.open('GET', fileUrl, true);
137
- xhr.responseType = 'blob';
138
- xhr.onload = function () {
139
- if (xhr.status === 200) {
140
- var link = document.createElement('a');
141
- var body = document.querySelector('body');
142
- link.href = window.URL.createObjectURL(xhr.response);
143
- link.download = fileName;
144
- // fix Firefox
145
- link.style.display = 'none';
146
- body.appendChild(link);
147
- link.click();
148
- body.removeChild(link);
149
- window.URL.revokeObjectURL(link.href);
150
- }
151
- };
152
- xhr.send();
153
- }
154
- /**
155
- * @description 文件大小提示转换
156
- */
157
- function transformFileSize(value) {
158
- if (value < 1024) {
159
- return round(value, 2).toFixed(2) + 'B';
160
- }
161
- else if (value < 1024 * 1024) {
162
- return round(divide(value, 1024), 2).toFixed(2) + 'KB';
163
- }
164
- return round(divide(value, 1024, 1024), 2).toFixed(2) + 'MB';
165
- }
166
- /**
167
- * @description 更具key判断前后值是否一致
168
- */
169
- function isEqualByKey(keys, record, preRecord) {
170
- var isEqual = false; // 是否相等
171
- if (!record || !preRecord) {
172
- isEqual = true;
173
- return isEqual;
174
- }
175
- // 如果数据源相同的话,那么判断是初次更改,应该更新
176
- if (record === preRecord) {
177
- isEqual = true;
178
- return isEqual;
179
- }
180
- for (var i = 0; i < keys.length; i++) {
181
- var key = keys[i];
182
- if (record[key] !== preRecord[key]) {
183
- isEqual = true;
184
- break;
185
- }
186
- }
187
- return isEqual;
188
- }
189
-
190
- var tools = /*#__PURE__*/Object.freeze({
191
- __proto__: null,
192
- timeTransfrom: timeTransfrom,
193
- plus: plus,
194
- minus: minus,
195
- times: times,
196
- divide: divide,
197
- exactRound: exactRound,
198
- toThousand: toThousand,
199
- clearAssignStr: clearAssignStr,
200
- loadFileRename: loadFileRename,
201
- transformFileSize: transformFileSize,
202
- isEqualByKey: isEqualByKey
203
- });
204
-
205
- 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 };