ztxkutils 1.6.9 → 1.7.3

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/request.js CHANGED
@@ -1,5 +1,5 @@
1
- import './tslib.es6-79a6072b.js';
1
+ import './tslib.es6-b9033aad.js';
2
2
  import 'axios';
3
3
  import 'ztxkui';
4
- export { a as default } from './request-7944ad16.js';
4
+ export { a as default } from './request-eff26459.js';
5
5
  import './authority-17b7fde2.js';
@@ -0,0 +1,183 @@
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
+ import { Modal } from 'ztxkui';
5
+
6
+ /**
7
+ * @description 时间格式转换
8
+ */
9
+ function timeTransfrom(timeParams) {
10
+ var _a, _b, _c, _d, _e;
11
+ var params = timeParams.params, fromKey = timeParams.fromKey, toKey = timeParams.toKey, _f = timeParams.type, type = _f === void 0 ? 'string' : _f;
12
+ var copyParams = __assign({}, params);
13
+ for (var i = 0; i < fromKey.length; i++) {
14
+ var fromKeyItem = fromKey[i];
15
+ var toKeyItem = toKey[i];
16
+ // 从一个键转换成两个键
17
+ if (typeof fromKeyItem === 'string' && typeof toKeyItem === 'object') {
18
+ if (type === 'string' && copyParams[fromKeyItem]) {
19
+ var _g = copyParams[fromKeyItem], startMoment = _g[0], endMoment = _g[1];
20
+ var start = void 0, end = void 0;
21
+ if (dayjs.isDayjs(startMoment)) {
22
+ start = startMoment.format('YYYY-MM-DD');
23
+ }
24
+ if (dayjs.isDayjs(endMoment)) {
25
+ end = endMoment.format('YYYY-MM-DD');
26
+ }
27
+ delete copyParams[fromKeyItem];
28
+ copyParams = __assign(__assign({}, copyParams), (_a = {}, _a[toKeyItem[0]] = start, _a[toKeyItem[1]] = end, _a));
29
+ }
30
+ else {
31
+ copyParams = __assign(__assign({}, copyParams), (_b = {}, _b[toKeyItem[0]] = undefined, _b[toKeyItem[1]] = undefined, _b));
32
+ }
33
+ }
34
+ // 从一个键转换成一个键
35
+ if (typeof fromKeyItem === 'string' && typeof toKeyItem === 'string') {
36
+ if (type === 'string') {
37
+ var _dayjsObj = copyParams[fromKeyItem];
38
+ var start = void 0;
39
+ if (dayjs.isDayjs(_dayjsObj)) {
40
+ start = _dayjsObj.format('YYYY-MM-DD');
41
+ }
42
+ delete copyParams[fromKeyItem];
43
+ copyParams = __assign(__assign({}, copyParams), (_c = {}, _c[toKeyItem] = start, _c));
44
+ }
45
+ if (type === 'object') {
46
+ var start = copyParams[fromKeyItem]
47
+ ? dayjs(copyParams[fromKeyItem])
48
+ : undefined;
49
+ delete copyParams[fromKeyItem];
50
+ copyParams = __assign(__assign({}, copyParams), (_d = {}, _d[toKeyItem] = start, _d));
51
+ }
52
+ }
53
+ // 从两个键转换成一个键
54
+ if (typeof fromKeyItem === 'object' && typeof toKeyItem === 'string') {
55
+ if (type === 'object') {
56
+ var startMoment = fromKeyItem[0], endMoment = fromKeyItem[1];
57
+ var intime = copyParams[toKeyItem] || [null, null];
58
+ if (copyParams[startMoment]) {
59
+ intime[0] = dayjs(copyParams[startMoment]);
60
+ delete copyParams[startMoment];
61
+ }
62
+ if (copyParams[endMoment]) {
63
+ intime[1] = dayjs(copyParams[endMoment]);
64
+ delete copyParams[endMoment];
65
+ }
66
+ copyParams = __assign(__assign({}, copyParams), (_e = {}, _e[toKeyItem] = intime, _e));
67
+ }
68
+ }
69
+ }
70
+ return copyParams;
71
+ }
72
+ function divide(num1, num2) {
73
+ var others = [];
74
+ for (var _i = 2; _i < arguments.length; _i++) {
75
+ others[_i - 2] = arguments[_i];
76
+ }
77
+ try {
78
+ return divide$1.apply(void 0, __spreadArray([num1, num2], others));
79
+ }
80
+ catch (err) {
81
+ console.log(err);
82
+ return 0;
83
+ }
84
+ }
85
+ /**
86
+ * @description 精确四舍五入后保留几位小数
87
+ */
88
+ function exactRound(num, ratio) {
89
+ var typeNum = typeof num;
90
+ if (typeNum !== 'number' && typeNum !== 'string') {
91
+ return num;
92
+ }
93
+ try {
94
+ return round(num, ratio).toFixed(ratio);
95
+ }
96
+ catch (err) {
97
+ console.error(err);
98
+ return num;
99
+ }
100
+ }
101
+ /**
102
+ * @description 添加千分符符号
103
+ */
104
+ function toThousand(num) {
105
+ var typeNum = typeof num;
106
+ if (typeNum !== 'number' && typeNum !== 'string') {
107
+ return num;
108
+ }
109
+ var str = (num + '').replace(/(\d{1,3})(?=(\d{3})+(?:$|\.))/g, '$1,');
110
+ return str;
111
+ }
112
+ /**
113
+ * @description 去除指定字符串
114
+ */
115
+ function clearAssignStr(str, originalStr) {
116
+ if (!originalStr) {
117
+ return originalStr;
118
+ }
119
+ if (originalStr.startsWith(str)) {
120
+ return originalStr.replace(str, '');
121
+ }
122
+ return originalStr;
123
+ }
124
+ /**
125
+ * @description 下载重命名
126
+ */
127
+ function loadFileRename(fileUrl, fileName) {
128
+ var xhr = new XMLHttpRequest();
129
+ xhr.open('GET', fileUrl, true);
130
+ xhr.responseType = 'blob';
131
+ xhr.onload = function () {
132
+ if (xhr.status === 200) {
133
+ var link = document.createElement('a');
134
+ var body = document.querySelector('body');
135
+ link.href = window.URL.createObjectURL(xhr.response);
136
+ link.download = fileName;
137
+ // fix Firefox
138
+ link.style.display = 'none';
139
+ body.appendChild(link);
140
+ link.click();
141
+ body.removeChild(link);
142
+ window.URL.revokeObjectURL(link.href);
143
+ }
144
+ };
145
+ xhr.send();
146
+ }
147
+ /**
148
+ * @description 当有依赖改变时,提示用户
149
+ */
150
+ function openTipModal(callback, data, tipTitle) {
151
+ if (Array.isArray(data) && data.length > 0) {
152
+ Modal.confirm({
153
+ content: tipTitle || '切换将清空已选数据!',
154
+ okText: '确认',
155
+ cancelText: '取消',
156
+ onCancel: function () {
157
+ callback && callback(false);
158
+ },
159
+ onOk: function () {
160
+ callback && callback(true);
161
+ },
162
+ });
163
+ }
164
+ else {
165
+ callback && callback(true);
166
+ }
167
+ }
168
+
169
+ var tools = /*#__PURE__*/Object.freeze({
170
+ __proto__: null,
171
+ timeTransfrom: timeTransfrom,
172
+ plus: plus,
173
+ minus: minus,
174
+ times: times,
175
+ divide: divide,
176
+ exactRound: exactRound,
177
+ toThousand: toThousand,
178
+ clearAssignStr: clearAssignStr,
179
+ loadFileRename: loadFileRename,
180
+ openTipModal: openTipModal
181
+ });
182
+
183
+ export { timeTransfrom as a, toThousand as b, clearAssignStr as c, divide as d, exactRound as e, loadFileRename as l, openTipModal as o, tools as t };
@@ -0,0 +1,196 @@
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
+ import { Modal } from 'ztxkui';
5
+
6
+ /**
7
+ * @description 时间格式转换
8
+ */
9
+ function timeTransfrom(timeParams) {
10
+ var _a, _b, _c, _d, _e;
11
+ var params = timeParams.params, fromKey = timeParams.fromKey, toKey = timeParams.toKey, _f = timeParams.type, type = _f === void 0 ? 'string' : _f;
12
+ var copyParams = __assign({}, params);
13
+ for (var i = 0; i < fromKey.length; i++) {
14
+ var fromKeyItem = fromKey[i];
15
+ var toKeyItem = toKey[i];
16
+ // 从一个键转换成两个键
17
+ if (typeof fromKeyItem === 'string' && typeof toKeyItem === 'object') {
18
+ if (type === 'string' && copyParams[fromKeyItem]) {
19
+ var _g = copyParams[fromKeyItem], startMoment = _g[0], endMoment = _g[1];
20
+ var start = void 0, end = void 0;
21
+ if (dayjs.isDayjs(startMoment)) {
22
+ start = startMoment.format('YYYY-MM-DD');
23
+ }
24
+ if (dayjs.isDayjs(endMoment)) {
25
+ end = endMoment.format('YYYY-MM-DD');
26
+ }
27
+ delete copyParams[fromKeyItem];
28
+ copyParams = __assign(__assign({}, copyParams), (_a = {}, _a[toKeyItem[0]] = start, _a[toKeyItem[1]] = end, _a));
29
+ }
30
+ else {
31
+ copyParams = __assign(__assign({}, copyParams), (_b = {}, _b[toKeyItem[0]] = undefined, _b[toKeyItem[1]] = undefined, _b));
32
+ }
33
+ }
34
+ // 从一个键转换成一个键
35
+ if (typeof fromKeyItem === 'string' && typeof toKeyItem === 'string') {
36
+ if (type === 'string') {
37
+ var _dayjsObj = copyParams[fromKeyItem];
38
+ var start = void 0;
39
+ if (dayjs.isDayjs(_dayjsObj)) {
40
+ start = _dayjsObj.format('YYYY-MM-DD');
41
+ }
42
+ delete copyParams[fromKeyItem];
43
+ copyParams = __assign(__assign({}, copyParams), (_c = {}, _c[toKeyItem] = start, _c));
44
+ }
45
+ if (type === 'object') {
46
+ var start = copyParams[fromKeyItem]
47
+ ? dayjs(copyParams[fromKeyItem])
48
+ : undefined;
49
+ delete copyParams[fromKeyItem];
50
+ copyParams = __assign(__assign({}, copyParams), (_d = {}, _d[toKeyItem] = start, _d));
51
+ }
52
+ }
53
+ // 从两个键转换成一个键
54
+ if (typeof fromKeyItem === 'object' && typeof toKeyItem === 'string') {
55
+ if (type === 'object') {
56
+ var startMoment = fromKeyItem[0], endMoment = fromKeyItem[1];
57
+ var intime = copyParams[toKeyItem] || [null, null];
58
+ if (copyParams[startMoment]) {
59
+ intime[0] = dayjs(copyParams[startMoment]);
60
+ delete copyParams[startMoment];
61
+ }
62
+ if (copyParams[endMoment]) {
63
+ intime[1] = dayjs(copyParams[endMoment]);
64
+ delete copyParams[endMoment];
65
+ }
66
+ copyParams = __assign(__assign({}, copyParams), (_e = {}, _e[toKeyItem] = intime, _e));
67
+ }
68
+ }
69
+ }
70
+ return copyParams;
71
+ }
72
+ function divide(num1, num2) {
73
+ var others = [];
74
+ for (var _i = 2; _i < arguments.length; _i++) {
75
+ others[_i - 2] = arguments[_i];
76
+ }
77
+ try {
78
+ return divide$1.apply(void 0, __spreadArray([num1, num2], others));
79
+ }
80
+ catch (err) {
81
+ console.log(err);
82
+ return 0;
83
+ }
84
+ }
85
+ /**
86
+ * @description 精确四舍五入后保留几位小数
87
+ */
88
+ function exactRound(num, ratio) {
89
+ var typeNum = typeof num;
90
+ if (typeNum !== 'number' && typeNum !== 'string') {
91
+ return num;
92
+ }
93
+ try {
94
+ return round(num, ratio).toFixed(ratio);
95
+ }
96
+ catch (err) {
97
+ console.error(err);
98
+ return num;
99
+ }
100
+ }
101
+ /**
102
+ * @description 添加千分符符号
103
+ */
104
+ function toThousand(num) {
105
+ var typeNum = typeof num;
106
+ if (typeNum !== 'number' && typeNum !== 'string') {
107
+ return num;
108
+ }
109
+ var str = (num + '').replace(/(\d{1,3})(?=(\d{3})+(?:$|\.))/g, '$1,');
110
+ return str;
111
+ }
112
+ /**
113
+ * @description 去除指定字符串
114
+ */
115
+ function clearAssignStr(str, originalStr) {
116
+ if (!originalStr) {
117
+ return originalStr;
118
+ }
119
+ if (originalStr.startsWith(str)) {
120
+ return originalStr.replace(str, '');
121
+ }
122
+ return originalStr;
123
+ }
124
+ /**
125
+ * @description 下载重命名
126
+ */
127
+ function loadFileRename(fileUrl, fileName) {
128
+ var xhr = new XMLHttpRequest();
129
+ xhr.open('GET', fileUrl, true);
130
+ xhr.responseType = 'blob';
131
+ xhr.onload = function () {
132
+ if (xhr.status === 200) {
133
+ var link = document.createElement('a');
134
+ var body = document.querySelector('body');
135
+ link.href = window.URL.createObjectURL(xhr.response);
136
+ link.download = fileName;
137
+ // fix Firefox
138
+ link.style.display = 'none';
139
+ body.appendChild(link);
140
+ link.click();
141
+ body.removeChild(link);
142
+ window.URL.revokeObjectURL(link.href);
143
+ }
144
+ };
145
+ xhr.send();
146
+ }
147
+ /**
148
+ * @description 当有依赖改变时,提示用户
149
+ */
150
+ function openTipModal(callback, data, tipTitle) {
151
+ if (Array.isArray(data) && data.length > 0) {
152
+ Modal.confirm({
153
+ content: tipTitle || '切换将清空已选数据!',
154
+ okText: '确认',
155
+ cancelText: '取消',
156
+ onCancel: function () {
157
+ callback && callback(false);
158
+ },
159
+ onOk: function () {
160
+ callback && callback(true);
161
+ },
162
+ });
163
+ }
164
+ else {
165
+ callback && callback(true);
166
+ }
167
+ }
168
+ /**
169
+ * @description 文件大小提示转换
170
+ */
171
+ function transformFileSize(value) {
172
+ if (value < 1024) {
173
+ return round(value, 2).toFixed(2) + 'B';
174
+ }
175
+ else if (value < 1024 * 1024) {
176
+ return round(divide(value, 1024), 2).toFixed(2) + 'KB';
177
+ }
178
+ return round(divide(value, 1024, 1024), 2).toFixed(2) + 'MB';
179
+ }
180
+
181
+ var tools = /*#__PURE__*/Object.freeze({
182
+ __proto__: null,
183
+ timeTransfrom: timeTransfrom,
184
+ plus: plus,
185
+ minus: minus,
186
+ times: times,
187
+ divide: divide,
188
+ exactRound: exactRound,
189
+ toThousand: toThousand,
190
+ clearAssignStr: clearAssignStr,
191
+ loadFileRename: loadFileRename,
192
+ openTipModal: openTipModal,
193
+ transformFileSize: transformFileSize
194
+ });
195
+
196
+ export { timeTransfrom as a, toThousand as b, clearAssignStr as c, divide as d, exactRound as e, transformFileSize as f, loadFileRename as l, openTipModal as o, tools as t };
package/dist/tools.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { plus, minus, times, divide } from 'number-precision';
1
+ import { plus, minus, times } from 'number-precision';
2
2
  /**
3
3
  * @description 常用工具方法
4
4
  * 跟业务无关的一些方法可以放在这个文件里面
@@ -21,7 +21,9 @@ export declare function timeTransfrom(timeParams: ITimeTransfrom): any;
21
21
  * @description 四则运算
22
22
  * 加、减、乘、除
23
23
  */
24
- export { plus, minus, times, divide };
24
+ export { plus, minus, times };
25
+ declare type numType = number | string;
26
+ export declare function divide(num1: numType, num2: numType, ...others: numType[]): number;
25
27
  /**
26
28
  * @description 精确四舍五入后保留几位小数
27
29
  */
@@ -42,3 +44,7 @@ export declare function loadFileRename(fileUrl: any, fileName: any): void;
42
44
  * @description 当有依赖改变时,提示用户
43
45
  */
44
46
  export declare function openTipModal(callback: (res: boolean) => void, data: any[], tipTitle?: string): void;
47
+ /**
48
+ * @description 文件大小提示转换
49
+ */
50
+ export declare function transformFileSize(value: number): string;
package/dist/tools.js CHANGED
@@ -1,5 +1,5 @@
1
- import './tslib.es6-79a6072b.js';
1
+ import './tslib.es6-b9033aad.js';
2
2
  import 'dayjs';
3
- export { divide, minus, plus, times } from 'number-precision';
3
+ export { minus, plus, times } from 'number-precision';
4
4
  import 'ztxkui';
5
- export { c as clearAssignStr, e as exactRound, l as loadFileRename, o as openTipModal, a as timeTransfrom, b as toThousand } from './tools-d11ca423.js';
5
+ export { c as clearAssignStr, d as divide, e as exactRound, l as loadFileRename, o as openTipModal, a as timeTransfrom, b as toThousand, f as transformFileSize } from './tools-b75fec50.js';
@@ -0,0 +1,71 @@
1
+ /*! *****************************************************************************
2
+ Copyright (c) Microsoft Corporation.
3
+
4
+ Permission to use, copy, modify, and/or distribute this software for any
5
+ purpose with or without fee is hereby granted.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
8
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
9
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
10
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
11
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
12
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
13
+ PERFORMANCE OF THIS SOFTWARE.
14
+ ***************************************************************************** */
15
+
16
+ var __assign = function() {
17
+ __assign = Object.assign || function __assign(t) {
18
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
19
+ s = arguments[i];
20
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
21
+ }
22
+ return t;
23
+ };
24
+ return __assign.apply(this, arguments);
25
+ };
26
+
27
+ function __awaiter(thisArg, _arguments, P, generator) {
28
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
29
+ return new (P || (P = Promise))(function (resolve, reject) {
30
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
31
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
32
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
33
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
34
+ });
35
+ }
36
+
37
+ function __generator(thisArg, body) {
38
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
39
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
40
+ function verb(n) { return function (v) { return step([n, v]); }; }
41
+ function step(op) {
42
+ if (f) throw new TypeError("Generator is already executing.");
43
+ while (_) try {
44
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
45
+ if (y = 0, t) op = [op[0] & 2, t.value];
46
+ switch (op[0]) {
47
+ case 0: case 1: t = op; break;
48
+ case 4: _.label++; return { value: op[1], done: false };
49
+ case 5: _.label++; y = op[1]; op = [0]; continue;
50
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
51
+ default:
52
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
53
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
54
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
55
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
56
+ if (t[2]) _.ops.pop();
57
+ _.trys.pop(); continue;
58
+ }
59
+ op = body.call(thisArg, _);
60
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
61
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
62
+ }
63
+ }
64
+
65
+ function __spreadArray(to, from) {
66
+ for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
67
+ to[j] = from[i];
68
+ return to;
69
+ }
70
+
71
+ export { __assign as _, __spreadArray as a, __awaiter as b, __generator as c };