ztxkutils 1.7.0 → 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-46a946e5.js';
4
- export { v as validate } from './validate-f3423df5.js';
3
+ export { t as tools } from './tools-e073f57e.js';
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,196 @@
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
+ 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
+ function divide(num1, num2) {
73
+ var others = [];
74
+ for (var _i = 2; _i < arguments.length; _i++) {
75
+ others[_i - 2] = arguments[_i];
76
+ }
77
+ try {
78
+ return divide$1.apply(void 0, __spreadArray([num1, num2], others));
79
+ }
80
+ catch (err) {
81
+ console.log(err);
82
+ return 0;
83
+ }
84
+ }
85
+ /**
86
+ * @description 精确四舍五入后保留几位小数
87
+ */
88
+ function exactRound(num, ratio) {
89
+ var typeNum = typeof num;
90
+ if (typeNum !== 'number' && typeNum !== 'string') {
91
+ return num;
92
+ }
93
+ try {
94
+ return round(num, ratio).toFixed(ratio);
95
+ }
96
+ catch (err) {
97
+ console.error(err);
98
+ return num;
99
+ }
100
+ }
101
+ /**
102
+ * @description 添加千分符符号
103
+ */
104
+ function toThousand(num) {
105
+ var typeNum = typeof num;
106
+ if (typeNum !== 'number' && typeNum !== 'string') {
107
+ return num;
108
+ }
109
+ var str = (num + '').replace(/(\d{1,3})(?=(\d{3})+(?:$|\.))/g, '$1,');
110
+ return str;
111
+ }
112
+ /**
113
+ * @description 去除指定字符串
114
+ */
115
+ function clearAssignStr(str, originalStr) {
116
+ if (!originalStr) {
117
+ return originalStr;
118
+ }
119
+ if (originalStr.startsWith(str)) {
120
+ return originalStr.replace(str, '');
121
+ }
122
+ return originalStr;
123
+ }
124
+ /**
125
+ * @description 下载重命名
126
+ */
127
+ function loadFileRename(fileUrl, fileName) {
128
+ var xhr = new XMLHttpRequest();
129
+ xhr.open('GET', fileUrl, true);
130
+ xhr.responseType = 'blob';
131
+ xhr.onload = function () {
132
+ if (xhr.status === 200) {
133
+ var link = document.createElement('a');
134
+ var body = document.querySelector('body');
135
+ link.href = window.URL.createObjectURL(xhr.response);
136
+ link.download = fileName;
137
+ // fix Firefox
138
+ link.style.display = 'none';
139
+ body.appendChild(link);
140
+ link.click();
141
+ body.removeChild(link);
142
+ window.URL.revokeObjectURL(link.href);
143
+ }
144
+ };
145
+ xhr.send();
146
+ }
147
+ /**
148
+ * @description 当有依赖改变时,提示用户
149
+ */
150
+ function openTipModal(callback, data, tipTitle) {
151
+ if (Array.isArray(data) && data.length > 0) {
152
+ Modal.confirm({
153
+ content: tipTitle || '切换将清空已选数据!',
154
+ okText: '确认',
155
+ cancelText: '取消',
156
+ onCancel: function () {
157
+ callback && callback(false);
158
+ },
159
+ onOk: function () {
160
+ callback && callback(true);
161
+ },
162
+ });
163
+ }
164
+ else {
165
+ callback && callback(true);
166
+ }
167
+ }
168
+ /**
169
+ * @description 文件大小提示转换
170
+ */
171
+ function transformFileSize(value) {
172
+ if (value < 1024) {
173
+ return round(value, 2).toFixed(2) + 'B';
174
+ }
175
+ else if (value < 1024 * 1024) {
176
+ return round(divide(value, 1024), 2).toFixed(2) + 'KB';
177
+ }
178
+ return round(divide(value, 1024, 1024), 2).toFixed(2) + 'MB';
179
+ }
180
+
181
+ var tools = /*#__PURE__*/Object.freeze({
182
+ __proto__: null,
183
+ timeTransfrom: timeTransfrom,
184
+ plus: plus,
185
+ minus: minus,
186
+ times: times,
187
+ divide: divide,
188
+ exactRound: exactRound,
189
+ toThousand: toThousand,
190
+ clearAssignStr: clearAssignStr,
191
+ loadFileRename: loadFileRename,
192
+ openTipModal: openTipModal,
193
+ transformFileSize: transformFileSize
194
+ });
195
+
196
+ export { timeTransfrom as a, toThousand as b, clearAssignStr as c, divide as d, exactRound as e, transformFileSize as f, loadFileRename as l, openTipModal as o, tools as t };
@@ -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
@@ -41,6 +41,6 @@ export declare function clearAssignStr(str: string, originalStr: string): string
41
41
  */
42
42
  export declare function loadFileRename(fileUrl: any, fileName: any): void;
43
43
  /**
44
- * @description 当有依赖改变时,提示用户
44
+ * @description 文件大小提示转换
45
45
  */
46
- export declare function openTipModal(callback: (res: boolean) => void, data: any[], tipTitle?: string): void;
46
+ export declare function transformFileSize(value: number): string;
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 } from './tools-46a946e5.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';
@@ -0,0 +1,60 @@
1
+ /**
2
+ * @description 常用正则表达式
3
+ */
4
+ var validate = {
5
+ /**
6
+ * @description 长度验证,最小长度字符,0-200个字符
7
+ */
8
+ smallLenValidate: /^(?:\s*)[\s\S]{0,200}(?:\s*)$/,
9
+ /**
10
+ * @description 长度验证,中等长度字符,0-400个字符
11
+ */
12
+ middleLenValidate: /^(?:\s*)[\s\S]{0,400}(?:\s*)$/,
13
+ /**
14
+ * @description 长度验证,最大长度字符,0-600个字符
15
+ */
16
+ largeLenValidate: /^(?:\s*)[\s\S]{0,600}(?:\s*)$/,
17
+ /**
18
+ * @description 电话号码验证
19
+ */
20
+ phoneValidate: /^1[0-9]{10}$/,
21
+ /**
22
+ * @description 身份证验证
23
+ * 18位 最后一位可以是X x
24
+ */
25
+ idCardValidate: /^\d{17}[0-9Xx]$/,
26
+ /**
27
+ * @description 邮箱验证
28
+ */
29
+ emailValidate: /^\S+@\S+$/,
30
+ /**
31
+ * @description 密码验证
32
+ */
33
+ passwordValidate: /^[A-Za-z\d@$!%*?&_.]{8,16}$/,
34
+ };
35
+ var commonMessage = {
36
+ smallLenMessage: function (type) {
37
+ if (type === void 0) { type = ''; }
38
+ return type + "\u8D85\u8FC7\u6700\u5927\u5B57\u7B26\u957F\u5EA620";
39
+ },
40
+ middleLenMessage: function (type) {
41
+ if (type === void 0) { type = ''; }
42
+ return type + "\u8D85\u8FC7\u6700\u5927\u5B57\u7B26\u957F\u5EA640";
43
+ },
44
+ largeLenMessage: function (type) {
45
+ if (type === void 0) { type = ''; }
46
+ return type + "\u8D85\u8FC7\u6700\u5927\u5B57\u7B26\u957F\u5EA660";
47
+ },
48
+ phoneMessage: '请输入正确的手机号',
49
+ idCardMessage: '请输入正确的身份证',
50
+ emailMessage: '请输入正确的邮箱',
51
+ passwordMessage: '密码由8-16位的大小写字母、数字和特殊字符组成',
52
+ };
53
+
54
+ var validate$1 = /*#__PURE__*/Object.freeze({
55
+ __proto__: null,
56
+ validate: validate,
57
+ commonMessage: commonMessage
58
+ });
59
+
60
+ export { validate as a, commonMessage as c, validate$1 as v };
@@ -0,0 +1,60 @@
1
+ /**
2
+ * @description 常用正则表达式
3
+ */
4
+ var validate = {
5
+ /**
6
+ * @description 长度验证,最小长度字符,0-200个字符
7
+ */
8
+ smallLenValidate: /^(?:\s*)[\s\S]{0,200}(?:\s*)$/,
9
+ /**
10
+ * @description 长度验证,中等长度字符,0-400个字符
11
+ */
12
+ middleLenValidate: /^(?:\s*)[\s\S]{0,400}(?:\s*)$/,
13
+ /**
14
+ * @description 长度验证,最大长度字符,0-600个字符
15
+ */
16
+ largeLenValidate: /^(?:\s*)[\s\S]{0,600}(?:\s*)$/,
17
+ /**
18
+ * @description 电话号码验证
19
+ */
20
+ phoneValidate: /^1[0-9]{10}$/,
21
+ /**
22
+ * @description 身份证验证
23
+ * 18位 最后一位可以是X x
24
+ */
25
+ idCardValidate: /^\d{17}[0-9Xx]$/,
26
+ /**
27
+ * @description 邮箱验证
28
+ */
29
+ emailValidate: /^\S+@\S+$/,
30
+ /**
31
+ * @description 密码验证
32
+ */
33
+ passwordValidate: /^[A-Za-z\d@$!%*?&_.]{8,16}$/,
34
+ };
35
+ var commonMessage = {
36
+ smallLenMessage: function (type) {
37
+ if (type === void 0) { type = ''; }
38
+ return type + "\u8D85\u8FC7\u6700\u5927\u5B57\u7B26\u957F\u5EA6200";
39
+ },
40
+ middleLenMessage: function (type) {
41
+ if (type === void 0) { type = ''; }
42
+ return type + "\u8D85\u8FC7\u6700\u5927\u5B57\u7B26\u957F\u5EA6400";
43
+ },
44
+ largeLenMessage: function (type) {
45
+ if (type === void 0) { type = ''; }
46
+ return type + "\u8D85\u8FC7\u6700\u5927\u5B57\u7B26\u957F\u5EA6600";
47
+ },
48
+ phoneMessage: '请输入正确的手机号',
49
+ idCardMessage: '请输入正确的身份证',
50
+ emailMessage: '请输入正确的邮箱',
51
+ passwordMessage: '密码由8-16位的大小写字母、数字和特殊字符组成',
52
+ };
53
+
54
+ var validate$1 = /*#__PURE__*/Object.freeze({
55
+ __proto__: null,
56
+ validate: validate,
57
+ commonMessage: commonMessage
58
+ });
59
+
60
+ export { validate as a, commonMessage as c, validate$1 as v };
@@ -3,13 +3,16 @@
3
3
  */
4
4
  declare const validate: {
5
5
  /**
6
- * @description 长度验证
7
- * smallLen
8
- * middleLen
9
- * largeLen
6
+ * @description 长度验证,最小长度字符,0-200个字符
10
7
  */
11
8
  smallLenValidate: RegExp;
9
+ /**
10
+ * @description 长度验证,中等长度字符,0-400个字符
11
+ */
12
12
  middleLenValidate: RegExp;
13
+ /**
14
+ * @description 长度验证,最大长度字符,0-600个字符
15
+ */
13
16
  largeLenValidate: RegExp;
14
17
  /**
15
18
  * @description 电话号码验证
package/dist/validate.js CHANGED
@@ -1 +1 @@
1
- export { c as commonMessage, a as validate } from './validate-f3423df5.js';
1
+ export { c as commonMessage, a as validate } from './validate-ecddae1d.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ztxkutils",
3
- "version": "1.7.0",
3
+ "version": "1.7.4",
4
4
  "description": "",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",