vue2-client 1.3.14 → 1.3.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/CHANGELOG.md +315 -311
- package/index.js +30 -30
- package/package.json +76 -76
- package/src/base-client/components/common/AddressSearchCombobox/AddressSearchCombobox.vue +225 -225
- package/src/base-client/components/common/CreateQuery/CreateQuery.vue +551 -551
- package/src/base-client/components/common/CreateQuery/CreateQueryItem.vue +777 -777
- package/src/base-client/components/common/CreateSimpleFormQuery/CreateSimpleFormQueryItem.vue +553 -553
- package/src/base-client/components/common/CustomColumnsDrawer/index.md +46 -46
- package/src/base-client/components/common/FormGroupQuery/FormGroupQuery.vue +165 -165
- package/src/base-client/components/common/JSONToTree/jsontotree.vue +275 -275
- package/src/base-client/components/common/Upload/Upload.vue +165 -161
- package/src/base-client/components/common/XAddForm/XAddForm.vue +353 -353
- package/src/base-client/components/common/XAddNativeForm/XAddNativeForm.vue +326 -326
- package/src/base-client/components/common/XCard/XCard.vue +64 -64
- package/src/base-client/components/common/XForm/XForm.vue +273 -273
- package/src/base-client/components/common/XForm/XFormItem.vue +389 -389
- package/src/base-client/components/common/XFormTable/index.md +96 -96
- package/src/base-client/components/common/XTable/XTable.vue +278 -278
- package/src/base-client/components/system/LogDetailsView/LogDetailsView.vue +376 -376
- package/src/base-client/components/system/QueryParamsDetailsView/QueryParamsDetailsView.vue +281 -281
- package/src/base-client/components/ticket/TicketDetailsView/TicketDetailsView.vue +807 -807
- package/src/base-client/components/ticket/TicketDetailsView/index.md +29 -29
- package/src/base-client/components/ticket/TicketDetailsView/part/TicketDetailsFlow.vue +260 -260
- package/src/base-client/components/ticket/TicketSubmitSuccessView/TicketSubmitSuccessView.vue +532 -532
- package/src/base-client/components/ticket/TicketSubmitSuccessView/index.md +29 -29
- package/src/base-client/plugins/AppData.js +69 -69
- package/src/base-client/plugins/GetLoginInfoService.js +179 -179
- package/src/base-client/plugins/PagedList.js +177 -177
- package/src/base-client/plugins/compatible/LoginServiceOA.js +20 -20
- package/src/base-client/plugins/i18n-extend.js +32 -32
- package/src/components/Ellipsis/index.md +38 -38
- package/src/components/NumberInfo/index.md +43 -43
- package/src/components/STable/README.md +341 -341
- package/src/components/STable/index.js +318 -318
- package/src/components/Trend/index.md +45 -45
- package/src/components/checkbox/ColorCheckbox.vue +157 -157
- package/src/components/checkbox/ImgCheckbox.vue +163 -163
- package/src/components/exception/ExceptionPage.vue +70 -70
- package/src/components/form/FormRow.vue +52 -52
- package/src/components/index.js +36 -36
- package/src/components/menu/SideMenu.vue +62 -62
- package/src/components/menu/menu.js +273 -273
- package/src/components/setting/Setting.vue +235 -235
- package/src/components/table/StandardTable.vue +141 -141
- package/src/components/table/advance/ActionColumns.vue +158 -158
- package/src/components/table/advance/SearchArea.vue +355 -355
- package/src/components/tool/AStepItem.vue +60 -60
- package/src/components/tool/AvatarList.vue +68 -68
- package/src/components/tool/Drawer.vue +142 -142
- package/src/components/tool/TagSelect.vue +83 -83
- package/src/components/transition/PageToggleTransition.vue +97 -97
- package/src/config/replacer/resolve.config.js +67 -67
- package/src/layouts/AdminLayout.vue +174 -174
- package/src/layouts/header/AdminHeader.vue +104 -104
- package/src/layouts/header/HeaderNotice.vue +167 -167
- package/src/layouts/header/HeaderSearch.vue +67 -67
- package/src/layouts/header/InstitutionDetail.vue +181 -181
- package/src/layouts/tabs/TabsHead.vue +190 -190
- package/src/layouts/tabs/TabsView.vue +379 -379
- package/src/mock/goods/index.js +108 -108
- package/src/pages/CreateQueryPage.vue +65 -65
- package/src/pages/login/Login.vue +277 -277
- package/src/pages/report/ReportTable.js +124 -124
- package/src/pages/report/ReportTableHome.vue +28 -28
- package/src/pages/resourceManage/orgListManage.vue +98 -98
- package/src/pages/system/dictionary/index.vue +43 -43
- package/src/pages/system/file/index.vue +317 -317
- package/src/pages/system/queryParams/index.vue +43 -43
- package/src/pages/system/ticket/index.vue +461 -461
- package/src/pages/system/ticket/submitTicketSuccess.vue +206 -206
- package/src/router/async/config.async.js +27 -27
- package/src/router/async/router.map.js +56 -56
- package/src/router/index.js +27 -27
- package/src/services/api/DictionaryDetailsViewApi.js +6 -6
- package/src/services/api/LogDetailsViewApi.js +10 -10
- package/src/services/api/QueryParamsDetailsViewApi.js +6 -6
- package/src/services/api/TicketDetailsViewApi.js +34 -34
- package/src/services/api/common.js +58 -58
- package/src/services/api/commonTempTable.js +10 -10
- package/src/services/api/index.js +17 -17
- package/src/services/api/manage.js +8 -8
- package/src/store/mutation-types.js +2 -2
- package/src/theme/default/nprogress.less +76 -76
- package/src/theme/default/style.less +47 -47
- package/src/utils/colors.js +103 -103
- package/src/utils/excel/Blob.js +180 -180
- package/src/utils/excel/Export2Excel.js +141 -141
- package/src/utils/formatter.js +68 -68
- package/src/utils/i18n.js +80 -80
- package/src/utils/request.js +225 -225
- package/src/utils/routerUtil.js +358 -358
- package/src/utils/theme-color-replacer-extend.js +91 -91
- package/src/utils/themeUtil.js +100 -100
- package/src/utils/util.js +230 -230
- package/vue.config.js +99 -99
package/src/utils/request.js
CHANGED
|
@@ -1,225 +1,225 @@
|
|
|
1
|
-
import axios from 'axios'
|
|
2
|
-
import Cookie from 'js-cookie'
|
|
3
|
-
import Vue from 'vue'
|
|
4
|
-
import { ACCESS_TOKEN, V4_ACCESS_TOKEN } from '@vue2-client/store/mutation-types'
|
|
5
|
-
import notification from 'ant-design-vue/es/notification'
|
|
6
|
-
|
|
7
|
-
let compatible
|
|
8
|
-
|
|
9
|
-
// 跨域认证信息 header 名
|
|
10
|
-
const xsrfHeaderName = 'Authorization'
|
|
11
|
-
|
|
12
|
-
axios.defaults.timeout = 5000
|
|
13
|
-
axios.defaults.withCredentials = true
|
|
14
|
-
axios.defaults.xsrfHeaderName = xsrfHeaderName
|
|
15
|
-
axios.defaults.xsrfCookieName = xsrfHeaderName
|
|
16
|
-
|
|
17
|
-
// 认证类型
|
|
18
|
-
const AUTH_TYPE = {
|
|
19
|
-
BEARER: 'Bearer',
|
|
20
|
-
BASIC: 'basic',
|
|
21
|
-
AUTH1: 'auth1',
|
|
22
|
-
AUTH2: 'auth2'
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
// http method
|
|
26
|
-
const METHOD = {
|
|
27
|
-
GET: 'get',
|
|
28
|
-
POST: 'post'
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* axios请求
|
|
33
|
-
* @param url 请求地址
|
|
34
|
-
* @param method {METHOD} http method
|
|
35
|
-
* @param params 请求参数
|
|
36
|
-
* @param config
|
|
37
|
-
* @returns {Promise<AxiosResponse<T>>}
|
|
38
|
-
*/
|
|
39
|
-
async function request (url, method, params, config) {
|
|
40
|
-
switch (method) {
|
|
41
|
-
case METHOD.GET:
|
|
42
|
-
return axios.get(url, { params, ...config })
|
|
43
|
-
case METHOD.POST:
|
|
44
|
-
return axios.post(url, params, config)
|
|
45
|
-
default:
|
|
46
|
-
return axios.get(url, { params, ...config })
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* 设置认证信息
|
|
52
|
-
* @param auth {Object}
|
|
53
|
-
* @param authType {AUTH_TYPE} 认证类型,默认:{AUTH_TYPE.BEARER}
|
|
54
|
-
*/
|
|
55
|
-
function setAuthorization (auth, authType = AUTH_TYPE.BEARER) {
|
|
56
|
-
switch (authType) {
|
|
57
|
-
case AUTH_TYPE.BEARER:
|
|
58
|
-
if (auth.token) {
|
|
59
|
-
Cookie.set(xsrfHeaderName, 'Bearer ' + auth.token, { expires: auth.expireAt })
|
|
60
|
-
}
|
|
61
|
-
break
|
|
62
|
-
case AUTH_TYPE.BASIC:
|
|
63
|
-
case AUTH_TYPE.AUTH1:
|
|
64
|
-
case AUTH_TYPE.AUTH2:
|
|
65
|
-
default:
|
|
66
|
-
break
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
/**
|
|
71
|
-
* 移出认证信息
|
|
72
|
-
* @param authType {AUTH_TYPE} 认证类型
|
|
73
|
-
*/
|
|
74
|
-
function removeAuthorization (authType = AUTH_TYPE.BEARER) {
|
|
75
|
-
switch (authType) {
|
|
76
|
-
case AUTH_TYPE.BEARER:
|
|
77
|
-
Cookie.remove(xsrfHeaderName)
|
|
78
|
-
break
|
|
79
|
-
case AUTH_TYPE.BASIC:
|
|
80
|
-
case AUTH_TYPE.AUTH1:
|
|
81
|
-
case AUTH_TYPE.AUTH2:
|
|
82
|
-
default:
|
|
83
|
-
break
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
/**
|
|
88
|
-
* 检查认证信息
|
|
89
|
-
* @param authType
|
|
90
|
-
* @returns {boolean}
|
|
91
|
-
*/
|
|
92
|
-
function checkAuthorization (authType = AUTH_TYPE.BEARER) {
|
|
93
|
-
switch (authType) {
|
|
94
|
-
case AUTH_TYPE.BEARER:
|
|
95
|
-
if (Cookie.get(xsrfHeaderName)) {
|
|
96
|
-
return true
|
|
97
|
-
}
|
|
98
|
-
break
|
|
99
|
-
case AUTH_TYPE.BASIC:
|
|
100
|
-
case AUTH_TYPE.AUTH1:
|
|
101
|
-
case AUTH_TYPE.AUTH2:
|
|
102
|
-
default:
|
|
103
|
-
break
|
|
104
|
-
}
|
|
105
|
-
return false
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
/**
|
|
109
|
-
* 加载 axios 拦截器
|
|
110
|
-
* @param interceptors
|
|
111
|
-
* @param options
|
|
112
|
-
*/
|
|
113
|
-
function loadInterceptors () {
|
|
114
|
-
// 加载请求拦截器
|
|
115
|
-
axios.interceptors.request.use(config => {
|
|
116
|
-
const token = localStorage.getItem(ACCESS_TOKEN)
|
|
117
|
-
// 如果 token 存在
|
|
118
|
-
// 让每个请求携带自定义 token 请根据实际情况自行修改
|
|
119
|
-
if (token) {
|
|
120
|
-
// 如果是首次使用系统LocalStorage需要初始化,在登陆之后重新获取一次compatible
|
|
121
|
-
if (compatible === null) {
|
|
122
|
-
compatible = localStorage.getItem('compatible')
|
|
123
|
-
}
|
|
124
|
-
// 判断是否为V4环境
|
|
125
|
-
if (compatible === 'V4') {
|
|
126
|
-
// V4 环境则添加 V4请求头
|
|
127
|
-
config.headers[V4_ACCESS_TOKEN] = token
|
|
128
|
-
} else {
|
|
129
|
-
config.headers[ACCESS_TOKEN] = token
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
if (!config.headers['Content-Type']) {
|
|
133
|
-
config.headers['Content-Type'] = 'application/json;charset=UTF-8'
|
|
134
|
-
}
|
|
135
|
-
return config
|
|
136
|
-
}, errorHandler)
|
|
137
|
-
// 加载响应拦截器
|
|
138
|
-
axios.interceptors.response.use((response) => {
|
|
139
|
-
// 判断是否为V4环境,不为compatible赋初始值
|
|
140
|
-
// 其有可能是undefined未定义,或第一次使用本系统LocalStorage在初始化,获得的值为null
|
|
141
|
-
if (compatible === null || compatible === undefined) {
|
|
142
|
-
compatible = localStorage.getItem('compatible')
|
|
143
|
-
}
|
|
144
|
-
if (compatible === 'V4') {
|
|
145
|
-
if (response.data.data) {
|
|
146
|
-
return response.data.data
|
|
147
|
-
} else {
|
|
148
|
-
return response.data
|
|
149
|
-
}
|
|
150
|
-
} else {
|
|
151
|
-
return response.data
|
|
152
|
-
}
|
|
153
|
-
}, errorHandler)
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
// 异常拦截处理器
|
|
157
|
-
const errorHandler = (error) => {
|
|
158
|
-
if (error.response) {
|
|
159
|
-
const data = error.response.data
|
|
160
|
-
// 从 localstorage 获取 token
|
|
161
|
-
const token = localStorage.getItem(ACCESS_TOKEN)
|
|
162
|
-
if (error.response.status === 403 || (data && data.code === 403)) {
|
|
163
|
-
notification.error({
|
|
164
|
-
message: '禁止访问',
|
|
165
|
-
description: data
|
|
166
|
-
})
|
|
167
|
-
} else if (error.response.status === 401 || (data && data.code === 401)) {
|
|
168
|
-
notification.error({
|
|
169
|
-
message: '鉴权失败',
|
|
170
|
-
description: data
|
|
171
|
-
})
|
|
172
|
-
if (token) {
|
|
173
|
-
Vue.$store.dispatch('Logout').then(() => {
|
|
174
|
-
setTimeout(() => {
|
|
175
|
-
window.location.reload()
|
|
176
|
-
}, 1500)
|
|
177
|
-
})
|
|
178
|
-
}
|
|
179
|
-
} else if (error.response.status === 500 || (data && data.code === 500)) {
|
|
180
|
-
notification.error({
|
|
181
|
-
message: '系统异常',
|
|
182
|
-
description: data
|
|
183
|
-
})
|
|
184
|
-
} else {
|
|
185
|
-
notification.error({
|
|
186
|
-
message: '网络异常',
|
|
187
|
-
description: data
|
|
188
|
-
})
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
return Promise.reject(error)
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
/**
|
|
195
|
-
* 解析 url 中的参数
|
|
196
|
-
* @param url
|
|
197
|
-
* @returns {Object}
|
|
198
|
-
*/
|
|
199
|
-
function parseUrlParams (url) {
|
|
200
|
-
const params = {}
|
|
201
|
-
if (!url || url === '' || typeof url !== 'string') {
|
|
202
|
-
return params
|
|
203
|
-
}
|
|
204
|
-
const paramsStr = url.split('?')[1]
|
|
205
|
-
if (!paramsStr) {
|
|
206
|
-
return params
|
|
207
|
-
}
|
|
208
|
-
const paramsArr = paramsStr.replace(/&|=/g, ' ').split(' ')
|
|
209
|
-
for (let i = 0; i < paramsArr.length / 2; i++) {
|
|
210
|
-
const value = paramsArr[i * 2 + 1]
|
|
211
|
-
params[paramsArr[i * 2]] = value === 'true' ? true : (value === 'false' ? false : value)
|
|
212
|
-
}
|
|
213
|
-
return params
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
export {
|
|
217
|
-
METHOD,
|
|
218
|
-
AUTH_TYPE,
|
|
219
|
-
request,
|
|
220
|
-
setAuthorization,
|
|
221
|
-
removeAuthorization,
|
|
222
|
-
checkAuthorization,
|
|
223
|
-
loadInterceptors,
|
|
224
|
-
parseUrlParams
|
|
225
|
-
}
|
|
1
|
+
import axios from 'axios'
|
|
2
|
+
import Cookie from 'js-cookie'
|
|
3
|
+
import Vue from 'vue'
|
|
4
|
+
import { ACCESS_TOKEN, V4_ACCESS_TOKEN } from '@vue2-client/store/mutation-types'
|
|
5
|
+
import notification from 'ant-design-vue/es/notification'
|
|
6
|
+
|
|
7
|
+
let compatible
|
|
8
|
+
|
|
9
|
+
// 跨域认证信息 header 名
|
|
10
|
+
const xsrfHeaderName = 'Authorization'
|
|
11
|
+
|
|
12
|
+
axios.defaults.timeout = 5000
|
|
13
|
+
axios.defaults.withCredentials = true
|
|
14
|
+
axios.defaults.xsrfHeaderName = xsrfHeaderName
|
|
15
|
+
axios.defaults.xsrfCookieName = xsrfHeaderName
|
|
16
|
+
|
|
17
|
+
// 认证类型
|
|
18
|
+
const AUTH_TYPE = {
|
|
19
|
+
BEARER: 'Bearer',
|
|
20
|
+
BASIC: 'basic',
|
|
21
|
+
AUTH1: 'auth1',
|
|
22
|
+
AUTH2: 'auth2'
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// http method
|
|
26
|
+
const METHOD = {
|
|
27
|
+
GET: 'get',
|
|
28
|
+
POST: 'post'
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* axios请求
|
|
33
|
+
* @param url 请求地址
|
|
34
|
+
* @param method {METHOD} http method
|
|
35
|
+
* @param params 请求参数
|
|
36
|
+
* @param config
|
|
37
|
+
* @returns {Promise<AxiosResponse<T>>}
|
|
38
|
+
*/
|
|
39
|
+
async function request (url, method, params, config) {
|
|
40
|
+
switch (method) {
|
|
41
|
+
case METHOD.GET:
|
|
42
|
+
return axios.get(url, { params, ...config })
|
|
43
|
+
case METHOD.POST:
|
|
44
|
+
return axios.post(url, params, config)
|
|
45
|
+
default:
|
|
46
|
+
return axios.get(url, { params, ...config })
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* 设置认证信息
|
|
52
|
+
* @param auth {Object}
|
|
53
|
+
* @param authType {AUTH_TYPE} 认证类型,默认:{AUTH_TYPE.BEARER}
|
|
54
|
+
*/
|
|
55
|
+
function setAuthorization (auth, authType = AUTH_TYPE.BEARER) {
|
|
56
|
+
switch (authType) {
|
|
57
|
+
case AUTH_TYPE.BEARER:
|
|
58
|
+
if (auth.token) {
|
|
59
|
+
Cookie.set(xsrfHeaderName, 'Bearer ' + auth.token, { expires: auth.expireAt })
|
|
60
|
+
}
|
|
61
|
+
break
|
|
62
|
+
case AUTH_TYPE.BASIC:
|
|
63
|
+
case AUTH_TYPE.AUTH1:
|
|
64
|
+
case AUTH_TYPE.AUTH2:
|
|
65
|
+
default:
|
|
66
|
+
break
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* 移出认证信息
|
|
72
|
+
* @param authType {AUTH_TYPE} 认证类型
|
|
73
|
+
*/
|
|
74
|
+
function removeAuthorization (authType = AUTH_TYPE.BEARER) {
|
|
75
|
+
switch (authType) {
|
|
76
|
+
case AUTH_TYPE.BEARER:
|
|
77
|
+
Cookie.remove(xsrfHeaderName)
|
|
78
|
+
break
|
|
79
|
+
case AUTH_TYPE.BASIC:
|
|
80
|
+
case AUTH_TYPE.AUTH1:
|
|
81
|
+
case AUTH_TYPE.AUTH2:
|
|
82
|
+
default:
|
|
83
|
+
break
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* 检查认证信息
|
|
89
|
+
* @param authType
|
|
90
|
+
* @returns {boolean}
|
|
91
|
+
*/
|
|
92
|
+
function checkAuthorization (authType = AUTH_TYPE.BEARER) {
|
|
93
|
+
switch (authType) {
|
|
94
|
+
case AUTH_TYPE.BEARER:
|
|
95
|
+
if (Cookie.get(xsrfHeaderName)) {
|
|
96
|
+
return true
|
|
97
|
+
}
|
|
98
|
+
break
|
|
99
|
+
case AUTH_TYPE.BASIC:
|
|
100
|
+
case AUTH_TYPE.AUTH1:
|
|
101
|
+
case AUTH_TYPE.AUTH2:
|
|
102
|
+
default:
|
|
103
|
+
break
|
|
104
|
+
}
|
|
105
|
+
return false
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* 加载 axios 拦截器
|
|
110
|
+
* @param interceptors
|
|
111
|
+
* @param options
|
|
112
|
+
*/
|
|
113
|
+
function loadInterceptors () {
|
|
114
|
+
// 加载请求拦截器
|
|
115
|
+
axios.interceptors.request.use(config => {
|
|
116
|
+
const token = localStorage.getItem(ACCESS_TOKEN)
|
|
117
|
+
// 如果 token 存在
|
|
118
|
+
// 让每个请求携带自定义 token 请根据实际情况自行修改
|
|
119
|
+
if (token) {
|
|
120
|
+
// 如果是首次使用系统LocalStorage需要初始化,在登陆之后重新获取一次compatible
|
|
121
|
+
if (compatible === null) {
|
|
122
|
+
compatible = localStorage.getItem('compatible')
|
|
123
|
+
}
|
|
124
|
+
// 判断是否为V4环境
|
|
125
|
+
if (compatible === 'V4') {
|
|
126
|
+
// V4 环境则添加 V4请求头
|
|
127
|
+
config.headers[V4_ACCESS_TOKEN] = token
|
|
128
|
+
} else {
|
|
129
|
+
config.headers[ACCESS_TOKEN] = token
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
if (!config.headers['Content-Type']) {
|
|
133
|
+
config.headers['Content-Type'] = 'application/json;charset=UTF-8'
|
|
134
|
+
}
|
|
135
|
+
return config
|
|
136
|
+
}, errorHandler)
|
|
137
|
+
// 加载响应拦截器
|
|
138
|
+
axios.interceptors.response.use((response) => {
|
|
139
|
+
// 判断是否为V4环境,不为compatible赋初始值
|
|
140
|
+
// 其有可能是undefined未定义,或第一次使用本系统LocalStorage在初始化,获得的值为null
|
|
141
|
+
if (compatible === null || compatible === undefined) {
|
|
142
|
+
compatible = localStorage.getItem('compatible')
|
|
143
|
+
}
|
|
144
|
+
if (compatible === 'V4') {
|
|
145
|
+
if (response.data.data) {
|
|
146
|
+
return response.data.data
|
|
147
|
+
} else {
|
|
148
|
+
return response.data
|
|
149
|
+
}
|
|
150
|
+
} else {
|
|
151
|
+
return response.data
|
|
152
|
+
}
|
|
153
|
+
}, errorHandler)
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
// 异常拦截处理器
|
|
157
|
+
const errorHandler = (error) => {
|
|
158
|
+
if (error.response) {
|
|
159
|
+
const data = error.response.data
|
|
160
|
+
// 从 localstorage 获取 token
|
|
161
|
+
const token = localStorage.getItem(ACCESS_TOKEN)
|
|
162
|
+
if (error.response.status === 403 || (data && data.code === 403)) {
|
|
163
|
+
notification.error({
|
|
164
|
+
message: '禁止访问',
|
|
165
|
+
description: data
|
|
166
|
+
})
|
|
167
|
+
} else if (error.response.status === 401 || (data && data.code === 401)) {
|
|
168
|
+
notification.error({
|
|
169
|
+
message: '鉴权失败',
|
|
170
|
+
description: data
|
|
171
|
+
})
|
|
172
|
+
if (token) {
|
|
173
|
+
Vue.$store.dispatch('Logout').then(() => {
|
|
174
|
+
setTimeout(() => {
|
|
175
|
+
window.location.reload()
|
|
176
|
+
}, 1500)
|
|
177
|
+
})
|
|
178
|
+
}
|
|
179
|
+
} else if (error.response.status === 500 || (data && data.code === 500)) {
|
|
180
|
+
notification.error({
|
|
181
|
+
message: '系统异常',
|
|
182
|
+
description: data
|
|
183
|
+
})
|
|
184
|
+
} else {
|
|
185
|
+
notification.error({
|
|
186
|
+
message: '网络异常',
|
|
187
|
+
description: data
|
|
188
|
+
})
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
return Promise.reject(error)
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* 解析 url 中的参数
|
|
196
|
+
* @param url
|
|
197
|
+
* @returns {Object}
|
|
198
|
+
*/
|
|
199
|
+
function parseUrlParams (url) {
|
|
200
|
+
const params = {}
|
|
201
|
+
if (!url || url === '' || typeof url !== 'string') {
|
|
202
|
+
return params
|
|
203
|
+
}
|
|
204
|
+
const paramsStr = url.split('?')[1]
|
|
205
|
+
if (!paramsStr) {
|
|
206
|
+
return params
|
|
207
|
+
}
|
|
208
|
+
const paramsArr = paramsStr.replace(/&|=/g, ' ').split(' ')
|
|
209
|
+
for (let i = 0; i < paramsArr.length / 2; i++) {
|
|
210
|
+
const value = paramsArr[i * 2 + 1]
|
|
211
|
+
params[paramsArr[i * 2]] = value === 'true' ? true : (value === 'false' ? false : value)
|
|
212
|
+
}
|
|
213
|
+
return params
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
export {
|
|
217
|
+
METHOD,
|
|
218
|
+
AUTH_TYPE,
|
|
219
|
+
request,
|
|
220
|
+
setAuthorization,
|
|
221
|
+
removeAuthorization,
|
|
222
|
+
checkAuthorization,
|
|
223
|
+
loadInterceptors,
|
|
224
|
+
parseUrlParams
|
|
225
|
+
}
|