byt-ui 0.1.9 → 0.1.10

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "byt-ui",
3
- "version": "0.1.9",
3
+ "version": "0.1.10",
4
4
  "private": false,
5
5
  "description": "byt组件库",
6
6
  "author": {
@@ -3,9 +3,9 @@ import { Message } from 'element-ui'
3
3
  import { getCookie } from './cookie'
4
4
 
5
5
  class Request {
6
- constructor(config = {}) {
6
+ constructor(config = {}, Vue = null) {
7
7
  const { options = {}, handler = {}} = config;
8
- this.request = null;
8
+ this._Vue = Vue || null;
9
9
  this._errorCode = {
10
10
  '000': '操作太频繁,请勿重复请求',
11
11
  '401': '当前操作没有权限',
@@ -13,8 +13,9 @@ class Request {
13
13
  '404': '接口不存在',
14
14
  '417': '未绑定登录账号,请使用密码登录后绑定',
15
15
  '423': '演示环境不能操作,如需了解联系我们',
16
+ '424': 'token过期,请重新登录',
16
17
  '426': '用户名不存在或密码错误',
17
- '428': '验证码错误,请重新输入',
18
+ '428': 'token过期,请重新登录',
18
19
  '429': '请求过频繁',
19
20
  '479': '演示环境,没有权限操作',
20
21
  'default': '系统未知错误,请反馈给管理员'
@@ -27,6 +28,8 @@ class Request {
27
28
  timeout: 60000,
28
29
  withCredentials: false
29
30
  }, options)
31
+
32
+ this.request = axios.create(this.options)
30
33
  // 注册fetch;
31
34
  this.register()
32
35
  }
@@ -56,19 +59,22 @@ class Request {
56
59
  case 200:
57
60
  if (res.data.code === 1) {
58
61
  Message.error(message)
59
- this.handler.error && this.handler.error(res.data);
60
62
  return Promise.reject(res.data)
61
63
  }
62
- this.handler.success && this.handler.success(res.data)
64
+ this.handler.success && this.handler.success(res.data);
63
65
  return res.data
64
66
  case 424:
65
67
  case 428:
66
68
  // 后台定义 424||428 针对令牌过期的特殊响应码
67
69
  this.handler.expire && this.handler.expire(res.data);
70
+ Message.error(message);
71
+ if (window.__POWERED_BY_QIANKUN__ && this._Vue) {
72
+ const { outLogin } = this._Vue.prototype.$appCommon;
73
+ outLogin && outLogin();
74
+ }
68
75
  break;
69
76
  default:
70
77
  Message.error(message);
71
- this.handler.error && this.handler.error(res.data);
72
78
  return Promise.reject(message)
73
79
  }
74
80
  }, error => {
@@ -82,7 +88,7 @@ class Request {
82
88
  Message.error(error.response.data.msg)
83
89
  break;
84
90
  }
85
- this.error && this.error(error.response);
91
+ this.handler.error && this.handler.error(error.response);
86
92
  }
87
93
  return Promise.reject(new Error(error))
88
94
  })
@@ -138,8 +144,6 @@ class Request {
138
144
  }
139
145
 
140
146
  register() {
141
- this.request = axios.create(this.options)
142
-
143
147
  // 添加拦截器
144
148
  this.interceptors();
145
149
 
@@ -148,12 +152,14 @@ class Request {
148
152
  }
149
153
  }
150
154
 
151
- export const { request } = new Request()
155
+ export const fetch = (config = {}, Vue) => {
156
+ const { request } = new Request(Object.assign({}, config), Vue)
157
+ return request
158
+ }
152
159
 
153
160
  export default {
154
- install(Vue, options = {}) {
155
- const { request } = new Request(Object.assign({}, options))
156
- Vue.prototype.$http = request
161
+ install(Vue, config = {}) {
162
+ Vue.prototype.$http = fetch(config, Vue)
157
163
  }
158
164
  }
159
165