qmwts 1.2.11 → 1.2.12
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.d.ts +1 -0
- package/dist/index.js +3 -1
- package/dist/utils/axios-instance2.d.ts +2 -0
- package/dist/utils/axios-instance2.js +50 -0
- package/dist/utils/common.d.ts +6 -0
- package/dist/utils/common.js +29 -0
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -23,3 +23,4 @@ export { fileType } from './utils/file-utils2';
|
|
|
23
23
|
export { clearValues } from './utils/object-utils2';
|
|
24
24
|
export { formatDateDiff, formatDateTime, parseDate } from './utils/date-utils';
|
|
25
25
|
export { useKeepAliveInit } from './utils/vue-utils';
|
|
26
|
+
export { debounce } from './utils/common';
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.useKeepAliveInit = exports.parseDate = exports.formatDateTime = exports.formatDateDiff = exports.clearValues = exports.fileType = exports.prototype = exports.findTreeNodes = exports.summation = exports.thousandths = exports.isNumber = exports.sha256Hex = 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;
|
|
3
|
+
exports.debounce = exports.useKeepAliveInit = exports.parseDate = exports.formatDateTime = exports.formatDateDiff = exports.clearValues = exports.fileType = exports.prototype = exports.findTreeNodes = exports.summation = exports.thousandths = exports.isNumber = exports.sha256Hex = 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");
|
|
@@ -51,3 +51,5 @@ Object.defineProperty(exports, "formatDateTime", { enumerable: true, get: functi
|
|
|
51
51
|
Object.defineProperty(exports, "parseDate", { enumerable: true, get: function () { return date_utils_1.parseDate; } });
|
|
52
52
|
var vue_utils_1 = require("./utils/vue-utils");
|
|
53
53
|
Object.defineProperty(exports, "useKeepAliveInit", { enumerable: true, get: function () { return vue_utils_1.useKeepAliveInit; } });
|
|
54
|
+
var common_1 = require("./utils/common");
|
|
55
|
+
Object.defineProperty(exports, "debounce", { enumerable: true, get: function () { return common_1.debounce; } });
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
const axios_1 = require("axios");
|
|
13
|
+
const param_builder_1 = require("./param-builder");
|
|
14
|
+
// post 默认application/json
|
|
15
|
+
// post 使用URLSearchParams自动变为application/x-www-form-urlencoded;charset=UTF-8
|
|
16
|
+
// post 使用FormData自动变为multipart/form-data
|
|
17
|
+
// get 默认无
|
|
18
|
+
// get 使用URLSearchParams默认无
|
|
19
|
+
// get 无法使用FormData
|
|
20
|
+
const instance = axios_1.default.create({});
|
|
21
|
+
instance.interceptors.request.use(request => {
|
|
22
|
+
request.data = param_builder_1.default.buildData(request.data);
|
|
23
|
+
request.params = param_builder_1.default.buildParams(request.params);
|
|
24
|
+
return request;
|
|
25
|
+
}, error => {
|
|
26
|
+
return Promise.reject(error);
|
|
27
|
+
});
|
|
28
|
+
instance.interceptors.response.use((response) => __awaiter(void 0, void 0, void 0, function* () {
|
|
29
|
+
if (response.config.responseType === 'blob') {
|
|
30
|
+
const { data } = response;
|
|
31
|
+
if (data.type === 'application/x-download') { // 不是json说明下载成功
|
|
32
|
+
const file = new File([data], decodeURI(response.headers['content-disposition'].split('filename=')[1]));
|
|
33
|
+
const a = document.createElement('a');
|
|
34
|
+
a.href = URL.createObjectURL(file);
|
|
35
|
+
a.download = file.name;
|
|
36
|
+
a.click();
|
|
37
|
+
// 释放
|
|
38
|
+
URL.revokeObjectURL(a.href);
|
|
39
|
+
a.remove();
|
|
40
|
+
return Promise.resolve(response);
|
|
41
|
+
}
|
|
42
|
+
else if (data.type === 'application/json') { // 是json说明有报错
|
|
43
|
+
response.data = yield new Response(data).json();
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return response;
|
|
47
|
+
}), error => {
|
|
48
|
+
return Promise.reject(error);
|
|
49
|
+
});
|
|
50
|
+
exports.default = instance;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.debounce = void 0;
|
|
4
|
+
const debounce = (fn, delay = 300, immediate = false) => {
|
|
5
|
+
let timer = null;
|
|
6
|
+
const debounced = function (...args) {
|
|
7
|
+
const callNow = immediate && !timer;
|
|
8
|
+
if (timer) {
|
|
9
|
+
clearTimeout(timer);
|
|
10
|
+
}
|
|
11
|
+
timer = setTimeout(() => {
|
|
12
|
+
timer = null;
|
|
13
|
+
if (!immediate) {
|
|
14
|
+
fn.apply(this, args);
|
|
15
|
+
}
|
|
16
|
+
}, delay);
|
|
17
|
+
if (callNow) {
|
|
18
|
+
fn.apply(this, args);
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
debounced.cancel = () => {
|
|
22
|
+
if (timer) {
|
|
23
|
+
clearTimeout(timer);
|
|
24
|
+
timer = null;
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
return debounced;
|
|
28
|
+
};
|
|
29
|
+
exports.debounce = debounce;
|