zmdms-utils 0.0.70 → 0.0.72
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/es/math.js +6 -3
- package/dist/es/request.d.ts +3 -0
- package/dist/es/request.js +5 -2
- package/dist/es/src/test.js +42 -0
- package/package.json +1 -1
- package/src/math.ts +6 -3
- package/src/request.ts +7 -1
- package/src/test.js +42 -0
package/dist/es/math.js
CHANGED
|
@@ -91,9 +91,12 @@ function divide(num1, num2, precision) {
|
|
|
91
91
|
if (typeof result === "number") {
|
|
92
92
|
return result;
|
|
93
93
|
}
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
//
|
|
94
|
+
// FIXME: 不记得这里为什么要先设置下小数位了。
|
|
95
|
+
// 会影响其他值的计算.
|
|
96
|
+
// Decimal.set({ precision });
|
|
97
|
+
// return new Decimal(_num1).div(_num2).toNumber();
|
|
98
|
+
// 这里改成这种模式。行为基本与之前是一致的
|
|
99
|
+
return Number(new Decimal(_num1).div(_num2).toFixed(precision));
|
|
97
100
|
}
|
|
98
101
|
catch (err) {
|
|
99
102
|
console.error("计算除法出错", err);
|
package/dist/es/request.d.ts
CHANGED
|
@@ -14,6 +14,7 @@ declare class AxiosRequest {
|
|
|
14
14
|
private messageWarning?;
|
|
15
15
|
private modalConfirm?;
|
|
16
16
|
private instanceAxios;
|
|
17
|
+
private tokenKey;
|
|
17
18
|
constructor(otherOptions: IOtherOptions);
|
|
18
19
|
private defaultSetting;
|
|
19
20
|
private interceptorsRequest;
|
|
@@ -64,6 +65,8 @@ interface IOtherOptions {
|
|
|
64
65
|
commonHeaders?: {
|
|
65
66
|
[prop: string]: any;
|
|
66
67
|
};
|
|
68
|
+
/** 请求认证TOKEN KEY */
|
|
69
|
+
tokenKey?: string;
|
|
67
70
|
/** 超时时间 */
|
|
68
71
|
timeout?: number;
|
|
69
72
|
/** 基础url */
|
package/dist/es/request.js
CHANGED
|
@@ -20,9 +20,12 @@ var AxiosRequest = /** @class */ (function () {
|
|
|
20
20
|
this.isTimeout = false;
|
|
21
21
|
// axios单例
|
|
22
22
|
this.instanceAxios = axios.create();
|
|
23
|
-
|
|
23
|
+
// tokenKey
|
|
24
|
+
this.tokenKey = TOKEN_KEY;
|
|
25
|
+
var crypto = otherOptions.crypto, jumpCallback = otherOptions.jumpCallback, isTimeoutConfirm = otherOptions.isTimeoutConfirm, isTimeoutConfirmStr = otherOptions.isTimeoutConfirmStr, messageWarning = otherOptions.messageWarning, modalConfirm = otherOptions.modalConfirm, tokenKey = otherOptions.tokenKey, resetOtherOptions = __rest(otherOptions, ["crypto", "jumpCallback", "isTimeoutConfirm", "isTimeoutConfirmStr", "messageWarning", "modalConfirm", "tokenKey"]);
|
|
24
26
|
this.otherOptions = __assign(__assign({}, defaultOptions), resetOtherOptions);
|
|
25
27
|
this.crypto = crypto;
|
|
28
|
+
this.tokenKey = tokenKey || TOKEN_KEY;
|
|
26
29
|
this.isTimeoutConfirm = isTimeoutConfirm;
|
|
27
30
|
this.isTimeoutConfirmStr = isTimeoutConfirmStr;
|
|
28
31
|
this.jumpCallback = jumpCallback;
|
|
@@ -226,7 +229,7 @@ var AxiosRequest = /** @class */ (function () {
|
|
|
226
229
|
}
|
|
227
230
|
if (isAuth) {
|
|
228
231
|
var token = getToken();
|
|
229
|
-
newOptions.headers[
|
|
232
|
+
newOptions.headers[this.tokenKey] = "bearer ".concat(token);
|
|
230
233
|
}
|
|
231
234
|
// 遍历params,将undefined值 转为null值
|
|
232
235
|
if (newOptions.data) {
|
package/dist/es/src/test.js
CHANGED
|
@@ -177,8 +177,50 @@ function times(num1, num2) {
|
|
|
177
177
|
}
|
|
178
178
|
}
|
|
179
179
|
|
|
180
|
+
function divide(num1, num2, precision = 5) {
|
|
181
|
+
try {
|
|
182
|
+
const _num1 = num1 == null ? NaN : Number(num1);
|
|
183
|
+
const _num2 = num2 == null ? NaN : Number(num2);
|
|
184
|
+
// 如果两个数都是非数字 那么直接返回0
|
|
185
|
+
const result = initNum(_num1, _num2);
|
|
186
|
+
if (typeof result === "number") {
|
|
187
|
+
return result;
|
|
188
|
+
}
|
|
189
|
+
// FIXME: 不记得这里为什么要先设置下小数位了。
|
|
190
|
+
// 计算完后要重置下这个值要不然会影响其他值的计算
|
|
191
|
+
// Decimal.set({ precision });
|
|
192
|
+
const result1 = Number(new Decimal(_num1).div(_num2).toFixed(precision));
|
|
193
|
+
return result1;
|
|
194
|
+
// return (isNaN(_num1) ? 0 : _num1) / (isNaN(_num2) ? 0 : _num2);
|
|
195
|
+
} catch (err) {
|
|
196
|
+
console.error("计算除法出错", err);
|
|
197
|
+
return 0;
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
function plus(num1, num2) {
|
|
202
|
+
try {
|
|
203
|
+
const _num1 = num1 == null ? NaN : Number(num1);
|
|
204
|
+
const _num2 = num2 == null ? NaN : Number(num2);
|
|
205
|
+
// 如果两个数都是非数字 那么直接返回0
|
|
206
|
+
const result = initNum(_num1, _num2);
|
|
207
|
+
if (typeof result === "number") {
|
|
208
|
+
return result;
|
|
209
|
+
}
|
|
210
|
+
return new Decimal(_num1).add(_num2).toNumber();
|
|
211
|
+
// return (isNaN(_num1) ? 0 : _num1) + (isNaN(_num2) ? 0 : _num2);
|
|
212
|
+
} catch (err) {
|
|
213
|
+
console.error("计算加法出错", err);
|
|
214
|
+
return 0;
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
|
|
180
218
|
console.log(times(78.11, 0.77));
|
|
181
219
|
console.log(times(7777777.77, 1.1));
|
|
220
|
+
console.log(divide(222.77111122, 2.1222111, 19));
|
|
221
|
+
console.log(divide(4, 2));
|
|
222
|
+
console.log(plus(1.1222111, 1.22233111));
|
|
223
|
+
console.log("=================");
|
|
182
224
|
// 7777777.77 * 1.1
|
|
183
225
|
const num1 = new Decimal("78.11");
|
|
184
226
|
|
package/package.json
CHANGED
package/src/math.ts
CHANGED
|
@@ -91,9 +91,12 @@ export function divide(num1: numType, num2: numType, precision: number = 5) {
|
|
|
91
91
|
if (typeof result === "number") {
|
|
92
92
|
return result;
|
|
93
93
|
}
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
//
|
|
94
|
+
// FIXME: 不记得这里为什么要先设置下小数位了。
|
|
95
|
+
// 会影响其他值的计算.
|
|
96
|
+
// Decimal.set({ precision });
|
|
97
|
+
// return new Decimal(_num1).div(_num2).toNumber();
|
|
98
|
+
// 这里改成这种模式。行为基本与之前是一致的
|
|
99
|
+
return Number(new Decimal(_num1).div(_num2).toFixed(precision));
|
|
97
100
|
} catch (err) {
|
|
98
101
|
console.error("计算除法出错", err);
|
|
99
102
|
return 0;
|
package/src/request.ts
CHANGED
|
@@ -36,6 +36,8 @@ export class AxiosRequest {
|
|
|
36
36
|
private modalConfirm?: IOtherOptions["modalConfirm"];
|
|
37
37
|
// axios单例
|
|
38
38
|
private instanceAxios: AxiosInstance = axios.create();
|
|
39
|
+
// tokenKey
|
|
40
|
+
private tokenKey: string = TOKEN_KEY;
|
|
39
41
|
|
|
40
42
|
constructor(otherOptions: IOtherOptions) {
|
|
41
43
|
const {
|
|
@@ -45,10 +47,12 @@ export class AxiosRequest {
|
|
|
45
47
|
isTimeoutConfirmStr,
|
|
46
48
|
messageWarning,
|
|
47
49
|
modalConfirm,
|
|
50
|
+
tokenKey,
|
|
48
51
|
...resetOtherOptions
|
|
49
52
|
} = otherOptions;
|
|
50
53
|
this.otherOptions = { ...defaultOptions, ...resetOtherOptions };
|
|
51
54
|
this.crypto = crypto;
|
|
55
|
+
this.tokenKey = tokenKey || TOKEN_KEY;
|
|
52
56
|
this.isTimeoutConfirm = isTimeoutConfirm;
|
|
53
57
|
this.isTimeoutConfirmStr = isTimeoutConfirmStr;
|
|
54
58
|
this.jumpCallback = jumpCallback;
|
|
@@ -275,7 +279,7 @@ export class AxiosRequest {
|
|
|
275
279
|
}
|
|
276
280
|
if (isAuth) {
|
|
277
281
|
const token = getToken();
|
|
278
|
-
newOptions.headers[
|
|
282
|
+
newOptions.headers[this.tokenKey] = `bearer ${token}`;
|
|
279
283
|
}
|
|
280
284
|
|
|
281
285
|
// 遍历params,将undefined值 转为null值
|
|
@@ -408,6 +412,8 @@ export interface IOtherOptions {
|
|
|
408
412
|
Authorization?: string;
|
|
409
413
|
/** 公用请求头 */
|
|
410
414
|
commonHeaders?: { [prop: string]: any };
|
|
415
|
+
/** 请求认证TOKEN KEY */
|
|
416
|
+
tokenKey?: string;
|
|
411
417
|
/** 超时时间 */
|
|
412
418
|
timeout?: number;
|
|
413
419
|
/** 基础url */
|
package/src/test.js
CHANGED
|
@@ -174,8 +174,50 @@ function times(num1, num2) {
|
|
|
174
174
|
}
|
|
175
175
|
}
|
|
176
176
|
|
|
177
|
+
function divide(num1, num2, precision = 5) {
|
|
178
|
+
try {
|
|
179
|
+
const _num1 = num1 == null ? NaN : Number(num1);
|
|
180
|
+
const _num2 = num2 == null ? NaN : Number(num2);
|
|
181
|
+
// 如果两个数都是非数字 那么直接返回0
|
|
182
|
+
const result = initNum(_num1, _num2);
|
|
183
|
+
if (typeof result === "number") {
|
|
184
|
+
return result;
|
|
185
|
+
}
|
|
186
|
+
// FIXME: 不记得这里为什么要先设置下小数位了。
|
|
187
|
+
// 计算完后要重置下这个值要不然会影响其他值的计算
|
|
188
|
+
// Decimal.set({ precision });
|
|
189
|
+
const result1 = Number(new Decimal(_num1).div(_num2).toFixed(precision));
|
|
190
|
+
return result1;
|
|
191
|
+
// return (isNaN(_num1) ? 0 : _num1) / (isNaN(_num2) ? 0 : _num2);
|
|
192
|
+
} catch (err) {
|
|
193
|
+
console.error("计算除法出错", err);
|
|
194
|
+
return 0;
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
function plus(num1, num2) {
|
|
199
|
+
try {
|
|
200
|
+
const _num1 = num1 == null ? NaN : Number(num1);
|
|
201
|
+
const _num2 = num2 == null ? NaN : Number(num2);
|
|
202
|
+
// 如果两个数都是非数字 那么直接返回0
|
|
203
|
+
const result = initNum(_num1, _num2);
|
|
204
|
+
if (typeof result === "number") {
|
|
205
|
+
return result;
|
|
206
|
+
}
|
|
207
|
+
return new Decimal(_num1).add(_num2).toNumber();
|
|
208
|
+
// return (isNaN(_num1) ? 0 : _num1) + (isNaN(_num2) ? 0 : _num2);
|
|
209
|
+
} catch (err) {
|
|
210
|
+
console.error("计算加法出错", err);
|
|
211
|
+
return 0;
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
|
|
177
215
|
console.log(times(78.11, 0.77));
|
|
178
216
|
console.log(times(7777777.77, 1.1));
|
|
217
|
+
console.log(divide(222.77111122, 2.1222111, 19));
|
|
218
|
+
console.log(divide(4, 2));
|
|
219
|
+
console.log(plus(1.1222111, 1.22233111));
|
|
220
|
+
console.log("=================");
|
|
179
221
|
// 7777777.77 * 1.1
|
|
180
222
|
const num1 = new Decimal("78.11");
|
|
181
223
|
|