zmdms-utils 0.0.56 → 0.0.57

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.
@@ -40,6 +40,10 @@ interface IOptions extends AxiosRequestConfig {
40
40
  * 实例返回信息 简化处理
41
41
  */
42
42
  isEasyMessage?: boolean;
43
+ /**
44
+ * 登录过期是否交给自己处理
45
+ */
46
+ isHandleLoginExpiration?: boolean;
43
47
  }
44
48
  interface IOtherOptions {
45
49
  /** token过期等 需要跳转到登录页 */
@@ -117,16 +117,18 @@ var AxiosRequest = /** @class */ (function () {
117
117
  // 响应错误处理
118
118
  AxiosRequest.prototype.responseError = function (error) {
119
119
  var _this = this;
120
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r;
120
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s;
121
121
  if (error === void 0) { error = {}; }
122
122
  var response = error.response;
123
+ // 登录过期是否自己处理
124
+ var isHandleLoginExpiration = (_a = error === null || error === void 0 ? void 0 : error.config) === null || _a === void 0 ? void 0 : _a.isHandleLoginExpiration;
123
125
  // 处理token失效
124
126
  // TODO: 刷新token逻辑
125
- if ((response === null || response === void 0 ? void 0 : response.status) === 401) {
127
+ if ((response === null || response === void 0 ? void 0 : response.status) === 401 && !isHandleLoginExpiration) {
126
128
  removeToken();
127
129
  if (!this.isExpired) {
128
130
  this.isExpired = true;
129
- (_a = this.messageWarning) === null || _a === void 0 ? void 0 : _a.call(this, "登录过期", 3.5, function () {
131
+ (_b = this.messageWarning) === null || _b === void 0 ? void 0 : _b.call(this, "登录过期", 3.5, function () {
130
132
  _this.isExpired = false;
131
133
  });
132
134
  this.logoutHandle(response.status);
@@ -134,11 +136,11 @@ var AxiosRequest = /** @class */ (function () {
134
136
  return;
135
137
  }
136
138
  // 处理被挤下线逻辑
137
- if ((response === null || response === void 0 ? void 0 : response.status) === 501) {
139
+ if ((response === null || response === void 0 ? void 0 : response.status) === 501 && !isHandleLoginExpiration) {
138
140
  removeToken();
139
141
  if (!this.isOffline) {
140
142
  this.isOffline = true;
141
- (_b = this.messageWarning) === null || _b === void 0 ? void 0 : _b.call(this, "你的账号已在其他地方登录!", 3.5, function () {
143
+ (_c = this.messageWarning) === null || _c === void 0 ? void 0 : _c.call(this, "你的账号已在其他地方登录!", 3.5, function () {
142
144
  _this.isOffline = false;
143
145
  });
144
146
  this.logoutHandle(response.status);
@@ -149,7 +151,7 @@ var AxiosRequest = /** @class */ (function () {
149
151
  if ((response === null || response === void 0 ? void 0 : response.status) === 404) {
150
152
  if (!this.isNotFound) {
151
153
  this.isNotFound = true;
152
- (_c = this.messageWarning) === null || _c === void 0 ? void 0 : _c.call(this, "\u63A5\u53E3\uFF1A".concat(response.config.url, " \u672A\u627E\u5230\uFF01"), 3.5, function () {
154
+ (_d = this.messageWarning) === null || _d === void 0 ? void 0 : _d.call(this, "\u63A5\u53E3\uFF1A".concat(response.config.url, " \u672A\u627E\u5230\uFF01"), 3.5, function () {
153
155
  _this.isNotFound = false;
154
156
  });
155
157
  }
@@ -157,24 +159,24 @@ var AxiosRequest = /** @class */ (function () {
157
159
  }
158
160
  // 处理接口超时逻辑
159
161
  if (this.isTimeoutConfirm &&
160
- ((_f = (_e = (_d = error === null || error === void 0 ? void 0 : error.config) === null || _d === void 0 ? void 0 : _d.method) === null || _e === void 0 ? void 0 : _e.toUpperCase) === null || _f === void 0 ? void 0 : _f.call(_e)) === "POST" &&
162
+ ((_g = (_f = (_e = error === null || error === void 0 ? void 0 : error.config) === null || _e === void 0 ? void 0 : _e.method) === null || _f === void 0 ? void 0 : _f.toUpperCase) === null || _g === void 0 ? void 0 : _g.call(_f)) === "POST" &&
161
163
  !response &&
162
164
  error.code === "ECONNABORTED" &&
163
- ((_h = (_g = error.message) === null || _g === void 0 ? void 0 : _g.indexOf) === null || _h === void 0 ? void 0 : _h.call(_g, "".concat(error.config.timeout, "ms"))) !== -1) {
165
+ ((_j = (_h = error.message) === null || _h === void 0 ? void 0 : _h.indexOf) === null || _j === void 0 ? void 0 : _j.call(_h, "".concat(error.config.timeout, "ms"))) !== -1) {
164
166
  if (!this.isTimeout) {
165
167
  this.isTimeout = true;
166
- (_j = this.modalConfirm) === null || _j === void 0 ? void 0 : _j.call(this, "".concat(this.isTimeoutConfirmStr
168
+ (_k = this.modalConfirm) === null || _k === void 0 ? void 0 : _k.call(this, "".concat(this.isTimeoutConfirmStr
167
169
  ? this.isTimeoutConfirmStr
168
- : "请求超时,请稍后再试,或联系相关人员确认后处理!", "\n \u63A5\u53E3\u5730\u5740: ").concat((_k = error === null || error === void 0 ? void 0 : error.config) === null || _k === void 0 ? void 0 : _k.url, "\n \u8BF7\u6C42\u65B9\u5F0F: ").concat((_l = error === null || error === void 0 ? void 0 : error.config) === null || _l === void 0 ? void 0 : _l.method, "\n \u8BF7\u6C42\u8D85\u65F6\u65F6\u95F4: ").concat(((_m = error === null || error === void 0 ? void 0 : error.config) === null || _m === void 0 ? void 0 : _m.timeout) / 1000, "\u79D2\n "), function () {
170
+ : "请求超时,请稍后再试,或联系相关人员确认后处理!", "\n \u63A5\u53E3\u5730\u5740: ").concat((_l = error === null || error === void 0 ? void 0 : error.config) === null || _l === void 0 ? void 0 : _l.url, "\n \u8BF7\u6C42\u65B9\u5F0F: ").concat((_m = error === null || error === void 0 ? void 0 : error.config) === null || _m === void 0 ? void 0 : _m.method, "\n \u8BF7\u6C42\u8D85\u65F6\u65F6\u95F4: ").concat(((_o = error === null || error === void 0 ? void 0 : error.config) === null || _o === void 0 ? void 0 : _o.timeout) / 1000, "\u79D2\n "), function () {
169
171
  _this.isTimeout = false;
170
172
  });
171
173
  }
172
174
  return;
173
175
  }
174
176
  // 提示业务错误
175
- if ((_o = error === null || error === void 0 ? void 0 : error.config) === null || _o === void 0 ? void 0 : _o.isErrorMessage) {
177
+ if ((_p = error === null || error === void 0 ? void 0 : error.config) === null || _p === void 0 ? void 0 : _p.isErrorMessage) {
176
178
  // 详细信息 再开发模式开启 之后上到别的环境会去掉
177
- (_p = this.modalConfirm) === null || _p === void 0 ? void 0 : _p.call(this, "".concat(((_r = (_q = error === null || error === void 0 ? void 0 : error.response) === null || _q === void 0 ? void 0 : _q.data) === null || _r === void 0 ? void 0 : _r.msg) || (error === null || error === void 0 ? void 0 : error.msg) || "服务器异常"));
179
+ (_q = this.modalConfirm) === null || _q === void 0 ? void 0 : _q.call(this, "".concat(((_s = (_r = error === null || error === void 0 ? void 0 : error.response) === null || _r === void 0 ? void 0 : _r.data) === null || _s === void 0 ? void 0 : _s.msg) || (error === null || error === void 0 ? void 0 : error.msg) || "服务器异常"));
178
180
  // 接口地址: ${error?.config?.url}
179
181
  // 响应状态码: ${error?.response?.status}
180
182
  // 请求方式: ${error?.config?.method}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zmdms-utils",
3
- "version": "0.0.56",
3
+ "version": "0.0.57",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",
package/src/request.ts CHANGED
@@ -152,9 +152,11 @@ export class AxiosRequest {
152
152
  // 响应错误处理
153
153
  private responseError(error: any = {}) {
154
154
  const { response } = error;
155
+ // 登录过期是否自己处理
156
+ const isHandleLoginExpiration = error?.config?.isHandleLoginExpiration;
155
157
  // 处理token失效
156
158
  // TODO: 刷新token逻辑
157
- if (response?.status === 401) {
159
+ if (response?.status === 401 && !isHandleLoginExpiration) {
158
160
  removeToken();
159
161
  if (!this.isExpired) {
160
162
  this.isExpired = true;
@@ -166,7 +168,7 @@ export class AxiosRequest {
166
168
  return;
167
169
  }
168
170
  // 处理被挤下线逻辑
169
- if (response?.status === 501) {
171
+ if (response?.status === 501 && !isHandleLoginExpiration) {
170
172
  removeToken();
171
173
  if (!this.isOffline) {
172
174
  this.isOffline = true;
@@ -360,6 +362,10 @@ export interface IOptions extends AxiosRequestConfig {
360
362
  * 实例返回信息 简化处理
361
363
  */
362
364
  isEasyMessage?: boolean;
365
+ /**
366
+ * 登录过期是否交给自己处理
367
+ */
368
+ isHandleLoginExpiration?: boolean;
363
369
  }
364
370
 
365
371
  export interface IOtherOptions {