ls-pro-common 1.0.37 → 1.0.40
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/common.css +14 -1
- package/dist/common.js +1 -1
- package/dist/common.min.css +14 -1
- package/dist/common.min.js +1 -1
- package/es/http/index.js +17 -10
- package/es/utils/index.d.ts +7 -2
- package/es/utils/index.js +29 -0
- package/lib/http/index.js +16 -9
- package/lib/utils/index.d.ts +7 -2
- package/lib/utils/index.js +33 -2
- package/package.json +3 -3
package/es/http/index.js
CHANGED
|
@@ -2,7 +2,7 @@ import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
|
2
2
|
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
|
|
3
3
|
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
4
4
|
import { extend } from 'umi-request';
|
|
5
|
-
import { getCache, getUrlQuery, setUrlQuery, getResourceProps, showError, toGatewayUrl } from '../utils'; //默认超时时间为1分钟
|
|
5
|
+
import { getCache, getUrlQuery, setUrlQuery, getResourceProps, showError, toGatewayUrl, reLogin } from '../utils'; //默认超时时间为1分钟
|
|
6
6
|
|
|
7
7
|
var request = extend({
|
|
8
8
|
timeout: 60000
|
|
@@ -23,7 +23,8 @@ request.interceptors.request.use(function (url, options) {
|
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
var param = {
|
|
26
|
-
resCode: getUrlQuery('resCode') || getUrlQuery('resourceId') || getResourceProps('resourceId')
|
|
26
|
+
resCode: getUrlQuery('resCode') || getUrlQuery('resourceId') || getResourceProps('resourceId'),
|
|
27
|
+
t: Date.now()
|
|
27
28
|
};
|
|
28
29
|
return {
|
|
29
30
|
url: setUrlQuery(url, param),
|
|
@@ -34,7 +35,8 @@ request.interceptors.request.use(function (url, options) {
|
|
|
34
35
|
|
|
35
36
|
request.interceptors.response.use( /*#__PURE__*/function () {
|
|
36
37
|
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(response, options) {
|
|
37
|
-
var noMsg, data,
|
|
38
|
+
var noMsg, _data$flag, _data$flag2, data, retCode, retMsg, status;
|
|
39
|
+
|
|
38
40
|
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
39
41
|
while (1) {
|
|
40
42
|
switch (_context.prev = _context.next) {
|
|
@@ -47,12 +49,12 @@ request.interceptors.response.use( /*#__PURE__*/function () {
|
|
|
47
49
|
}
|
|
48
50
|
|
|
49
51
|
showError(options.url + response.statusText);
|
|
50
|
-
_context.next =
|
|
52
|
+
_context.next = 13;
|
|
51
53
|
break;
|
|
52
54
|
|
|
53
55
|
case 5:
|
|
54
56
|
if (!(noMsg != '1')) {
|
|
55
|
-
_context.next =
|
|
57
|
+
_context.next = 13;
|
|
56
58
|
break;
|
|
57
59
|
}
|
|
58
60
|
|
|
@@ -61,17 +63,22 @@ request.interceptors.response.use( /*#__PURE__*/function () {
|
|
|
61
63
|
|
|
62
64
|
case 8:
|
|
63
65
|
data = _context.sent;
|
|
64
|
-
flag = data.flag;
|
|
66
|
+
retCode = (data === null || data === void 0 ? void 0 : (_data$flag = data.flag) === null || _data$flag === void 0 ? void 0 : _data$flag.retCode) || '0';
|
|
67
|
+
retMsg = ((_data$flag2 = data.flag) === null || _data$flag2 === void 0 ? void 0 : _data$flag2.retMsg) || '访问接口出错';
|
|
65
68
|
status = (getUrlQuery('apiStatus') || '0').split(',');
|
|
66
69
|
|
|
67
|
-
if (
|
|
68
|
-
|
|
70
|
+
if (retCode && !status.includes(retCode)) {
|
|
71
|
+
if (retCode === 'timeout' || retCode === '4011') {
|
|
72
|
+
reLogin();
|
|
73
|
+
} else {
|
|
74
|
+
showError(retMsg);
|
|
75
|
+
}
|
|
69
76
|
}
|
|
70
77
|
|
|
71
|
-
case
|
|
78
|
+
case 13:
|
|
72
79
|
return _context.abrupt("return", response);
|
|
73
80
|
|
|
74
|
-
case
|
|
81
|
+
case 14:
|
|
75
82
|
case "end":
|
|
76
83
|
return _context.stop();
|
|
77
84
|
}
|
package/es/utils/index.d.ts
CHANGED
|
@@ -53,7 +53,7 @@ export declare const dateAdd: (dt: Date | null, addDay: number, addMonth?: numbe
|
|
|
53
53
|
* @param dec 小数位数,默认为2位小数
|
|
54
54
|
* @returns xx,xxx.xx
|
|
55
55
|
*/
|
|
56
|
-
export declare const formatMoney: (num: number, dec?: number) => string;
|
|
56
|
+
export declare const formatMoney: (num: number | string, dec?: number) => string;
|
|
57
57
|
/**
|
|
58
58
|
* 获取Cookie
|
|
59
59
|
* @param {String} name cookie名
|
|
@@ -85,7 +85,7 @@ export declare const setCache: (key: string, data: any, session?: boolean) => vo
|
|
|
85
85
|
* @param { boolean } session 从 sessionStorage 取数还是从 localStorage 中取数 默认从 localStorage
|
|
86
86
|
* @returns 关键字对应的值
|
|
87
87
|
*/
|
|
88
|
-
export declare const getCache:
|
|
88
|
+
export declare const getCache: (key: string, session?: boolean) => string | null;
|
|
89
89
|
/** @name 显示错误 */
|
|
90
90
|
export declare const showError: (text: string) => void;
|
|
91
91
|
/** @name 显示警示 */
|
|
@@ -94,6 +94,11 @@ export declare const showWarn: (text: string) => void;
|
|
|
94
94
|
export declare const showSuccess: (text: string) => void;
|
|
95
95
|
/** @name 显示确认 */
|
|
96
96
|
export declare const showConfirm: (text: string, title?: string) => Promise<unknown>;
|
|
97
|
+
/**
|
|
98
|
+
* token过期重新登录
|
|
99
|
+
* @returns
|
|
100
|
+
*/
|
|
101
|
+
export declare const reLogin: () => void;
|
|
97
102
|
/**
|
|
98
103
|
* 日期组选择转换
|
|
99
104
|
* @param values 选择的值
|
package/es/utils/index.js
CHANGED
|
@@ -108,6 +108,15 @@ export var dateAdd = function dateAdd(dt, addDay) {
|
|
|
108
108
|
|
|
109
109
|
export var formatMoney = function formatMoney(num) {
|
|
110
110
|
var dec = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 2;
|
|
111
|
+
|
|
112
|
+
if (typeof num !== 'number') {
|
|
113
|
+
num = Number(num);
|
|
114
|
+
|
|
115
|
+
if (Number.isNaN(num)) {
|
|
116
|
+
num = 0;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
111
120
|
var str = num.toFixed(dec);
|
|
112
121
|
|
|
113
122
|
if (str.indexOf('.') === -1) {
|
|
@@ -220,6 +229,26 @@ export var showConfirm = function showConfirm(text) {
|
|
|
220
229
|
});
|
|
221
230
|
});
|
|
222
231
|
};
|
|
232
|
+
var timeout = false;
|
|
233
|
+
/**
|
|
234
|
+
* token过期重新登录
|
|
235
|
+
* @returns
|
|
236
|
+
*/
|
|
237
|
+
|
|
238
|
+
export var reLogin = function reLogin() {
|
|
239
|
+
if (timeout) return;
|
|
240
|
+
timeout = true;
|
|
241
|
+
|
|
242
|
+
_Modal.warning({
|
|
243
|
+
title: '登录状态已过期,请重新登录',
|
|
244
|
+
okText: '重新登录',
|
|
245
|
+
maskClosable: false,
|
|
246
|
+
afterClose: function afterClose() {
|
|
247
|
+
timeout = false;
|
|
248
|
+
location.href = '/login?redirect=' + encodeURI(location.href);
|
|
249
|
+
}
|
|
250
|
+
});
|
|
251
|
+
};
|
|
223
252
|
/**
|
|
224
253
|
* 日期组选择转换
|
|
225
254
|
* @param values 选择的值
|
package/lib/http/index.js
CHANGED
|
@@ -42,7 +42,8 @@ request.interceptors.request.use(function (url, options) {
|
|
|
42
42
|
}
|
|
43
43
|
|
|
44
44
|
var param = {
|
|
45
|
-
resCode: (0, _utils.getUrlQuery)('resCode') || (0, _utils.getUrlQuery)('resourceId') || (0, _utils.getResourceProps)('resourceId')
|
|
45
|
+
resCode: (0, _utils.getUrlQuery)('resCode') || (0, _utils.getUrlQuery)('resourceId') || (0, _utils.getResourceProps)('resourceId'),
|
|
46
|
+
t: Date.now()
|
|
46
47
|
};
|
|
47
48
|
return {
|
|
48
49
|
url: (0, _utils.setUrlQuery)(url, param),
|
|
@@ -53,7 +54,8 @@ request.interceptors.request.use(function (url, options) {
|
|
|
53
54
|
|
|
54
55
|
request.interceptors.response.use( /*#__PURE__*/function () {
|
|
55
56
|
var _ref = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(response, options) {
|
|
56
|
-
var noMsg, data,
|
|
57
|
+
var noMsg, _data$flag, _data$flag2, data, retCode, retMsg, status;
|
|
58
|
+
|
|
57
59
|
return _regenerator.default.wrap(function _callee$(_context) {
|
|
58
60
|
while (1) {
|
|
59
61
|
switch (_context.prev = _context.next) {
|
|
@@ -66,12 +68,12 @@ request.interceptors.response.use( /*#__PURE__*/function () {
|
|
|
66
68
|
}
|
|
67
69
|
|
|
68
70
|
(0, _utils.showError)(options.url + response.statusText);
|
|
69
|
-
_context.next =
|
|
71
|
+
_context.next = 13;
|
|
70
72
|
break;
|
|
71
73
|
|
|
72
74
|
case 5:
|
|
73
75
|
if (!(noMsg != '1')) {
|
|
74
|
-
_context.next =
|
|
76
|
+
_context.next = 13;
|
|
75
77
|
break;
|
|
76
78
|
}
|
|
77
79
|
|
|
@@ -80,17 +82,22 @@ request.interceptors.response.use( /*#__PURE__*/function () {
|
|
|
80
82
|
|
|
81
83
|
case 8:
|
|
82
84
|
data = _context.sent;
|
|
83
|
-
flag = data.flag;
|
|
85
|
+
retCode = (data === null || data === void 0 ? void 0 : (_data$flag = data.flag) === null || _data$flag === void 0 ? void 0 : _data$flag.retCode) || '0';
|
|
86
|
+
retMsg = ((_data$flag2 = data.flag) === null || _data$flag2 === void 0 ? void 0 : _data$flag2.retMsg) || '访问接口出错';
|
|
84
87
|
status = ((0, _utils.getUrlQuery)('apiStatus') || '0').split(',');
|
|
85
88
|
|
|
86
|
-
if (
|
|
87
|
-
|
|
89
|
+
if (retCode && !status.includes(retCode)) {
|
|
90
|
+
if (retCode === 'timeout' || retCode === '4011') {
|
|
91
|
+
(0, _utils.reLogin)();
|
|
92
|
+
} else {
|
|
93
|
+
(0, _utils.showError)(retMsg);
|
|
94
|
+
}
|
|
88
95
|
}
|
|
89
96
|
|
|
90
|
-
case
|
|
97
|
+
case 13:
|
|
91
98
|
return _context.abrupt("return", response);
|
|
92
99
|
|
|
93
|
-
case
|
|
100
|
+
case 14:
|
|
94
101
|
case "end":
|
|
95
102
|
return _context.stop();
|
|
96
103
|
}
|
package/lib/utils/index.d.ts
CHANGED
|
@@ -53,7 +53,7 @@ export declare const dateAdd: (dt: Date | null, addDay: number, addMonth?: numbe
|
|
|
53
53
|
* @param dec 小数位数,默认为2位小数
|
|
54
54
|
* @returns xx,xxx.xx
|
|
55
55
|
*/
|
|
56
|
-
export declare const formatMoney: (num: number, dec?: number) => string;
|
|
56
|
+
export declare const formatMoney: (num: number | string, dec?: number) => string;
|
|
57
57
|
/**
|
|
58
58
|
* 获取Cookie
|
|
59
59
|
* @param {String} name cookie名
|
|
@@ -85,7 +85,7 @@ export declare const setCache: (key: string, data: any, session?: boolean) => vo
|
|
|
85
85
|
* @param { boolean } session 从 sessionStorage 取数还是从 localStorage 中取数 默认从 localStorage
|
|
86
86
|
* @returns 关键字对应的值
|
|
87
87
|
*/
|
|
88
|
-
export declare const getCache:
|
|
88
|
+
export declare const getCache: (key: string, session?: boolean) => string | null;
|
|
89
89
|
/** @name 显示错误 */
|
|
90
90
|
export declare const showError: (text: string) => void;
|
|
91
91
|
/** @name 显示警示 */
|
|
@@ -94,6 +94,11 @@ export declare const showWarn: (text: string) => void;
|
|
|
94
94
|
export declare const showSuccess: (text: string) => void;
|
|
95
95
|
/** @name 显示确认 */
|
|
96
96
|
export declare const showConfirm: (text: string, title?: string) => Promise<unknown>;
|
|
97
|
+
/**
|
|
98
|
+
* token过期重新登录
|
|
99
|
+
* @returns
|
|
100
|
+
*/
|
|
101
|
+
export declare const reLogin: () => void;
|
|
97
102
|
/**
|
|
98
103
|
* 日期组选择转换
|
|
99
104
|
* @param values 选择的值
|
package/lib/utils/index.js
CHANGED
|
@@ -25,7 +25,7 @@ Object.defineProperty(exports, "getUrlQuery", {
|
|
|
25
25
|
return _utils.getUrlQuery;
|
|
26
26
|
}
|
|
27
27
|
});
|
|
28
|
-
exports.setTitle = exports.setCookie = exports.setCache = exports.rangeToSearch = exports.nowAdd = exports.now = exports.isLogin = exports.isDev = exports.handleSizeCols = exports.getUserName = exports.getUserInfo = void 0;
|
|
28
|
+
exports.setTitle = exports.setCookie = exports.setCache = exports.reLogin = exports.rangeToSearch = exports.nowAdd = exports.now = exports.isLogin = exports.isDev = exports.handleSizeCols = exports.getUserName = exports.getUserInfo = void 0;
|
|
29
29
|
Object.defineProperty(exports, "setUrlQuery", {
|
|
30
30
|
enumerable: true,
|
|
31
31
|
get: function get() {
|
|
@@ -177,6 +177,15 @@ exports.dateAdd = dateAdd;
|
|
|
177
177
|
|
|
178
178
|
var formatMoney = function formatMoney(num) {
|
|
179
179
|
var dec = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 2;
|
|
180
|
+
|
|
181
|
+
if (typeof num !== 'number') {
|
|
182
|
+
num = Number(num);
|
|
183
|
+
|
|
184
|
+
if (Number.isNaN(num)) {
|
|
185
|
+
num = 0;
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
|
|
180
189
|
var str = num.toFixed(dec);
|
|
181
190
|
|
|
182
191
|
if (str.indexOf('.') === -1) {
|
|
@@ -316,6 +325,28 @@ var showConfirm = function showConfirm(text) {
|
|
|
316
325
|
});
|
|
317
326
|
});
|
|
318
327
|
};
|
|
328
|
+
|
|
329
|
+
exports.showConfirm = showConfirm;
|
|
330
|
+
var timeout = false;
|
|
331
|
+
/**
|
|
332
|
+
* token过期重新登录
|
|
333
|
+
* @returns
|
|
334
|
+
*/
|
|
335
|
+
|
|
336
|
+
var reLogin = function reLogin() {
|
|
337
|
+
if (timeout) return;
|
|
338
|
+
timeout = true;
|
|
339
|
+
|
|
340
|
+
_modal.default.warning({
|
|
341
|
+
title: '登录状态已过期,请重新登录',
|
|
342
|
+
okText: '重新登录',
|
|
343
|
+
maskClosable: false,
|
|
344
|
+
afterClose: function afterClose() {
|
|
345
|
+
timeout = false;
|
|
346
|
+
location.href = '/login?redirect=' + encodeURI(location.href);
|
|
347
|
+
}
|
|
348
|
+
});
|
|
349
|
+
};
|
|
319
350
|
/**
|
|
320
351
|
* 日期组选择转换
|
|
321
352
|
* @param values 选择的值
|
|
@@ -326,7 +357,7 @@ var showConfirm = function showConfirm(text) {
|
|
|
326
357
|
*/
|
|
327
358
|
|
|
328
359
|
|
|
329
|
-
exports.
|
|
360
|
+
exports.reLogin = reLogin;
|
|
330
361
|
|
|
331
362
|
var rangeToSearch = function rangeToSearch(values, startField, endField) {
|
|
332
363
|
var endSuffix = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : '';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ls-pro-common",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.40",
|
|
4
4
|
"description": "ls-pro-common",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"antd",
|
|
@@ -28,8 +28,8 @@
|
|
|
28
28
|
],
|
|
29
29
|
"dependencies": {
|
|
30
30
|
"@ant-design/icons": "^4.3.0",
|
|
31
|
-
"ls-pro-table": "2.62.
|
|
32
|
-
"ls-pro-form": "1.52.
|
|
31
|
+
"ls-pro-table": "2.62.31",
|
|
32
|
+
"ls-pro-form": "1.52.26",
|
|
33
33
|
"@babel/runtime": "^7.16.3",
|
|
34
34
|
"classnames": "^2.2.6",
|
|
35
35
|
"moment": "^2.27.0",
|