ztxkutils 1.6.8 → 1.6.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.
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-3340e70f.js';
3
+ export { t as tools } from './tools-d11ca423.js';
4
4
  export { v as validate } from './validate-f3423df5.js';
5
5
  export { r as request } from './request-7944ad16.js';
6
6
  export { r as reqUrl } from './reqUrl-198b3d35.js';
7
7
  import './tslib.es6-79a6072b.js';
8
8
  import 'dayjs';
9
9
  import 'number-precision';
10
- import 'axios';
11
10
  import 'ztxkui';
11
+ import 'axios';
@@ -0,0 +1,170 @@
1
+ import { _ as __assign } from './tslib.es6-79a6072b.js';
2
+ import dayjs from 'dayjs';
3
+ import { round, plus, minus, times, divide } 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
+ /**
73
+ * @description 精确四舍五入后保留几位小数
74
+ */
75
+ function exactRound(num, ratio) {
76
+ var typeNum = typeof num;
77
+ if (typeNum !== 'number' && typeNum !== 'string') {
78
+ return num;
79
+ }
80
+ try {
81
+ return round(num, ratio).toFixed(ratio);
82
+ }
83
+ catch (err) {
84
+ console.error(err);
85
+ return num;
86
+ }
87
+ }
88
+ /**
89
+ * @description 添加千分符符号
90
+ */
91
+ function toThousand(num) {
92
+ var typeNum = typeof num;
93
+ if (typeNum !== 'number' && typeNum !== 'string') {
94
+ return num;
95
+ }
96
+ var str = (num + '').replace(/(\d{1,3})(?=(\d{3})+(?:$|\.))/g, '$1,');
97
+ return str;
98
+ }
99
+ /**
100
+ * @description 去除指定字符串
101
+ */
102
+ function clearAssignStr(str, originalStr) {
103
+ if (!originalStr) {
104
+ return originalStr;
105
+ }
106
+ if (originalStr.startsWith(str)) {
107
+ return originalStr.replace(str, '');
108
+ }
109
+ return originalStr;
110
+ }
111
+ /**
112
+ * @description 下载重命名
113
+ */
114
+ function loadFileRename(fileUrl, fileName) {
115
+ var xhr = new XMLHttpRequest();
116
+ xhr.open('GET', fileUrl, true);
117
+ xhr.responseType = 'blob';
118
+ xhr.onload = function () {
119
+ if (xhr.status === 200) {
120
+ var link = document.createElement('a');
121
+ var body = document.querySelector('body');
122
+ link.href = window.URL.createObjectURL(xhr.response);
123
+ link.download = fileName;
124
+ // fix Firefox
125
+ link.style.display = 'none';
126
+ body.appendChild(link);
127
+ link.click();
128
+ body.removeChild(link);
129
+ window.URL.revokeObjectURL(link.href);
130
+ }
131
+ };
132
+ xhr.send();
133
+ }
134
+ /**
135
+ * @description 当有依赖改变时,提示用户
136
+ */
137
+ function openTipModal(callback, data, tipTitle) {
138
+ if (Array.isArray(data) && data.length > 0) {
139
+ Modal.confirm({
140
+ content: tipTitle || '切换将清空已选数据!',
141
+ okText: '确认',
142
+ cancelText: '取消',
143
+ onCancel: function () {
144
+ callback && callback(false);
145
+ },
146
+ onOk: function () {
147
+ callback && callback(true);
148
+ },
149
+ });
150
+ }
151
+ else {
152
+ callback && callback(true);
153
+ }
154
+ }
155
+
156
+ var tools = /*#__PURE__*/Object.freeze({
157
+ __proto__: null,
158
+ timeTransfrom: timeTransfrom,
159
+ plus: plus,
160
+ minus: minus,
161
+ times: times,
162
+ divide: divide,
163
+ exactRound: exactRound,
164
+ toThousand: toThousand,
165
+ clearAssignStr: clearAssignStr,
166
+ loadFileRename: loadFileRename,
167
+ openTipModal: openTipModal
168
+ });
169
+
170
+ export { timeTransfrom as a, toThousand as b, clearAssignStr as c, exactRound as e, loadFileRename as l, openTipModal as o, tools as t };
package/dist/tools.d.ts CHANGED
@@ -38,3 +38,7 @@ export declare function clearAssignStr(str: string, originalStr: string): string
38
38
  * @description 下载重命名
39
39
  */
40
40
  export declare function loadFileRename(fileUrl: any, fileName: any): void;
41
+ /**
42
+ * @description 当有依赖改变时,提示用户
43
+ */
44
+ export declare function openTipModal(callback: (res: boolean) => void, data: any[], tipTitle?: string): void;
package/dist/tools.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import './tslib.es6-79a6072b.js';
2
2
  import 'dayjs';
3
3
  export { divide, minus, plus, times } from 'number-precision';
4
- export { c as clearAssignStr, e as exactRound, l as loadFileRename, a as timeTransfrom, b as toThousand } from './tools-3340e70f.js';
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';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ztxkutils",
3
- "version": "1.6.8",
3
+ "version": "1.6.9",
4
4
  "description": "",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",