ztxkutils 1.7.2 → 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/index.js +1 -1
- package/dist/tools-b75fec50.js +196 -0
- package/dist/tools.d.ts +4 -0
- package/dist/tools.js +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
@@ -1,6 +1,6 @@
|
|
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-
|
3
|
+
export { t as tools } from './tools-b75fec50.js';
|
4
4
|
export { v as validate } from './validate-ecddae1d.js';
|
5
5
|
export { r as request } from './request-eff26459.js';
|
6
6
|
export { r as reqUrl } from './reqUrl-198b3d35.js';
|
@@ -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
@@ -44,3 +44,7 @@ export declare function loadFileRename(fileUrl: any, fileName: any): void;
|
|
44
44
|
* @description 当有依赖改变时,提示用户
|
45
45
|
*/
|
46
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
@@ -2,4 +2,4 @@ import './tslib.es6-b9033aad.js';
|
|
2
2
|
import 'dayjs';
|
3
3
|
export { minus, plus, times } from 'number-precision';
|
4
4
|
import 'ztxkui';
|
5
|
-
export { c as clearAssignStr, d as divide, e as exactRound, l as loadFileRename, o as openTipModal, a as timeTransfrom, b as toThousand } from './tools-
|
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';
|