ztxkutils 1.7.3 → 1.7.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/businessTools.d.ts +7 -0
- package/dist/businessTools.js +25 -0
- package/dist/fileOperation.d.ts +13 -0
- package/dist/fileOperation.js +35 -1
- package/dist/index.js +2 -2
- package/dist/tools-e073f57e.js +173 -0
- package/dist/tools.d.ts +0 -4
- package/dist/tools.js +1 -2
- package/package.json +1 -1
@@ -0,0 +1,25 @@
|
|
1
|
+
import { Modal } from 'ztxkui';
|
2
|
+
|
3
|
+
/**
|
4
|
+
* @description 当有依赖改变时,提示用户
|
5
|
+
*/
|
6
|
+
function openTipModal(callback, options) {
|
7
|
+
if (options && options.showModal) {
|
8
|
+
Modal.confirm({
|
9
|
+
content: options.tipTitle || '切换将清空已选数据!',
|
10
|
+
okText: '确认',
|
11
|
+
cancelText: '取消',
|
12
|
+
onCancel: function () {
|
13
|
+
callback && callback(false);
|
14
|
+
},
|
15
|
+
onOk: function () {
|
16
|
+
callback && callback(true);
|
17
|
+
},
|
18
|
+
});
|
19
|
+
}
|
20
|
+
else {
|
21
|
+
callback && callback(true);
|
22
|
+
}
|
23
|
+
}
|
24
|
+
|
25
|
+
export { openTipModal };
|
package/dist/fileOperation.d.ts
CHANGED
@@ -5,12 +5,25 @@
|
|
5
5
|
* @param {string} fileName 文件名
|
6
6
|
*/
|
7
7
|
export declare function downloadFile(apiUrl: string, fileId: string, fileName: string, authToken?: string): void;
|
8
|
+
/**
|
9
|
+
* @description 公共文件下载,并重命名
|
10
|
+
* @param {string} apiUrl api服务器ip端口
|
11
|
+
* @param {string} fileId 文件id
|
12
|
+
* @param {string} fileName 文件名
|
13
|
+
*/
|
14
|
+
export declare function downloadPublicFile(apiUrl: string, fileId: string, fileName: string): void;
|
8
15
|
/**
|
9
16
|
* @description 生成文件下载路径
|
10
17
|
* @param {string} apiUrl api服务器ip端口
|
11
18
|
* @param {string} fileId 文件id
|
12
19
|
*/
|
13
20
|
export declare function createDownloadUrl(apiUrl: string, fileId: string, authToken?: string): string;
|
21
|
+
/**
|
22
|
+
* @description 生成公共文件下载路径
|
23
|
+
* @param {string} apiUrl api服务器ip端口
|
24
|
+
* @param {string} fileId 文件id
|
25
|
+
*/
|
26
|
+
export declare function createPublicDownloadUrl(apiUrl: string, fileId: string): string;
|
14
27
|
/**
|
15
28
|
* @description 文件预览方法
|
16
29
|
* @param {string} fileUrl 文件服务器ip端口
|
package/dist/fileOperation.js
CHANGED
@@ -31,6 +31,32 @@ function downloadFile(apiUrl, fileId, fileName, authToken) {
|
|
31
31
|
};
|
32
32
|
xhr.send();
|
33
33
|
}
|
34
|
+
/**
|
35
|
+
* @description 公共文件下载,并重命名
|
36
|
+
* @param {string} apiUrl api服务器ip端口
|
37
|
+
* @param {string} fileId 文件id
|
38
|
+
* @param {string} fileName 文件名
|
39
|
+
*/
|
40
|
+
function downloadPublicFile(apiUrl, fileId, fileName) {
|
41
|
+
var xhr = new XMLHttpRequest();
|
42
|
+
xhr.open('GET', apiUrl + "/api/zmdms-resource/oss/endpoint/public/download-file/" + fileId, true);
|
43
|
+
xhr.responseType = 'blob';
|
44
|
+
xhr.onload = function () {
|
45
|
+
if (xhr.status === 200 || xhr.status === 201) {
|
46
|
+
var link = document.createElement('a');
|
47
|
+
var body = document.querySelector('body');
|
48
|
+
link.href = window.URL.createObjectURL(xhr.response);
|
49
|
+
link.download = fileName;
|
50
|
+
// fix Firefox
|
51
|
+
link.style.display = 'none';
|
52
|
+
body.appendChild(link);
|
53
|
+
link.click();
|
54
|
+
body.removeChild(link);
|
55
|
+
window.URL.revokeObjectURL(link.href);
|
56
|
+
}
|
57
|
+
};
|
58
|
+
xhr.send();
|
59
|
+
}
|
34
60
|
/**
|
35
61
|
* @description 生成文件下载路径
|
36
62
|
* @param {string} apiUrl api服务器ip端口
|
@@ -40,6 +66,14 @@ function createDownloadUrl(apiUrl, fileId, authToken) {
|
|
40
66
|
var token = getToken() || authToken;
|
41
67
|
return apiUrl + "/api/zmdms-resource/oss/endpoint/download-file/" + fileId + "?Zmdms-Auth=bearer " + token;
|
42
68
|
}
|
69
|
+
/**
|
70
|
+
* @description 生成公共文件下载路径
|
71
|
+
* @param {string} apiUrl api服务器ip端口
|
72
|
+
* @param {string} fileId 文件id
|
73
|
+
*/
|
74
|
+
function createPublicDownloadUrl(apiUrl, fileId) {
|
75
|
+
return apiUrl + "/api/zmdms-resource/oss/endpoint/public/download-file/" + fileId;
|
76
|
+
}
|
43
77
|
/**
|
44
78
|
* @description 文件预览方法
|
45
79
|
* @param {string} fileUrl 文件服务器ip端口
|
@@ -71,4 +105,4 @@ function createThumbnailUrl(apiUrl, fileId, scale, authToken) {
|
|
71
105
|
return apiUrl + "/api/zmdms-resource/oss/endpoint/thumbnail/" + fileId + "?scale=" + scale + "&Zmdms-Auth=bearer " + token;
|
72
106
|
}
|
73
107
|
|
74
|
-
export { createDownloadUrl, createOriginalUrl, createThumbnailUrl, downloadFile, previewFile };
|
108
|
+
export { createDownloadUrl, createOriginalUrl, createPublicDownloadUrl, createThumbnailUrl, downloadFile, downloadPublicFile, previewFile };
|
package/dist/index.js
CHANGED
@@ -1,11 +1,11 @@
|
|
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-e073f57e.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';
|
7
7
|
import './tslib.es6-b9033aad.js';
|
8
8
|
import 'dayjs';
|
9
9
|
import 'number-precision';
|
10
|
-
import 'ztxkui';
|
11
10
|
import 'axios';
|
11
|
+
import 'ztxkui';
|
@@ -0,0 +1,173 @@
|
|
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
|
+
var tools = /*#__PURE__*/Object.freeze({
|
160
|
+
__proto__: null,
|
161
|
+
timeTransfrom: timeTransfrom,
|
162
|
+
plus: plus,
|
163
|
+
minus: minus,
|
164
|
+
times: times,
|
165
|
+
divide: divide,
|
166
|
+
exactRound: exactRound,
|
167
|
+
toThousand: toThousand,
|
168
|
+
clearAssignStr: clearAssignStr,
|
169
|
+
loadFileRename: loadFileRename,
|
170
|
+
transformFileSize: transformFileSize
|
171
|
+
});
|
172
|
+
|
173
|
+
export { timeTransfrom as a, toThousand as b, clearAssignStr as c, divide as d, exactRound as e, transformFileSize as f, loadFileRename as l, tools as t };
|
package/dist/tools.d.ts
CHANGED
@@ -40,10 +40,6 @@ export declare function clearAssignStr(str: string, originalStr: string): string
|
|
40
40
|
* @description 下载重命名
|
41
41
|
*/
|
42
42
|
export declare function loadFileRename(fileUrl: any, fileName: any): void;
|
43
|
-
/**
|
44
|
-
* @description 当有依赖改变时,提示用户
|
45
|
-
*/
|
46
|
-
export declare function openTipModal(callback: (res: boolean) => void, data: any[], tipTitle?: string): void;
|
47
43
|
/**
|
48
44
|
* @description 文件大小提示转换
|
49
45
|
*/
|
package/dist/tools.js
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
import './tslib.es6-b9033aad.js';
|
2
2
|
import 'dayjs';
|
3
3
|
export { minus, plus, times } from 'number-precision';
|
4
|
-
|
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';
|
4
|
+
export { c as clearAssignStr, d as divide, e as exactRound, l as loadFileRename, a as timeTransfrom, b as toThousand, f as transformFileSize } from './tools-e073f57e.js';
|