vue2-client 1.11.6 → 1.12.2

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