ls-pro-common 1.0.39 → 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/es/http/index.js CHANGED
@@ -1,15 +1,12 @@
1
1
  import _regeneratorRuntime from "@babel/runtime/regenerator";
2
- import "antd/es/modal/style";
3
- import _Modal from "antd/es/modal";
4
2
  import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
5
3
  import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
6
4
  import { extend } from 'umi-request';
7
- import { getCache, getUrlQuery, setUrlQuery, getResourceProps, showError, toGatewayUrl } from '../utils';
8
- //默认超时时间为1分钟
5
+ import { getCache, getUrlQuery, setUrlQuery, getResourceProps, showError, toGatewayUrl, reLogin } from '../utils'; //默认超时时间为1分钟
6
+
9
7
  var request = extend({
10
8
  timeout: 60000
11
9
  });
12
- var showLogin = false;
13
10
  /** 请求拦截器,统一添加token */
14
11
 
15
12
  request.interceptors.request.use(function (url, options) {
@@ -72,18 +69,7 @@ request.interceptors.response.use( /*#__PURE__*/function () {
72
69
 
73
70
  if (retCode && !status.includes(retCode)) {
74
71
  if (retCode === 'timeout' || retCode === '4011') {
75
- if (!showLogin) {
76
- showLogin = true;
77
-
78
- _Modal.warning({
79
- title: '登录状态已过期,请重新登录',
80
- okText: '重新登录',
81
- afterClose: function afterClose() {
82
- location.href = '/login?redirect=' + encodeURI(location.href);
83
- showLogin = false;
84
- }
85
- });
86
- }
72
+ reLogin();
87
73
  } else {
88
74
  showError(retMsg);
89
75
  }
@@ -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: any;
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
@@ -229,6 +229,26 @@ export var showConfirm = function showConfirm(text) {
229
229
  });
230
230
  });
231
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
+ };
232
252
  /**
233
253
  * 日期组选择转换
234
254
  * @param values 选择的值
package/lib/http/index.js CHANGED
@@ -15,10 +15,6 @@ exports.httpPut = httpPut;
15
15
 
16
16
  var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
17
17
 
18
- require("antd/es/modal/style");
19
-
20
- var _modal = _interopRequireDefault(require("antd/es/modal"));
21
-
22
18
  var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
23
19
 
24
20
  var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
@@ -31,7 +27,6 @@ var _utils = require("../utils");
31
27
  var request = (0, _umiRequest.extend)({
32
28
  timeout: 60000
33
29
  });
34
- var showLogin = false;
35
30
  /** 请求拦截器,统一添加token */
36
31
 
37
32
  request.interceptors.request.use(function (url, options) {
@@ -93,18 +88,7 @@ request.interceptors.response.use( /*#__PURE__*/function () {
93
88
 
94
89
  if (retCode && !status.includes(retCode)) {
95
90
  if (retCode === 'timeout' || retCode === '4011') {
96
- if (!showLogin) {
97
- showLogin = true;
98
-
99
- _modal.default.warning({
100
- title: '登录状态已过期,请重新登录',
101
- okText: '重新登录',
102
- afterClose: function afterClose() {
103
- location.href = '/login?redirect=' + encodeURI(location.href);
104
- showLogin = false;
105
- }
106
- });
107
- }
91
+ (0, _utils.reLogin)();
108
92
  } else {
109
93
  (0, _utils.showError)(retMsg);
110
94
  }
@@ -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: any;
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 选择的值
@@ -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() {
@@ -325,6 +325,28 @@ var showConfirm = function showConfirm(text) {
325
325
  });
326
326
  });
327
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
+ };
328
350
  /**
329
351
  * 日期组选择转换
330
352
  * @param values 选择的值
@@ -335,7 +357,7 @@ var showConfirm = function showConfirm(text) {
335
357
  */
336
358
 
337
359
 
338
- exports.showConfirm = showConfirm;
360
+ exports.reLogin = reLogin;
339
361
 
340
362
  var rangeToSearch = function rangeToSearch(values, startField, endField) {
341
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.39",
3
+ "version": "1.0.40",
4
4
  "description": "ls-pro-common",
5
5
  "keywords": [
6
6
  "antd",