ztxkutils 1.6.5 → 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/request.js CHANGED
@@ -1,5 +1,5 @@
1
- import './tslib.es6-2755a364.js';
1
+ import './tslib.es6-79a6072b.js';
2
2
  import 'axios';
3
3
  import 'ztxkui';
4
- export { a as default } from './request-12c66cd8.js';
4
+ export { a as default } from './request-7944ad16.js';
5
5
  import './authority-17b7fde2.js';
@@ -0,0 +1,147 @@
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
+
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
+ /**
72
+ * @description 精确四舍五入后保留几位小数
73
+ */
74
+ function exactRound(num, ratio) {
75
+ var typeNum = typeof num;
76
+ if (typeNum !== 'number' && typeNum !== 'string') {
77
+ return num;
78
+ }
79
+ try {
80
+ return round(num, ratio).toFixed(ratio);
81
+ }
82
+ catch (err) {
83
+ console.error(err);
84
+ return num;
85
+ }
86
+ }
87
+ /**
88
+ * @description 添加千分符符号
89
+ */
90
+ function toThousand(num) {
91
+ var typeNum = typeof num;
92
+ if (typeNum !== 'number' && typeNum !== 'string') {
93
+ return num;
94
+ }
95
+ var str = (num + '').replace(/(\d{1,3})(?=(\d{3})+(?:$|\.))/g, '$1,');
96
+ return str;
97
+ }
98
+ /**
99
+ * @description 去除指定字符串
100
+ */
101
+ function clearAssignStr(str, originalStr) {
102
+ if (!originalStr) {
103
+ return originalStr;
104
+ }
105
+ if (originalStr.startsWith(str)) {
106
+ return originalStr.replace(str, '');
107
+ }
108
+ return originalStr;
109
+ }
110
+ /**
111
+ * @description 下载重命名
112
+ */
113
+ function loadFileRename(fileUrl, fileName) {
114
+ var xhr = new XMLHttpRequest();
115
+ xhr.open('GET', fileUrl, true);
116
+ xhr.responseType = 'blob';
117
+ xhr.onload = function () {
118
+ if (xhr.status === 200) {
119
+ var link = document.createElement('a');
120
+ var body = document.querySelector('body');
121
+ link.href = window.URL.createObjectURL(xhr.response);
122
+ link.download = fileName;
123
+ // fix Firefox
124
+ link.style.display = 'none';
125
+ body.appendChild(link);
126
+ link.click();
127
+ body.removeChild(link);
128
+ window.URL.revokeObjectURL(link.href);
129
+ }
130
+ };
131
+ xhr.send();
132
+ }
133
+
134
+ var tools = /*#__PURE__*/Object.freeze({
135
+ __proto__: null,
136
+ timeTransfrom: timeTransfrom,
137
+ plus: plus,
138
+ minus: minus,
139
+ times: times,
140
+ divide: divide,
141
+ exactRound: exactRound,
142
+ toThousand: toThousand,
143
+ clearAssignStr: clearAssignStr,
144
+ loadFileRename: loadFileRename
145
+ });
146
+
147
+ export { timeTransfrom as a, toThousand as b, clearAssignStr as c, exactRound as e, loadFileRename as l, tools as t };
@@ -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
- import './tslib.es6-2755a364.js';
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-37d63daa.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';
@@ -0,0 +1,65 @@
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
+ export { __assign as _, __awaiter as a, __generator as b };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ztxkutils",
3
- "version": "1.6.5",
3
+ "version": "1.6.9",
4
4
  "description": "",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",
@@ -45,6 +45,7 @@
45
45
  },
46
46
  "dependencies": {
47
47
  "js-base64": "^3.6.0",
48
+ "screenfull": "^5.1.0",
48
49
  "sockjs-client": "^1.5.1",
49
50
  "stompjs": "^2.3.3",
50
51
  "zt-sockjs-client": "^0.0.1"