vue2-client 1.14.27 → 1.14.28

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.
@@ -1,377 +1,378 @@
1
- import axios from 'axios'
2
- import Cookie from 'js-cookie'
3
- import {
4
- ACCESS_TOKEN,
5
- SYSTEM_VERSION,
6
- V4_ACCESS_TOKEN, V4_SESSION_KEY
7
- } from '@vue2-client/store/mutation-types'
8
- import notification from 'ant-design-vue/es/notification'
9
- import errorCode from '@vue2-client/utils/errorCode'
10
- import qs from 'qs'
11
- import { logout, V4RefreshToken } from '@vue2-client/services/user'
12
- import { LOGIN, SEARCH, V4_LOGIN } from '@vue2-client/services/apiService'
13
- import { setV4AccessToken } from '@vue2-client/utils/login'
14
- import EncryptUtil from '@vue2-client/utils/EncryptUtil'
15
- // 是否显示重新登录
16
- let isReloginShow
17
-
18
- axios.defaults.timeout = 50000
19
- axios.defaults.withCredentials = true
20
- // 如果是microapp
21
- if (window.__MICRO_APP_ENVIRONMENT__) {
22
- const data = window.microApp.getData() // 获取主应用下发的data数据
23
- // 修改baseurl为主应用地址
24
- if (data.origin) {
25
- axios.defaults.baseURL = data.origin
26
- }
27
- }
28
- // 认证类型
29
- const AUTH_TYPE = {
30
- BEARER: 'Bearer',
31
- BASIC: 'basic',
32
- AUTH1: 'auth1',
33
- AUTH2: 'auth2'
34
- }
35
-
36
- // http method
37
- const METHOD = {
38
- GET: 'get',
39
- POST: 'post',
40
- PUT: 'put',
41
- DELETE: 'delete'
42
- }
43
- /**
44
- * axios请求
45
- * @param url 请求地址
46
- * @param method {METHOD} http method
47
- * @param params 请求参数
48
- * @param config
49
- * @returns {Promise<AxiosResponse<T>>}
50
- */
51
- async function request (url, method, params, config) {
52
- switch (method) {
53
- case METHOD.GET:
54
- return axios.get(url, { params, ...config })
55
- case METHOD.POST:
56
- return axios.post(url, params, config)
57
- case METHOD.PUT:
58
- return axios.put(url, params, config)
59
- case METHOD.DELETE:
60
- return axios.delete(url, { params, ...config })
61
- default:
62
- return axios.get(url, { params, ...config })
63
- }
64
- }
65
-
66
- /**
67
- * 设置认证信息
68
- * @param auth {Object}
69
- * @param authType {AUTH_TYPE} 认证类型,默认:{AUTH_TYPE.BEARER}
70
- */
71
- function setAuthorization (auth, authType = AUTH_TYPE.BEARER) {
72
- switch (authType) {
73
- case AUTH_TYPE.BEARER:
74
- localStorage.setItem(V4_ACCESS_TOKEN, 'Bearer ' + auth.token)
75
- Cookie.set(V4_ACCESS_TOKEN, 'Bearer ' + auth.token, { expires: auth.expireAt })
76
- break
77
- case AUTH_TYPE.BASIC:
78
- case AUTH_TYPE.AUTH1:
79
- case AUTH_TYPE.AUTH2:
80
- default:
81
- break
82
- }
83
- }
84
-
85
- /**
86
- * 设置系统版本
87
- * @param value 系统版本
88
- */
89
- export function setSystemVersion (value) {
90
- Cookie.set(SYSTEM_VERSION, value)
91
- }
92
-
93
- /**
94
- * 获取系统版本
95
- */
96
- export function getSystemVersion () {
97
- return Cookie.get(SYSTEM_VERSION) || 'V4'
98
- }
99
-
100
- /**
101
- * 移出认证信息
102
- * @param authType {AUTH_TYPE} 认证类型
103
- */
104
- function removeAuthorization (authType = AUTH_TYPE.BEARER) {
105
- switch (authType) {
106
- case AUTH_TYPE.BEARER:
107
- Cookie.remove(V4_ACCESS_TOKEN)
108
- localStorage.removeItem(V4_ACCESS_TOKEN)
109
- localStorage.removeItem(V4_SESSION_KEY)
110
- break
111
- case AUTH_TYPE.BASIC:
112
- case AUTH_TYPE.AUTH1:
113
- case AUTH_TYPE.AUTH2:
114
- default:
115
- break
116
- }
117
- }
118
-
119
- /**
120
- * 检查认证信息
121
- * @param authType
122
- * @returns {boolean}
123
- */
124
- function checkAuthorization (authType = AUTH_TYPE.BEARER) {
125
- switch (authType) {
126
- case AUTH_TYPE.BEARER:
127
- if (localStorage.getItem(V4_ACCESS_TOKEN) || Cookie.get(V4_ACCESS_TOKEN)) {
128
- return true
129
- }
130
- break
131
- case AUTH_TYPE.BASIC:
132
- case AUTH_TYPE.AUTH1:
133
- case AUTH_TYPE.AUTH2:
134
- default:
135
- break
136
- }
137
- return false
138
- }
139
-
140
- /**
141
- * 加载 axios 拦截器
142
- * @param interceptors
143
- * @param options
144
- */
145
- function loadInterceptors () {
146
- // 加载请求拦截器
147
- axios.interceptors.request.use(config => {
148
- const token = localStorage.getItem(ACCESS_TOKEN)
149
- // 如果 token 存在
150
- // 让每个请求携带自定义 token 请根据实际情况自行修改
151
- if (token) {
152
- if (config.url !== V4_LOGIN) {
153
- // V4 环境则添加 V4请求头
154
- config.headers[V4_ACCESS_TOKEN] = token
155
- config.headers[ACCESS_TOKEN] = token
156
- }
157
- }
158
-
159
- const v4SessionKey = localStorage.getItem(V4_SESSION_KEY)
160
- if (['post'].includes(config.method.toLowerCase()) && v4SessionKey &&
161
- !config.url.includes('/logic/openapi/') &&
162
- !config.url.includes('devApi') &&
163
- !config.url.includes('auth/login')) {
164
- if (config.data && !(config.data instanceof FormData)) {
165
- config.data = {
166
- encrypted: EncryptUtil.AESEncryptCBC(config.data, v4SessionKey)
167
- }
168
- config.headers['X-Sec'] = '1'
169
- config.headers['X-Rand'] = Math.random().toString(36).substr(2, 5)
170
- config.headers['X-Ts'] = Date.now()
171
- }
172
- }
173
-
174
- // 请求v3 时,添加X-Skip-Lua头 避免地方项目 nginx 加密导致请求 不同
175
- if ([LOGIN, SEARCH].includes(config.url) || config.url.startsWith('/rs/user')) {
176
- config.headers['X-Skip-Lua'] = 1
177
- }
178
- if (!config.headers['Content-Type']) {
179
- config.headers['Content-Type'] = 'application/json;charset=UTF-8'
180
- }
181
- // 处理params参数
182
- if (config.params) {
183
- const url = config.url + '?' + qs.stringify(config.params, { indices: false })
184
- config.params = {}
185
- config.url = url
186
- }
187
- return config
188
- }, errorHandler)
189
- // 加载响应拦截器
190
- axios.interceptors.response.use((res) => {
191
- // 判断是否为V4环境,不为compatible赋初始值
192
- // 其有可能是undefined未定义,或第一次使用本系统LocalStorage在初始化,获得的值为null
193
- const compatible = getSystemVersion()
194
- if (compatible === 'V4' || (res.data.code && Object.prototype.hasOwnProperty.call(res.data, 'msg'))) {
195
- // 请求rul
196
- const requestUrl = res.config.url
197
- // 未设置状态码则默认成功状态
198
- const code = res.data.code || 200
199
- // 兼容V3, V3使用XFormTable需要这个
200
- if (res.data.data) {
201
- if (compatible === 'V4') {
202
- res.data = res.data.data
203
- } else {
204
- let isJsonArray = false
205
- if (typeof res.data.data === 'string') {
206
- try {
207
- const parsedData = JSON.parse(res.data.data)
208
- isJsonArray = Array.isArray(parsedData)
209
- } catch (e) {
210
- isJsonArray = false
211
- }
212
- }
213
- if (!(Array.isArray(res.data.data) || isJsonArray)) {
214
- res.data = res.data.data
215
- }
216
- }
217
- }
218
- // 获取错误信息
219
- const msg = errorCode[code] || res.data.msg || errorCode.default
220
- // 二进制数据则直接返回
221
- if (res.request.responseType === 'blob' || res.request.responseType === 'arraybuffer') {
222
- return res.data
223
- }
224
- if (code === 401) {
225
- if (res.data.msg && localStorage.getItem('SinglePage_TOKEN')) {
226
- const config = res.config
227
- return V4RefreshToken().then((res) => {
228
- setV4AccessToken(res)
229
- return axios(config)
230
- }).catch((extendError) => {
231
- loginExpire()
232
- return Promise.reject(extendError)
233
- })
234
- } else {
235
- loginExpire()
236
- }
237
- } else if (code === 500) {
238
- if (requestUrl !== '/login') {
239
- notification.error({
240
- message: '失败',
241
- description: msg
242
- })
243
- }
244
- } else if (code === 601) {
245
- notification.warn({
246
- message: '警告',
247
- description: msg
248
- })
249
- } else if (code !== 200) {
250
- notification.error({
251
- message: '失败',
252
- description: msg
253
- })
254
- } else {
255
- return res.data
256
- }
257
- return Promise.reject(msg)
258
- } else {
259
- return res.data
260
- }
261
- }, errorHandler)
262
- }
263
-
264
- function loginExpire () {
265
- if (!isReloginShow) {
266
- isReloginShow = true
267
- if (window.__MICRO_APP_ENVIRONMENT__) {
268
- logout().then(() => {
269
- isReloginShow = false
270
- })
271
- } else {
272
- notification.open({
273
- message: '系统提示',
274
- description: '登录状态已过期,请重新登录',
275
- btn: h => {
276
- return h(
277
- 'a-button',
278
- {
279
- props: {
280
- type: 'primary',
281
- size: 'small'
282
- },
283
- on: {
284
- click: () => {
285
- logout().then(() => {
286
- isReloginShow = false
287
- location.href = '/login'
288
- })
289
- }
290
- }
291
- },
292
- '确认'
293
- )
294
- },
295
- duration: 0,
296
- onClose: () => {
297
- isReloginShow = false
298
- }
299
- })
300
- }
301
- }
302
- }
303
- // 异常拦截处理器
304
- const errorHandler = (error) => {
305
- if (error.response) {
306
- const data = error.response.data
307
- // localstorage 获取 token
308
- const token = localStorage.getItem(ACCESS_TOKEN)
309
- if (error.response.status === 403 || (data && data.code === 403)) {
310
- notification.error({
311
- message: '禁止访问',
312
- description: data
313
- })
314
- } else if (error.response.status === 401 || (data && data.code === 401)) {
315
- notification.error({
316
- message: '鉴权失败',
317
- description: data
318
- })
319
- if (token) {
320
- logout().then(() => {
321
- setTimeout(() => {
322
- window.location.reload()
323
- }, 1500)
324
- })
325
- }
326
- } else if (error.response.status === 500 || (data && data.code === 500)) {
327
- notification.error({
328
- message: '系统异常',
329
- description: data
330
- })
331
- } else if (error.response.status === 601 || (data && data.code === 601)) {
332
- notification.warn({
333
- message: '系统警告',
334
- description: data
335
- })
336
- } else {
337
- notification.error({
338
- message: '网络异常',
339
- description: data
340
- })
341
- }
342
- }
343
- return Promise.reject(error)
344
- }
345
-
346
- /**
347
- * 解析 url 中的参数
348
- * @param url
349
- * @returns {Object}
350
- */
351
- function parseUrlParams (url) {
352
- const params = {}
353
- if (!url || url === '' || typeof url !== 'string') {
354
- return params
355
- }
356
- const paramsStr = url.split('?')[1]
357
- if (!paramsStr) {
358
- return params
359
- }
360
- const paramsArr = paramsStr.replace(/&|=/g, ' ').split(' ')
361
- for (let i = 0; i < paramsArr.length / 2; i++) {
362
- const value = paramsArr[i * 2 + 1]
363
- params[paramsArr[i * 2]] = value === 'true' ? true : (value === 'false' ? false : value)
364
- }
365
- return params
366
- }
367
-
368
- export {
369
- METHOD,
370
- AUTH_TYPE,
371
- request,
372
- setAuthorization,
373
- removeAuthorization,
374
- checkAuthorization,
375
- loadInterceptors,
376
- parseUrlParams
377
- }
1
+ import axios from 'axios'
2
+ import Cookie from 'js-cookie'
3
+ import {
4
+ ACCESS_TOKEN,
5
+ SYSTEM_VERSION,
6
+ V4_ACCESS_TOKEN, V4_SESSION_KEY
7
+ } from '@vue2-client/store/mutation-types'
8
+ import notification from 'ant-design-vue/es/notification'
9
+ import errorCode from '@vue2-client/utils/errorCode'
10
+ import qs from 'qs'
11
+ import { logout, V4RefreshToken } from '@vue2-client/services/user'
12
+ import { LOGIN, SEARCH, V4_LOGIN } from '@vue2-client/services/apiService'
13
+ import { setV4AccessToken } from '@vue2-client/utils/login'
14
+ import EncryptUtil from '@vue2-client/utils/EncryptUtil'
15
+ // 是否显示重新登录
16
+ let isReloginShow
17
+
18
+ axios.defaults.timeout = 50000
19
+ axios.defaults.withCredentials = true
20
+ // 如果是microapp
21
+ if (window.__MICRO_APP_ENVIRONMENT__) {
22
+ const data = window.microApp.getData() // 获取主应用下发的data数据
23
+ // 修改baseurl为主应用地址
24
+ if (data.origin) {
25
+ axios.defaults.baseURL = data.origin
26
+ }
27
+ }
28
+ // 认证类型
29
+ const AUTH_TYPE = {
30
+ BEARER: 'Bearer',
31
+ BASIC: 'basic',
32
+ AUTH1: 'auth1',
33
+ AUTH2: 'auth2'
34
+ }
35
+
36
+ // http method
37
+ const METHOD = {
38
+ GET: 'get',
39
+ POST: 'post',
40
+ PUT: 'put',
41
+ DELETE: 'delete'
42
+ }
43
+ /**
44
+ * axios请求
45
+ * @param url 请求地址
46
+ * @param method {METHOD} http method
47
+ * @param params 请求参数
48
+ * @param config
49
+ * @returns {Promise<AxiosResponse<T>>}
50
+ */
51
+ async function request (url, method, params, config) {
52
+ switch (method) {
53
+ case METHOD.GET:
54
+ return axios.get(url, { params, ...config })
55
+ case METHOD.POST:
56
+ return axios.post(url, params, config)
57
+ case METHOD.PUT:
58
+ return axios.put(url, params, config)
59
+ case METHOD.DELETE:
60
+ return axios.delete(url, { params, ...config })
61
+ default:
62
+ return axios.get(url, { params, ...config })
63
+ }
64
+ }
65
+
66
+ /**
67
+ * 设置认证信息
68
+ * @param auth {Object}
69
+ * @param authType {AUTH_TYPE} 认证类型,默认:{AUTH_TYPE.BEARER}
70
+ */
71
+ function setAuthorization (auth, authType = AUTH_TYPE.BEARER) {
72
+ switch (authType) {
73
+ case AUTH_TYPE.BEARER:
74
+ localStorage.setItem(V4_ACCESS_TOKEN, 'Bearer ' + auth.token)
75
+ Cookie.set(V4_ACCESS_TOKEN, 'Bearer ' + auth.token, { expires: auth.expireAt })
76
+ break
77
+ case AUTH_TYPE.BASIC:
78
+ case AUTH_TYPE.AUTH1:
79
+ case AUTH_TYPE.AUTH2:
80
+ default:
81
+ break
82
+ }
83
+ }
84
+
85
+ /**
86
+ * 设置系统版本
87
+ * @param value 系统版本
88
+ */
89
+ export function setSystemVersion (value) {
90
+ Cookie.set(SYSTEM_VERSION, value)
91
+ }
92
+
93
+ /**
94
+ * 获取系统版本
95
+ */
96
+ export function getSystemVersion () {
97
+ return Cookie.get(SYSTEM_VERSION) || 'V4'
98
+ }
99
+
100
+ /**
101
+ * 移出认证信息
102
+ * @param authType {AUTH_TYPE} 认证类型
103
+ */
104
+ function removeAuthorization (authType = AUTH_TYPE.BEARER) {
105
+ switch (authType) {
106
+ case AUTH_TYPE.BEARER:
107
+ Cookie.remove(V4_ACCESS_TOKEN)
108
+ localStorage.removeItem(V4_ACCESS_TOKEN)
109
+ localStorage.removeItem(V4_SESSION_KEY)
110
+ break
111
+ case AUTH_TYPE.BASIC:
112
+ case AUTH_TYPE.AUTH1:
113
+ case AUTH_TYPE.AUTH2:
114
+ default:
115
+ break
116
+ }
117
+ }
118
+
119
+ /**
120
+ * 检查认证信息
121
+ * @param authType
122
+ * @returns {boolean}
123
+ */
124
+ function checkAuthorization (authType = AUTH_TYPE.BEARER) {
125
+ switch (authType) {
126
+ case AUTH_TYPE.BEARER:
127
+ if (localStorage.getItem(V4_ACCESS_TOKEN) || Cookie.get(V4_ACCESS_TOKEN)) {
128
+ return true
129
+ }
130
+ break
131
+ case AUTH_TYPE.BASIC:
132
+ case AUTH_TYPE.AUTH1:
133
+ case AUTH_TYPE.AUTH2:
134
+ default:
135
+ break
136
+ }
137
+ return false
138
+ }
139
+
140
+ /**
141
+ * 加载 axios 拦截器
142
+ * @param interceptors
143
+ * @param options
144
+ */
145
+ function loadInterceptors () {
146
+ // 加载请求拦截器
147
+ axios.interceptors.request.use(config => {
148
+ const token = localStorage.getItem(ACCESS_TOKEN)
149
+ // 如果 token 存在
150
+ // 让每个请求携带自定义 token 请根据实际情况自行修改
151
+ if (token) {
152
+ if (config.url !== V4_LOGIN) {
153
+ // V4 环境则添加 V4请求头
154
+ config.headers[V4_ACCESS_TOKEN] = token
155
+ config.headers[ACCESS_TOKEN] = token
156
+ }
157
+ }
158
+
159
+ const v4SessionKey = localStorage.getItem(V4_SESSION_KEY)
160
+ if (['post'].includes(config.method.toLowerCase()) && v4SessionKey &&
161
+ !config.url.includes('/logic/openapi/') &&
162
+ !config.url.includes('devApi') &&
163
+ !config.url.includes('auth/login') &&
164
+ config.url.includes('api/af-')) {
165
+ if (config.data && !(config.data instanceof FormData)) {
166
+ config.data = {
167
+ encrypted: EncryptUtil.AESEncryptCBC(config.data, v4SessionKey)
168
+ }
169
+ config.headers['X-Sec'] = '1'
170
+ config.headers['X-Rand'] = Math.random().toString(36).substr(2, 5)
171
+ config.headers['X-Ts'] = Date.now()
172
+ }
173
+ }
174
+
175
+ // 请求v3 时,添加X-Skip-Lua头 避免地方项目 nginx 加密导致请求 不同
176
+ if ([LOGIN, SEARCH].includes(config.url) || config.url.startsWith('/rs/user')) {
177
+ config.headers['X-Skip-Lua'] = 1
178
+ }
179
+ if (!config.headers['Content-Type']) {
180
+ config.headers['Content-Type'] = 'application/json;charset=UTF-8'
181
+ }
182
+ // 处理params参数
183
+ if (config.params) {
184
+ const url = config.url + '?' + qs.stringify(config.params, { indices: false })
185
+ config.params = {}
186
+ config.url = url
187
+ }
188
+ return config
189
+ }, errorHandler)
190
+ // 加载响应拦截器
191
+ axios.interceptors.response.use((res) => {
192
+ // 判断是否为V4环境,不为compatible赋初始值
193
+ // 其有可能是undefined未定义,或第一次使用本系统LocalStorage在初始化,获得的值为null
194
+ const compatible = getSystemVersion()
195
+ if (compatible === 'V4' || (res.data.code && Object.prototype.hasOwnProperty.call(res.data, 'msg'))) {
196
+ // 请求rul
197
+ const requestUrl = res.config.url
198
+ // 未设置状态码则默认成功状态
199
+ const code = res.data.code || 200
200
+ // 兼容V3, V3使用XFormTable需要这个
201
+ if (res.data.data) {
202
+ if (compatible === 'V4') {
203
+ res.data = res.data.data
204
+ } else {
205
+ let isJsonArray = false
206
+ if (typeof res.data.data === 'string') {
207
+ try {
208
+ const parsedData = JSON.parse(res.data.data)
209
+ isJsonArray = Array.isArray(parsedData)
210
+ } catch (e) {
211
+ isJsonArray = false
212
+ }
213
+ }
214
+ if (!(Array.isArray(res.data.data) || isJsonArray)) {
215
+ res.data = res.data.data
216
+ }
217
+ }
218
+ }
219
+ // 获取错误信息
220
+ const msg = errorCode[code] || res.data.msg || errorCode.default
221
+ // 二进制数据则直接返回
222
+ if (res.request.responseType === 'blob' || res.request.responseType === 'arraybuffer') {
223
+ return res.data
224
+ }
225
+ if (code === 401) {
226
+ if (res.data.msg && localStorage.getItem('SinglePage_TOKEN')) {
227
+ const config = res.config
228
+ return V4RefreshToken().then((res) => {
229
+ setV4AccessToken(res)
230
+ return axios(config)
231
+ }).catch((extendError) => {
232
+ loginExpire()
233
+ return Promise.reject(extendError)
234
+ })
235
+ } else {
236
+ loginExpire()
237
+ }
238
+ } else if (code === 500) {
239
+ if (requestUrl !== '/login') {
240
+ notification.error({
241
+ message: '失败',
242
+ description: msg
243
+ })
244
+ }
245
+ } else if (code === 601) {
246
+ notification.warn({
247
+ message: '警告',
248
+ description: msg
249
+ })
250
+ } else if (code !== 200) {
251
+ notification.error({
252
+ message: '失败',
253
+ description: msg
254
+ })
255
+ } else {
256
+ return res.data
257
+ }
258
+ return Promise.reject(msg)
259
+ } else {
260
+ return res.data
261
+ }
262
+ }, errorHandler)
263
+ }
264
+
265
+ function loginExpire () {
266
+ if (!isReloginShow) {
267
+ isReloginShow = true
268
+ if (window.__MICRO_APP_ENVIRONMENT__) {
269
+ logout().then(() => {
270
+ isReloginShow = false
271
+ })
272
+ } else {
273
+ notification.open({
274
+ message: '系统提示',
275
+ description: '登录状态已过期,请重新登录',
276
+ btn: h => {
277
+ return h(
278
+ 'a-button',
279
+ {
280
+ props: {
281
+ type: 'primary',
282
+ size: 'small'
283
+ },
284
+ on: {
285
+ click: () => {
286
+ logout().then(() => {
287
+ isReloginShow = false
288
+ location.href = '/login'
289
+ })
290
+ }
291
+ }
292
+ },
293
+ '确认'
294
+ )
295
+ },
296
+ duration: 0,
297
+ onClose: () => {
298
+ isReloginShow = false
299
+ }
300
+ })
301
+ }
302
+ }
303
+ }
304
+ // 异常拦截处理器
305
+ const errorHandler = (error) => {
306
+ if (error.response) {
307
+ const data = error.response.data
308
+ // localstorage 获取 token
309
+ const token = localStorage.getItem(ACCESS_TOKEN)
310
+ if (error.response.status === 403 || (data && data.code === 403)) {
311
+ notification.error({
312
+ message: '禁止访问',
313
+ description: data
314
+ })
315
+ } else if (error.response.status === 401 || (data && data.code === 401)) {
316
+ notification.error({
317
+ message: '鉴权失败',
318
+ description: data
319
+ })
320
+ if (token) {
321
+ logout().then(() => {
322
+ setTimeout(() => {
323
+ window.location.reload()
324
+ }, 1500)
325
+ })
326
+ }
327
+ } else if (error.response.status === 500 || (data && data.code === 500)) {
328
+ notification.error({
329
+ message: '系统异常',
330
+ description: data
331
+ })
332
+ } else if (error.response.status === 601 || (data && data.code === 601)) {
333
+ notification.warn({
334
+ message: '系统警告',
335
+ description: data
336
+ })
337
+ } else {
338
+ notification.error({
339
+ message: '网络异常',
340
+ description: data
341
+ })
342
+ }
343
+ }
344
+ return Promise.reject(error)
345
+ }
346
+
347
+ /**
348
+ * 解析 url 中的参数
349
+ * @param url
350
+ * @returns {Object}
351
+ */
352
+ function parseUrlParams (url) {
353
+ const params = {}
354
+ if (!url || url === '' || typeof url !== 'string') {
355
+ return params
356
+ }
357
+ const paramsStr = url.split('?')[1]
358
+ if (!paramsStr) {
359
+ return params
360
+ }
361
+ const paramsArr = paramsStr.replace(/&|=/g, ' ').split(' ')
362
+ for (let i = 0; i < paramsArr.length / 2; i++) {
363
+ const value = paramsArr[i * 2 + 1]
364
+ params[paramsArr[i * 2]] = value === 'true' ? true : (value === 'false' ? false : value)
365
+ }
366
+ return params
367
+ }
368
+
369
+ export {
370
+ METHOD,
371
+ AUTH_TYPE,
372
+ request,
373
+ setAuthorization,
374
+ removeAuthorization,
375
+ checkAuthorization,
376
+ loadInterceptors,
377
+ parseUrlParams
378
+ }