qmwts 1.1.68 → 1.1.70
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/class/local-date.d.ts +1 -1
- package/dist/class/local-date.js +6 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +3 -3
- package/dist/utils/axios-builder.d.ts +2 -0
- package/dist/utils/axios-builder.js +18 -0
- package/dist/utils/axios-instance.d.ts +2 -2
- package/dist/utils/axios-instance.js +7 -6
- package/dist/utils/encryptor.js +2 -2
- package/dist/utils/object-utils.d.ts +1 -0
- package/dist/utils/object-utils.js +11 -0
- package/dist/utils/param-builder.d.ts +6 -0
- package/dist/utils/param-builder.js +27 -0
- package/dist/utils/request-data-generator.js +4 -1
- package/package.json +2 -2
- package/dist/utils/uuid-utils.d.ts +0 -4
- package/dist/utils/uuid-utils.js +0 -11
|
@@ -3,7 +3,7 @@ export default class LocalDate {
|
|
|
3
3
|
constructor();
|
|
4
4
|
constructor(date: Date);
|
|
5
5
|
static now(): LocalDate;
|
|
6
|
-
static parse(date: string | number): LocalDate;
|
|
6
|
+
static parse(date: string | number | Date | null | undefined): LocalDate | null;
|
|
7
7
|
static of(year: number, month: number, date: number): LocalDate;
|
|
8
8
|
getYear(): number;
|
|
9
9
|
getMonth(): number;
|
package/dist/class/local-date.js
CHANGED
|
@@ -12,7 +12,12 @@ class LocalDate {
|
|
|
12
12
|
return new LocalDate();
|
|
13
13
|
}
|
|
14
14
|
static parse(date) {
|
|
15
|
-
|
|
15
|
+
if (date == null)
|
|
16
|
+
return null;
|
|
17
|
+
const d = date instanceof Date ? date : new Date(date);
|
|
18
|
+
if (Number.isNaN(d.getTime())) // 无效日期返回null
|
|
19
|
+
return null;
|
|
20
|
+
return new LocalDate(d);
|
|
16
21
|
}
|
|
17
22
|
static of(year, month, date) {
|
|
18
23
|
return new LocalDate(new Date(year, month - 1, date));
|
package/dist/index.d.ts
CHANGED
|
@@ -9,7 +9,7 @@ export { default as NumberUtils } from './utils/number-utils';
|
|
|
9
9
|
export { default as JsonUtils } from './utils/json-utils';
|
|
10
10
|
export { default as ObjectUtils } from './utils/object-utils';
|
|
11
11
|
export { default as PrototypeUtils } from './utils/prototype-utils';
|
|
12
|
-
export { default as
|
|
12
|
+
export { default as ParamBuilder } from './utils/param-builder';
|
|
13
13
|
export { default as FileUtils } from './utils/file-utils';
|
|
14
14
|
export { default as StringUtils } from './utils/string-utils';
|
|
15
15
|
export { default as LocalDate } from './class/local-date';
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.YearMonth = exports.LocalDateTime = exports.LocalDate = exports.StringUtils = exports.FileUtils = exports.
|
|
3
|
+
exports.YearMonth = exports.LocalDateTime = exports.LocalDate = exports.StringUtils = exports.FileUtils = exports.ParamBuilder = exports.PrototypeUtils = exports.ObjectUtils = exports.JsonUtils = exports.NumberUtils = exports.Encryptor = exports.Downloader = exports.AxiosInstance = exports.FinanceUtils = exports.ArrayUtils = void 0;
|
|
4
4
|
var array_utils_1 = require("./utils/array-utils");
|
|
5
5
|
Object.defineProperty(exports, "ArrayUtils", { enumerable: true, get: function () { return array_utils_1.default; } });
|
|
6
6
|
var finance_utils_1 = require("./utils/finance-utils");
|
|
@@ -19,8 +19,8 @@ var object_utils_1 = require("./utils/object-utils");
|
|
|
19
19
|
Object.defineProperty(exports, "ObjectUtils", { enumerable: true, get: function () { return object_utils_1.default; } });
|
|
20
20
|
var prototype_utils_1 = require("./utils/prototype-utils");
|
|
21
21
|
Object.defineProperty(exports, "PrototypeUtils", { enumerable: true, get: function () { return prototype_utils_1.default; } });
|
|
22
|
-
var
|
|
23
|
-
Object.defineProperty(exports, "
|
|
22
|
+
var param_builder_1 = require("./utils/param-builder");
|
|
23
|
+
Object.defineProperty(exports, "ParamBuilder", { enumerable: true, get: function () { return param_builder_1.default; } });
|
|
24
24
|
var file_utils_1 = require("./utils/file-utils");
|
|
25
25
|
Object.defineProperty(exports, "FileUtils", { enumerable: true, get: function () { return file_utils_1.default; } });
|
|
26
26
|
var string_utils_1 = require("./utils/string-utils");
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
var axios_1 = require("axios");
|
|
4
|
+
axios_1.default.interceptors.request.use(function (request) {
|
|
5
|
+
console.log('request');
|
|
6
|
+
return request;
|
|
7
|
+
}, function (error) {
|
|
8
|
+
console.log('request error');
|
|
9
|
+
return Promise.reject(error);
|
|
10
|
+
});
|
|
11
|
+
axios_1.default.interceptors.response.use(function (response) {
|
|
12
|
+
console.log('response');
|
|
13
|
+
return response;
|
|
14
|
+
}, function (error) {
|
|
15
|
+
console.log('response error');
|
|
16
|
+
return Promise.reject(error);
|
|
17
|
+
});
|
|
18
|
+
exports.default = axios_1.default;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
export default
|
|
1
|
+
declare const instance: import("axios").AxiosInstance;
|
|
2
|
+
export default instance;
|
|
@@ -1,21 +1,22 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const axios_1 = require("axios");
|
|
4
|
-
const
|
|
4
|
+
const param_builder_1 = require("./param-builder");
|
|
5
5
|
// post 默认application/json
|
|
6
6
|
// post 使用URLSearchParams自动变为application/x-www-form-urlencoded;charset=UTF-8
|
|
7
7
|
// post 使用FormData自动变为multipart/form-data
|
|
8
8
|
// get 默认无
|
|
9
9
|
// get 使用URLSearchParams默认无
|
|
10
10
|
// get 无法使用FormData
|
|
11
|
-
axios_1.default.
|
|
12
|
-
|
|
13
|
-
request.
|
|
11
|
+
const instance = axios_1.default.create({});
|
|
12
|
+
instance.interceptors.request.use(request => {
|
|
13
|
+
request.data = param_builder_1.default.buildData(request.data);
|
|
14
|
+
request.params = param_builder_1.default.buildParams(request.params);
|
|
14
15
|
return request;
|
|
15
16
|
}, error => {
|
|
16
17
|
return Promise.reject(error);
|
|
17
18
|
});
|
|
18
|
-
|
|
19
|
+
instance.interceptors.response.use(async (response) => {
|
|
19
20
|
if (response.config.responseType === 'blob') {
|
|
20
21
|
const { data } = response;
|
|
21
22
|
if (data.type === 'application/x-download') { // 不是json说明下载成功
|
|
@@ -37,4 +38,4 @@ axios_1.default.interceptors.response.use(async (response) => {
|
|
|
37
38
|
}, error => {
|
|
38
39
|
return Promise.reject(error);
|
|
39
40
|
});
|
|
40
|
-
exports.default =
|
|
41
|
+
exports.default = instance;
|
package/dist/utils/encryptor.js
CHANGED
|
@@ -2,12 +2,12 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.default = {
|
|
4
4
|
encrypt(s, type) {
|
|
5
|
-
if (type ===
|
|
5
|
+
if (type === 'base64')
|
|
6
6
|
return btoa(s);
|
|
7
7
|
throw '请指定加密类型';
|
|
8
8
|
},
|
|
9
9
|
decrypt(s, type) {
|
|
10
|
-
if (type ===
|
|
10
|
+
if (type === 'base64')
|
|
11
11
|
try {
|
|
12
12
|
return atob(s);
|
|
13
13
|
}
|
|
@@ -2,5 +2,6 @@ declare const _default: {
|
|
|
2
2
|
optionalChaining(o: any | undefined, chain: string, substitute?: any): any;
|
|
3
3
|
setValue(o?: any, value?: any, exclusions?: any): void;
|
|
4
4
|
merge(...objects: any[]): object;
|
|
5
|
+
contains(a?: Record<string, any>, b?: Record<string, any>): boolean;
|
|
5
6
|
};
|
|
6
7
|
export default _default;
|
|
@@ -38,5 +38,16 @@ exports.default = {
|
|
|
38
38
|
}
|
|
39
39
|
}
|
|
40
40
|
return data;
|
|
41
|
+
},
|
|
42
|
+
// a是否包含b的全部属性
|
|
43
|
+
contains(a = {}, b = {}) {
|
|
44
|
+
return Object.entries(b).every(([key, valueB]) => {
|
|
45
|
+
const valueA = a[key];
|
|
46
|
+
// 都是对象或数组 → 递归比较
|
|
47
|
+
if (prototype_utils_1.default.isObject(valueA) && prototype_utils_1.default.isObject(valueB))
|
|
48
|
+
return this.contains(valueA, valueB);
|
|
49
|
+
// 其他情况直接比较(包括 null、数字、字符串、布尔值等)
|
|
50
|
+
return valueA === valueB;
|
|
51
|
+
});
|
|
41
52
|
}
|
|
42
53
|
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = {
|
|
4
|
+
build(data = {}, params) {
|
|
5
|
+
for (const key in data) {
|
|
6
|
+
if (Object.prototype.hasOwnProperty.call(data, key)) { // 只遍历自有属性,不要原型链上的属性
|
|
7
|
+
const value = data[key];
|
|
8
|
+
if (Array.isArray(value)) { // 数组循环append
|
|
9
|
+
const len = value.length;
|
|
10
|
+
for (let i = 0; i < len; i++) {
|
|
11
|
+
params.append(key, value[i]);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
else if (value != null) {
|
|
15
|
+
params.append(key, value);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
return params;
|
|
20
|
+
},
|
|
21
|
+
buildParams(data = {}) {
|
|
22
|
+
return this.build(data, new URLSearchParams());
|
|
23
|
+
},
|
|
24
|
+
buildData(data = {}) {
|
|
25
|
+
return this.build(data, new FormData());
|
|
26
|
+
},
|
|
27
|
+
};
|
|
@@ -6,9 +6,12 @@ exports.default = {
|
|
|
6
6
|
if (Array.isArray(value))
|
|
7
7
|
for (const i of value)
|
|
8
8
|
params.append(key, i);
|
|
9
|
-
else if (value
|
|
9
|
+
else if (isValidValue(value))
|
|
10
10
|
params.append(key, value);
|
|
11
11
|
}
|
|
12
12
|
return params;
|
|
13
13
|
}
|
|
14
14
|
};
|
|
15
|
+
function isValidValue(value) {
|
|
16
|
+
return value !== null && value !== void 0;
|
|
17
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "qmwts",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.70",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -22,6 +22,6 @@
|
|
|
22
22
|
"jszip": "^3.10.1"
|
|
23
23
|
},
|
|
24
24
|
"peerDependencies": {
|
|
25
|
-
"axios": "^1.
|
|
25
|
+
"axios": "^1.12.2"
|
|
26
26
|
}
|
|
27
27
|
}
|
package/dist/utils/uuid-utils.js
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.default = {
|
|
4
|
-
uuid: function () {
|
|
5
|
-
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
|
|
6
|
-
var r = (Math.random() * 16) | 0;
|
|
7
|
-
var v = c === 'x' ? r : (r & 0x3) | 0x8;
|
|
8
|
-
return v.toString(16);
|
|
9
|
-
});
|
|
10
|
-
}
|
|
11
|
-
};
|