ztxkutils 1.7.3 → 1.7.4

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.
@@ -0,0 +1,4 @@
1
+ /**
2
+ * @description 当有依赖改变时,提示用户
3
+ */
4
+ export declare function openTipModal(callback: (res: boolean) => void, data: any[], tipTitle?: string): void;
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-b75fec50.js';
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
- 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, 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';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ztxkutils",
3
- "version": "1.7.3",
3
+ "version": "1.7.4",
4
4
  "description": "",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",