byt-ui 0.1.14 → 0.1.15
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/lib/byt-ui.common.js +16 -10
- package/lib/byt-ui.umd.js +16 -10
- package/lib/byt-ui.umd.min.js +1 -1
- package/package.json +1 -1
- package/packages/common/modules/request.js +17 -12
package/package.json
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import axios from 'axios'
|
|
2
2
|
import { Message } from 'element-ui'
|
|
3
3
|
import { getCookie } from './cookie'
|
|
4
|
-
|
|
5
4
|
class Request {
|
|
6
5
|
constructor(config = {}, Vue = null) {
|
|
7
6
|
const { options = {}, handler = {}} = config;
|
|
@@ -18,6 +17,7 @@ class Request {
|
|
|
18
17
|
'428': 'token过期,请重新登录',
|
|
19
18
|
'429': '请求过频繁',
|
|
20
19
|
'479': '演示环境,没有权限操作',
|
|
20
|
+
'503': '服务未启动,请联系管理员处理',
|
|
21
21
|
'default': '系统未知错误,请反馈给管理员'
|
|
22
22
|
}
|
|
23
23
|
this._methods = ['get', 'post', 'delete', 'put']
|
|
@@ -26,17 +26,22 @@ class Request {
|
|
|
26
26
|
baseURL: '/bytserver',
|
|
27
27
|
responseType: 'json',
|
|
28
28
|
timeout: 60000,
|
|
29
|
-
|
|
29
|
+
showError: true,
|
|
30
|
+
withCredentials: false,
|
|
31
|
+
validateStatus(status) {
|
|
32
|
+
// >=200或者<=500的统一由成功拦截处理
|
|
33
|
+
return status >= 200 && status <= 500 // 默认的
|
|
34
|
+
}
|
|
30
35
|
}, options)
|
|
31
36
|
|
|
32
|
-
this.
|
|
37
|
+
this._request = axios.create(this.options)
|
|
33
38
|
// 注册fetch;
|
|
34
39
|
this.register()
|
|
35
40
|
}
|
|
36
41
|
|
|
37
42
|
interceptors() {
|
|
38
43
|
// HTTPrequest拦截
|
|
39
|
-
this.
|
|
44
|
+
this._request.interceptors.request.use(config => {
|
|
40
45
|
const TENANT_ID = getCookie('tenantId')
|
|
41
46
|
const isToken = (config.headers || {}).isToken === false
|
|
42
47
|
const token = getCookie('access_token')
|
|
@@ -51,7 +56,7 @@ class Request {
|
|
|
51
56
|
})
|
|
52
57
|
|
|
53
58
|
// HTTPresponse拦截
|
|
54
|
-
this.
|
|
59
|
+
this._request.interceptors.response.use(res => {
|
|
55
60
|
const status = Number(res.status) || 200
|
|
56
61
|
const message = res.data.msg || this._errorCode[status] || this._errorCode['default']
|
|
57
62
|
if (status == 424 || status == 428) {
|
|
@@ -61,7 +66,7 @@ class Request {
|
|
|
61
66
|
const { outLogin } = this._Vue.prototype.$appCommon;
|
|
62
67
|
outLogin && outLogin();
|
|
63
68
|
}
|
|
64
|
-
return res.data
|
|
69
|
+
return Promise.reject(res.data)
|
|
65
70
|
}
|
|
66
71
|
if (status !== 200 || res.data.code === 1) {
|
|
67
72
|
if (res.config.showError) Message.error(message)
|
|
@@ -70,7 +75,7 @@ class Request {
|
|
|
70
75
|
|
|
71
76
|
this.handler.success && this.handler.success(res.data);
|
|
72
77
|
return res.data
|
|
73
|
-
}, error => {
|
|
78
|
+
}, (error) => {
|
|
74
79
|
if (error.response) {
|
|
75
80
|
// const status = error.response.status
|
|
76
81
|
const message = error.response.data.msg;
|
|
@@ -91,7 +96,7 @@ class Request {
|
|
|
91
96
|
}
|
|
92
97
|
setMethods() {
|
|
93
98
|
this._methods.forEach(v => {
|
|
94
|
-
this.
|
|
99
|
+
this._request[v] = ({
|
|
95
100
|
url,
|
|
96
101
|
data = {},
|
|
97
102
|
params = {},
|
|
@@ -101,7 +106,7 @@ class Request {
|
|
|
101
106
|
showError
|
|
102
107
|
}) => {
|
|
103
108
|
return new Promise((resolve, reject) => {
|
|
104
|
-
this.
|
|
109
|
+
this._request({
|
|
105
110
|
url,
|
|
106
111
|
method: v.toUpperCase(),
|
|
107
112
|
data,
|
|
@@ -124,7 +129,7 @@ class Request {
|
|
|
124
129
|
// 重试请求
|
|
125
130
|
reject(err)
|
|
126
131
|
if (retry > 0) {
|
|
127
|
-
this.
|
|
132
|
+
this._request[v]({
|
|
128
133
|
url,
|
|
129
134
|
data,
|
|
130
135
|
params,
|
|
@@ -150,8 +155,8 @@ class Request {
|
|
|
150
155
|
}
|
|
151
156
|
|
|
152
157
|
export const fetch = (config = {}, Vue) => {
|
|
153
|
-
const {
|
|
154
|
-
return
|
|
158
|
+
const { _request } = new Request(Object.assign({}, config), Vue)
|
|
159
|
+
return _request
|
|
155
160
|
}
|
|
156
161
|
|
|
157
162
|
export default {
|