ztxkutils 1.7.8 → 1.8.2

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,9 +1,9 @@
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-e073f57e.js';
3
+ export { t as tools } from './tools-49b33116.js';
4
4
  export { v as validate } from './validate-ecddae1d.js';
5
5
  export { r as request } from './request-eff26459.js';
6
- export { r as reqUrl } from './reqUrl-198b3d35.js';
6
+ export { r as reqUrl } from './reqUrl-68c864fb.js';
7
7
  import './tslib.es6-b9033aad.js';
8
8
  import 'dayjs';
9
9
  import 'number-precision';
@@ -0,0 +1,48 @@
1
+ /**
2
+ * @file 项目基本配置,包括各个环境的请求地址
3
+ */
4
+ // 环境变量
5
+ function getReqUrl(processObj) {
6
+ var ENV = processObj.REACT_APP_ENV;
7
+ // api服务器各个环境地址
8
+ var ZT_API_DEV = processObj.REACT_APP_ZT_API_DEV || 'http://192.168.0.83:8000'; // 开发环境
9
+ var ZT_API_TEST = processObj.REACT_APP_ZT_API_TEST || 'http://192.168.0.135:8000'; // 测试环境
10
+ var ZT_API_STAGE = processObj.REACT_APP_ZT_API_STAGE || 'http://192.168.0.134:8000'; // 阶段性环境
11
+ var ZT_API_PRODUCT = processObj.REACT_APP_ZT_API_PRODUCT || 'http://dz.zmd.com.cn'; // 生产环境
12
+ // 文件服务器
13
+ var ZT_FILE_PREVIEW_DEV = processObj.REACT_APP_ZT_FILE_PREVIEW_DEV || 'http://192.168.0.83:88'; // 开发环境
14
+ var ZT_FILE_PREVIEW_TEST = processObj.REACT_APP_ZT_FILE_PREVIEW_TEST || 'http://192.168.0.135:8012'; // 测试环境
15
+ var ZT_FILE_PREVIEW_STAGE = processObj.REACT_APP_ZT_FILE_PREVIEW_STAGE || 'http://192.168.0.134:8012'; // 阶段性环境
16
+ var ZT_FILE_PREVIEW_PRODUCT = processObj.REACT_ZT_FILE_PREVIEW_PRODUCT || 'http://dzfile.zmd.com.cn:8012'; // 生产环境
17
+ // 实际api请求地址
18
+ var ZT_API_BASEURL = ZT_API_DEV;
19
+ var ZT_FILE_BASEURL = ZT_FILE_PREVIEW_DEV;
20
+ if (ENV) {
21
+ switch (ENV.toLowerCase()) {
22
+ case 'zt-dev':
23
+ ZT_API_BASEURL = ZT_API_DEV;
24
+ ZT_FILE_BASEURL = ZT_FILE_PREVIEW_DEV;
25
+ break;
26
+ case 'zt-test':
27
+ ZT_API_BASEURL = ZT_API_TEST;
28
+ ZT_FILE_BASEURL = ZT_FILE_PREVIEW_TEST;
29
+ break;
30
+ case 'zt-stage':
31
+ ZT_API_BASEURL = ZT_API_STAGE;
32
+ ZT_FILE_BASEURL = ZT_FILE_PREVIEW_STAGE;
33
+ break;
34
+ case 'zt-product':
35
+ ZT_API_BASEURL = ZT_API_PRODUCT;
36
+ ZT_FILE_BASEURL = ZT_FILE_PREVIEW_PRODUCT;
37
+ break;
38
+ }
39
+ }
40
+ return { ZT_API_BASEURL: ZT_API_BASEURL, ZT_FILE_BASEURL: ZT_FILE_BASEURL };
41
+ }
42
+
43
+ var reqUrl = /*#__PURE__*/Object.freeze({
44
+ __proto__: null,
45
+ getReqUrl: getReqUrl
46
+ });
47
+
48
+ export { getReqUrl as g, reqUrl as r };
package/dist/reqUrl.js CHANGED
@@ -1 +1 @@
1
- export { g as getReqUrl } from './reqUrl-198b3d35.js';
1
+ export { g as getReqUrl } from './reqUrl-68c864fb.js';
@@ -98,14 +98,17 @@ var StompClient = /** @class */ (function () {
98
98
  _this.successCallbacks[key].isExecute = false;
99
99
  });
100
100
  }
101
- // 重连逻辑, 1秒后重连
101
+ // 重连逻辑, 默认3秒后重连
102
+ // 重连间隔,每隔5秒递增,超过最大间隔时间后,取最大间隔时间重连
102
103
  _this.client.disconnect(function () {
103
104
  var _a;
104
105
  _this.client = null;
105
106
  _this.reconnectionNum++;
107
+ var timeInterval = Math.ceil(_this.reconnectionNum / 5) *
108
+ ((_a = _this.connectWsConfig.reconnectionTime) !== null && _a !== void 0 ? _a : 3000);
106
109
  setTimeout(function () {
107
110
  _this.init();
108
- }, Math.ceil(_this.reconnectionNum / 5) * ((_a = _this.connectWsConfig.reconnectionTime) !== null && _a !== void 0 ? _a : 3000));
111
+ }, timeInterval > 30000 ? 30000 : timeInterval);
109
112
  });
110
113
  });
111
114
  };
@@ -0,0 +1,195 @@
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
+ * @description 更具key判断前后值是否一致
160
+ */
161
+ function isEqualByKey(keys, record, preRecord) {
162
+ var isEqual = false; // 是否相等
163
+ if (!record || !preRecord) {
164
+ isEqual = true;
165
+ return isEqual;
166
+ }
167
+ if (record === preRecord) {
168
+ return isEqual;
169
+ }
170
+ for (var i = 0; i < keys.length; i++) {
171
+ var key = keys[i];
172
+ if (record[key] !== preRecord[key]) {
173
+ isEqual = true;
174
+ break;
175
+ }
176
+ }
177
+ return isEqual;
178
+ }
179
+
180
+ var tools = /*#__PURE__*/Object.freeze({
181
+ __proto__: null,
182
+ timeTransfrom: timeTransfrom,
183
+ plus: plus,
184
+ minus: minus,
185
+ times: times,
186
+ divide: divide,
187
+ exactRound: exactRound,
188
+ toThousand: toThousand,
189
+ clearAssignStr: clearAssignStr,
190
+ loadFileRename: loadFileRename,
191
+ transformFileSize: transformFileSize,
192
+ isEqualByKey: isEqualByKey
193
+ });
194
+
195
+ export { timeTransfrom as a, toThousand as b, clearAssignStr as c, divide as d, exactRound as e, transformFileSize as f, isEqualByKey as i, loadFileRename as l, 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 transformFileSize(value: number): string;
47
+ /**
48
+ * @description 更具key判断前后值是否一致
49
+ */
50
+ export declare function isEqualByKey(keys: string[], record: any, preRecord: any): boolean;
package/dist/tools.js CHANGED
@@ -1,4 +1,4 @@
1
1
  import './tslib.es6-b9033aad.js';
2
2
  import 'dayjs';
3
3
  export { minus, plus, times } from 'number-precision';
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';
4
+ export { c as clearAssignStr, d as divide, e as exactRound, i as isEqualByKey, l as loadFileRename, a as timeTransfrom, b as toThousand, f as transformFileSize } from './tools-49b33116.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ztxkutils",
3
- "version": "1.7.8",
3
+ "version": "1.8.2",
4
4
  "description": "",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",