vue2-client 1.2.34 → 1.2.37
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/.eslintrc.js +82 -82
- package/CHANGELOG.md +15 -0
- package/package.json +1 -1
- package/src/base-client/all.js +59 -59
- package/src/base-client/components/common/CreateQuery/CreateQuery.vue +1342 -1335
- package/src/base-client/components/common/CreateSimpleFormQuery/CreateSimpleFormQuery.vue +752 -752
- package/src/base-client/components/common/Upload/Upload.vue +124 -124
- package/src/base-client/components/common/Upload/index.js +3 -3
- package/src/base-client/components/common/XAddForm/XAddForm.vue +338 -338
- package/src/base-client/components/common/XForm/XFormItem.vue +280 -280
- package/src/base-client/components/common/XFormTable/XFormTable.vue +484 -484
- package/src/base-client/components/iot/DeviceDetailsView/part/DeviceDetailsException.vue +57 -57
- package/src/base-client/components/iot/DeviceDetailsView/part/DeviceDetailsRead.vue +131 -131
- package/src/base-client/components/ticket/TicketSubmitSuccessView/TicketSubmitSuccessView.vue +532 -528
- package/src/config/config.js +2 -0
- package/src/config/default/setting.config.js +34 -34
- package/src/layouts/AdminLayout.vue +2 -2
- package/src/layouts/tabs/TabsView.vue +6 -0
- package/src/pages/login/Login.vue +198 -198
- package/src/pages/resourceManage/resourceManageMain.vue +0 -1
- package/src/pages/system/ticket/index.vue +440 -437
- package/src/router/async/config.async.js +26 -26
- package/src/router/async/router.map.js +59 -59
- package/src/router/index.js +27 -27
- package/src/services/api/restTools.js +24 -24
- package/src/utils/request.js +198 -198
- package/vue.config.js +36 -36
|
@@ -1,26 +1,26 @@
|
|
|
1
|
-
import routerMap from './router.map'
|
|
2
|
-
import { parseRoutes } from '@vue2-client/utils/routerUtil'
|
|
3
|
-
|
|
4
|
-
// 异步路由配置
|
|
5
|
-
const routesConfig = [
|
|
6
|
-
'login',
|
|
7
|
-
'submitTicket',
|
|
8
|
-
'root',
|
|
9
|
-
{
|
|
10
|
-
router: 'exp404',
|
|
11
|
-
path: '*',
|
|
12
|
-
name: '404'
|
|
13
|
-
},
|
|
14
|
-
{
|
|
15
|
-
router: 'exp403',
|
|
16
|
-
path: '/403',
|
|
17
|
-
name: '403'
|
|
18
|
-
}
|
|
19
|
-
]
|
|
20
|
-
|
|
21
|
-
const options = {
|
|
22
|
-
mode: 'history',
|
|
23
|
-
routes: parseRoutes(routesConfig, routerMap)
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export default options
|
|
1
|
+
import routerMap from './router.map'
|
|
2
|
+
import { parseRoutes } from '@vue2-client/utils/routerUtil'
|
|
3
|
+
|
|
4
|
+
// 异步路由配置
|
|
5
|
+
const routesConfig = [
|
|
6
|
+
'login',
|
|
7
|
+
'submitTicket',
|
|
8
|
+
'root',
|
|
9
|
+
{
|
|
10
|
+
router: 'exp404',
|
|
11
|
+
path: '*',
|
|
12
|
+
name: '404'
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
router: 'exp403',
|
|
16
|
+
path: '/403',
|
|
17
|
+
name: '403'
|
|
18
|
+
}
|
|
19
|
+
]
|
|
20
|
+
|
|
21
|
+
const options = {
|
|
22
|
+
mode: 'history',
|
|
23
|
+
routes: parseRoutes(routesConfig, routerMap)
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export default options
|
|
@@ -1,59 +1,59 @@
|
|
|
1
|
-
// 视图组件
|
|
2
|
-
const view = {
|
|
3
|
-
tabs: () => import('@vue2-client/layouts/tabs'),
|
|
4
|
-
blank: () => import('@vue2-client/layouts/BlankView'),
|
|
5
|
-
page: () => import('@vue2-client/layouts/PageView'),
|
|
6
|
-
singlePage: () => import('@vue2-client/layouts/SinglePageView')
|
|
7
|
-
}
|
|
8
|
-
// 动态路由对象定义
|
|
9
|
-
const routerResource = {}
|
|
10
|
-
// --------------------------------------基本视图组件--------------------------------------
|
|
11
|
-
// 空白视图
|
|
12
|
-
routerResource.blank = view.blank
|
|
13
|
-
// 单页面视图
|
|
14
|
-
routerResource.singlePage = view.singlePage
|
|
15
|
-
// --------------------------------------系统配置--------------------------------------
|
|
16
|
-
routerResource.system = view.blank
|
|
17
|
-
// 字典管理
|
|
18
|
-
routerResource.dictionaryManage = () => import(/* webpackChunkName: "dictionary" */ '@vue2-client/pages/system/dictionary')
|
|
19
|
-
// 查询配置管理
|
|
20
|
-
routerResource.queryParamsManage = () => import(/* webpackChunkName: "queryParams" */ '@vue2-client/pages/system/queryParams')
|
|
21
|
-
// 系统问题反馈工单
|
|
22
|
-
routerResource.submitTicket = () => import(/* webpackChunkName: "submitTicket" */ '@vue2-client/pages/system/ticket')
|
|
23
|
-
// --------------------------------------报表组件--------------------------------------
|
|
24
|
-
routerResource.reportTable = () => import(/* webpackChunkName: "ReportTableHome" */ '@vue2-client/pages/report/ReportTableHome')
|
|
25
|
-
// --------------------------------------资源管理--------------------------------------
|
|
26
|
-
routerResource.resourceManageMain = () => import(/* webpackChunkName: "resourceManageMain" */ '@vue2-client/pages/resourceManage/resourceManageMain')
|
|
27
|
-
|
|
28
|
-
// 基础路由组件注册
|
|
29
|
-
const routerMap = {
|
|
30
|
-
login: {
|
|
31
|
-
authority: '*',
|
|
32
|
-
path: '/login',
|
|
33
|
-
component: () => import('@vue2-client/pages/login')
|
|
34
|
-
},
|
|
35
|
-
root: {
|
|
36
|
-
path: '/',
|
|
37
|
-
name: '首页',
|
|
38
|
-
redirect: '/login',
|
|
39
|
-
component: view.tabs
|
|
40
|
-
},
|
|
41
|
-
exp403: {
|
|
42
|
-
authority: '*',
|
|
43
|
-
name: 'exp403',
|
|
44
|
-
path: '403',
|
|
45
|
-
component: () => import('@vue2-client/pages/exception/403')
|
|
46
|
-
},
|
|
47
|
-
exp404: {
|
|
48
|
-
name: 'exp404',
|
|
49
|
-
path: '404',
|
|
50
|
-
component: () => import('@vue2-client/pages/exception/404')
|
|
51
|
-
},
|
|
52
|
-
exp500: {
|
|
53
|
-
name: 'exp500',
|
|
54
|
-
path: '500',
|
|
55
|
-
component: () => import('@vue2-client/pages/exception/500')
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
Object.assign(routerMap, routerResource)
|
|
59
|
-
export default routerMap
|
|
1
|
+
// 视图组件
|
|
2
|
+
const view = {
|
|
3
|
+
tabs: () => import('@vue2-client/layouts/tabs'),
|
|
4
|
+
blank: () => import('@vue2-client/layouts/BlankView'),
|
|
5
|
+
page: () => import('@vue2-client/layouts/PageView'),
|
|
6
|
+
singlePage: () => import('@vue2-client/layouts/SinglePageView')
|
|
7
|
+
}
|
|
8
|
+
// 动态路由对象定义
|
|
9
|
+
const routerResource = {}
|
|
10
|
+
// --------------------------------------基本视图组件--------------------------------------
|
|
11
|
+
// 空白视图
|
|
12
|
+
routerResource.blank = view.blank
|
|
13
|
+
// 单页面视图
|
|
14
|
+
routerResource.singlePage = view.singlePage
|
|
15
|
+
// --------------------------------------系统配置--------------------------------------
|
|
16
|
+
routerResource.system = view.blank
|
|
17
|
+
// 字典管理
|
|
18
|
+
routerResource.dictionaryManage = () => import(/* webpackChunkName: "dictionary" */ '@vue2-client/pages/system/dictionary')
|
|
19
|
+
// 查询配置管理
|
|
20
|
+
routerResource.queryParamsManage = () => import(/* webpackChunkName: "queryParams" */ '@vue2-client/pages/system/queryParams')
|
|
21
|
+
// 系统问题反馈工单
|
|
22
|
+
routerResource.submitTicket = () => import(/* webpackChunkName: "submitTicket" */ '@vue2-client/pages/system/ticket')
|
|
23
|
+
// --------------------------------------报表组件--------------------------------------
|
|
24
|
+
routerResource.reportTable = () => import(/* webpackChunkName: "ReportTableHome" */ '@vue2-client/pages/report/ReportTableHome')
|
|
25
|
+
// --------------------------------------资源管理--------------------------------------
|
|
26
|
+
routerResource.resourceManageMain = () => import(/* webpackChunkName: "resourceManageMain" */ '@vue2-client/pages/resourceManage/resourceManageMain')
|
|
27
|
+
|
|
28
|
+
// 基础路由组件注册
|
|
29
|
+
const routerMap = {
|
|
30
|
+
login: {
|
|
31
|
+
authority: '*',
|
|
32
|
+
path: '/login',
|
|
33
|
+
component: () => import('@vue2-client/pages/login')
|
|
34
|
+
},
|
|
35
|
+
root: {
|
|
36
|
+
path: '/',
|
|
37
|
+
name: '首页',
|
|
38
|
+
redirect: '/login',
|
|
39
|
+
component: view.tabs
|
|
40
|
+
},
|
|
41
|
+
exp403: {
|
|
42
|
+
authority: '*',
|
|
43
|
+
name: 'exp403',
|
|
44
|
+
path: '403',
|
|
45
|
+
component: () => import('@vue2-client/pages/exception/403')
|
|
46
|
+
},
|
|
47
|
+
exp404: {
|
|
48
|
+
name: 'exp404',
|
|
49
|
+
path: '404',
|
|
50
|
+
component: () => import('@vue2-client/pages/exception/404')
|
|
51
|
+
},
|
|
52
|
+
exp500: {
|
|
53
|
+
name: 'exp500',
|
|
54
|
+
path: '500',
|
|
55
|
+
component: () => import('@vue2-client/pages/exception/500')
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
Object.assign(routerMap, routerResource)
|
|
59
|
+
export default routerMap
|
package/src/router/index.js
CHANGED
|
@@ -1,27 +1,27 @@
|
|
|
1
|
-
import { formatRoutes } from '@vue2-client/utils/routerUtil'
|
|
2
|
-
|
|
3
|
-
// 不需要登录拦截的路由配置
|
|
4
|
-
const loginIgnore = {
|
|
5
|
-
names: ['404', '403'], // 根据路由名称匹配
|
|
6
|
-
paths: ['/login'], // 根据路由fullPath匹配
|
|
7
|
-
/**
|
|
8
|
-
* 判断路由是否包含在该配置中
|
|
9
|
-
* @param route vue-router 的 route 对象
|
|
10
|
-
* @returns {boolean}
|
|
11
|
-
*/
|
|
12
|
-
includes (route) {
|
|
13
|
-
return this.names.includes(route.name) || this.paths.includes(route.path)
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* 初始化路由实例
|
|
19
|
-
* @param isAsync 是否异步路由模式
|
|
20
|
-
* @returns {RouterOptions}
|
|
21
|
-
*/
|
|
22
|
-
function initRouter (isAsync) {
|
|
23
|
-
const options = require('./async/config.async').default
|
|
24
|
-
formatRoutes(options.routes)
|
|
25
|
-
return options
|
|
26
|
-
}
|
|
27
|
-
export { loginIgnore, initRouter }
|
|
1
|
+
import { formatRoutes } from '@vue2-client/utils/routerUtil'
|
|
2
|
+
|
|
3
|
+
// 不需要登录拦截的路由配置
|
|
4
|
+
const loginIgnore = {
|
|
5
|
+
names: ['404', '403'], // 根据路由名称匹配
|
|
6
|
+
paths: ['/login', '/submitTicket'], // 根据路由fullPath匹配
|
|
7
|
+
/**
|
|
8
|
+
* 判断路由是否包含在该配置中
|
|
9
|
+
* @param route vue-router 的 route 对象
|
|
10
|
+
* @returns {boolean}
|
|
11
|
+
*/
|
|
12
|
+
includes (route) {
|
|
13
|
+
return this.names.includes(route.name) || this.paths.includes(route.path)
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* 初始化路由实例
|
|
19
|
+
* @param isAsync 是否异步路由模式
|
|
20
|
+
* @returns {RouterOptions}
|
|
21
|
+
*/
|
|
22
|
+
function initRouter (isAsync) {
|
|
23
|
+
const options = require('./async/config.async').default
|
|
24
|
+
formatRoutes(options.routes)
|
|
25
|
+
return options
|
|
26
|
+
}
|
|
27
|
+
export { loginIgnore, initRouter }
|
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
import { METHOD, request } from '@vue2-client/utils/request'
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* GET请求
|
|
5
|
-
* @param url 请求地址
|
|
6
|
-
* @param parameter 路径参数
|
|
7
|
-
* @returns {Promise<AxiosResponse<T>>}
|
|
8
|
-
*/
|
|
9
|
-
function get (url, parameter) {
|
|
10
|
-
return request(url, METHOD.GET, parameter)
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* POST请求
|
|
15
|
-
* @param url 请求地址
|
|
16
|
-
* @param parameter 请求参数
|
|
17
|
-
* @param config
|
|
18
|
-
* @returns {Promise<AxiosResponse<T>>}
|
|
19
|
-
*/
|
|
20
|
-
function post (url, parameter, config = {}) {
|
|
21
|
-
return request(url, METHOD.POST, parameter, config)
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export { get, post }
|
|
1
|
+
import { METHOD, request } from '@vue2-client/utils/request'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* GET请求
|
|
5
|
+
* @param url 请求地址
|
|
6
|
+
* @param parameter 路径参数
|
|
7
|
+
* @returns {Promise<AxiosResponse<T>>}
|
|
8
|
+
*/
|
|
9
|
+
function get (url, parameter) {
|
|
10
|
+
return request(url, METHOD.GET, parameter)
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* POST请求
|
|
15
|
+
* @param url 请求地址
|
|
16
|
+
* @param parameter 请求参数
|
|
17
|
+
* @param config
|
|
18
|
+
* @returns {Promise<AxiosResponse<T>>}
|
|
19
|
+
*/
|
|
20
|
+
function post (url, parameter, config = {}) {
|
|
21
|
+
return request(url, METHOD.POST, parameter, config)
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export { get, post }
|
package/src/utils/request.js
CHANGED
|
@@ -1,198 +1,198 @@
|
|
|
1
|
-
import axios from 'axios'
|
|
2
|
-
import Cookie from 'js-cookie'
|
|
3
|
-
import Vue from 'vue'
|
|
4
|
-
import { ACCESS_TOKEN } from '@vue2-client/store/mutation-types'
|
|
5
|
-
import notification from 'ant-design-vue/es/notification'
|
|
6
|
-
|
|
7
|
-
// 跨域认证信息 header 名
|
|
8
|
-
const xsrfHeaderName = 'Authorization'
|
|
9
|
-
|
|
10
|
-
axios.defaults.timeout = 5000
|
|
11
|
-
axios.defaults.withCredentials = true
|
|
12
|
-
axios.defaults.xsrfHeaderName = xsrfHeaderName
|
|
13
|
-
axios.defaults.xsrfCookieName = xsrfHeaderName
|
|
14
|
-
|
|
15
|
-
// 认证类型
|
|
16
|
-
const AUTH_TYPE = {
|
|
17
|
-
BEARER: 'Bearer',
|
|
18
|
-
BASIC: 'basic',
|
|
19
|
-
AUTH1: 'auth1',
|
|
20
|
-
AUTH2: 'auth2'
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
// http method
|
|
24
|
-
const METHOD = {
|
|
25
|
-
GET: 'get',
|
|
26
|
-
POST: 'post'
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* axios请求
|
|
31
|
-
* @param url 请求地址
|
|
32
|
-
* @param method {METHOD} http method
|
|
33
|
-
* @param params 请求参数
|
|
34
|
-
* @param config
|
|
35
|
-
* @returns {Promise<AxiosResponse<T>>}
|
|
36
|
-
*/
|
|
37
|
-
async function request (url, method, params, config) {
|
|
38
|
-
switch (method) {
|
|
39
|
-
case METHOD.GET:
|
|
40
|
-
return axios.get(url, { params, ...config })
|
|
41
|
-
case METHOD.POST:
|
|
42
|
-
return axios.post(url, params, config)
|
|
43
|
-
default:
|
|
44
|
-
return axios.get(url, { params, ...config })
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* 设置认证信息
|
|
50
|
-
* @param auth {Object}
|
|
51
|
-
* @param authType {AUTH_TYPE} 认证类型,默认:{AUTH_TYPE.BEARER}
|
|
52
|
-
*/
|
|
53
|
-
function setAuthorization (auth, authType = AUTH_TYPE.BEARER) {
|
|
54
|
-
switch (authType) {
|
|
55
|
-
case AUTH_TYPE.BEARER:
|
|
56
|
-
Cookie.set(xsrfHeaderName, 'Bearer ' + auth.token, { expires: auth.expireAt })
|
|
57
|
-
break
|
|
58
|
-
case AUTH_TYPE.BASIC:
|
|
59
|
-
case AUTH_TYPE.AUTH1:
|
|
60
|
-
case AUTH_TYPE.AUTH2:
|
|
61
|
-
default:
|
|
62
|
-
break
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
/**
|
|
67
|
-
* 移出认证信息
|
|
68
|
-
* @param authType {AUTH_TYPE} 认证类型
|
|
69
|
-
*/
|
|
70
|
-
function removeAuthorization (authType = AUTH_TYPE.BEARER) {
|
|
71
|
-
switch (authType) {
|
|
72
|
-
case AUTH_TYPE.BEARER:
|
|
73
|
-
Cookie.remove(xsrfHeaderName)
|
|
74
|
-
break
|
|
75
|
-
case AUTH_TYPE.BASIC:
|
|
76
|
-
case AUTH_TYPE.AUTH1:
|
|
77
|
-
case AUTH_TYPE.AUTH2:
|
|
78
|
-
default:
|
|
79
|
-
break
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
/**
|
|
84
|
-
* 检查认证信息
|
|
85
|
-
* @param authType
|
|
86
|
-
* @returns {boolean}
|
|
87
|
-
*/
|
|
88
|
-
function checkAuthorization (authType = AUTH_TYPE.BEARER) {
|
|
89
|
-
switch (authType) {
|
|
90
|
-
case AUTH_TYPE.BEARER:
|
|
91
|
-
if (Cookie.get(xsrfHeaderName)) {
|
|
92
|
-
return true
|
|
93
|
-
}
|
|
94
|
-
break
|
|
95
|
-
case AUTH_TYPE.BASIC:
|
|
96
|
-
case AUTH_TYPE.AUTH1:
|
|
97
|
-
case AUTH_TYPE.AUTH2:
|
|
98
|
-
default:
|
|
99
|
-
break
|
|
100
|
-
}
|
|
101
|
-
return false
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
/**
|
|
105
|
-
* 加载 axios 拦截器
|
|
106
|
-
* @param interceptors
|
|
107
|
-
* @param options
|
|
108
|
-
*/
|
|
109
|
-
function loadInterceptors () {
|
|
110
|
-
// 加载请求拦截器
|
|
111
|
-
axios.interceptors.request.use(config => {
|
|
112
|
-
const token = localStorage.getItem(ACCESS_TOKEN)
|
|
113
|
-
// 如果 token 存在
|
|
114
|
-
// 让每个请求携带自定义 token 请根据实际情况自行修改
|
|
115
|
-
if (token) {
|
|
116
|
-
config.headers['Access-Token'] = token
|
|
117
|
-
}
|
|
118
|
-
if (!config.headers['Content-Type']) {
|
|
119
|
-
config.headers['Content-Type'] = 'application/json;charset=UTF-8'
|
|
120
|
-
}
|
|
121
|
-
return config
|
|
122
|
-
}, errorHandler)
|
|
123
|
-
// 加载响应拦截器
|
|
124
|
-
axios.interceptors.response.use((response) => {
|
|
125
|
-
return response.data
|
|
126
|
-
}, errorHandler)
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
// 异常拦截处理器
|
|
130
|
-
const errorHandler = (error) => {
|
|
131
|
-
if (error.response) {
|
|
132
|
-
const data = error.response.data
|
|
133
|
-
// 从 localstorage 获取 token
|
|
134
|
-
const token = localStorage.getItem(ACCESS_TOKEN)
|
|
135
|
-
if (error.response.status === 403) {
|
|
136
|
-
notification.error({
|
|
137
|
-
message: '禁止访问',
|
|
138
|
-
description: data
|
|
139
|
-
})
|
|
140
|
-
} else if (error.response.status === 401 && !(data.result && data.result.isLogin)) {
|
|
141
|
-
notification.error({
|
|
142
|
-
message: '鉴权失败',
|
|
143
|
-
description: data
|
|
144
|
-
})
|
|
145
|
-
if (token) {
|
|
146
|
-
Vue.$store.dispatch('Logout').then(() => {
|
|
147
|
-
setTimeout(() => {
|
|
148
|
-
window.location.reload()
|
|
149
|
-
}, 1500)
|
|
150
|
-
})
|
|
151
|
-
}
|
|
152
|
-
} else if (error.response.status === 500) {
|
|
153
|
-
notification.error({
|
|
154
|
-
message: '系统异常',
|
|
155
|
-
description: data
|
|
156
|
-
})
|
|
157
|
-
} else {
|
|
158
|
-
notification.error({
|
|
159
|
-
message: '数据异常',
|
|
160
|
-
description: data
|
|
161
|
-
})
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
return Promise.reject(error)
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
/**
|
|
168
|
-
* 解析 url 中的参数
|
|
169
|
-
* @param url
|
|
170
|
-
* @returns {Object}
|
|
171
|
-
*/
|
|
172
|
-
function parseUrlParams (url) {
|
|
173
|
-
const params = {}
|
|
174
|
-
if (!url || url === '' || typeof url !== 'string') {
|
|
175
|
-
return params
|
|
176
|
-
}
|
|
177
|
-
const paramsStr = url.split('?')[1]
|
|
178
|
-
if (!paramsStr) {
|
|
179
|
-
return params
|
|
180
|
-
}
|
|
181
|
-
const paramsArr = paramsStr.replace(/&|=/g, ' ').split(' ')
|
|
182
|
-
for (let i = 0; i < paramsArr.length / 2; i++) {
|
|
183
|
-
const value = paramsArr[i * 2 + 1]
|
|
184
|
-
params[paramsArr[i * 2]] = value === 'true' ? true : (value === 'false' ? false : value)
|
|
185
|
-
}
|
|
186
|
-
return params
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
export {
|
|
190
|
-
METHOD,
|
|
191
|
-
AUTH_TYPE,
|
|
192
|
-
request,
|
|
193
|
-
setAuthorization,
|
|
194
|
-
removeAuthorization,
|
|
195
|
-
checkAuthorization,
|
|
196
|
-
loadInterceptors,
|
|
197
|
-
parseUrlParams
|
|
198
|
-
}
|
|
1
|
+
import axios from 'axios'
|
|
2
|
+
import Cookie from 'js-cookie'
|
|
3
|
+
import Vue from 'vue'
|
|
4
|
+
import { ACCESS_TOKEN } from '@vue2-client/store/mutation-types'
|
|
5
|
+
import notification from 'ant-design-vue/es/notification'
|
|
6
|
+
|
|
7
|
+
// 跨域认证信息 header 名
|
|
8
|
+
const xsrfHeaderName = 'Authorization'
|
|
9
|
+
|
|
10
|
+
axios.defaults.timeout = 5000
|
|
11
|
+
axios.defaults.withCredentials = true
|
|
12
|
+
axios.defaults.xsrfHeaderName = xsrfHeaderName
|
|
13
|
+
axios.defaults.xsrfCookieName = xsrfHeaderName
|
|
14
|
+
|
|
15
|
+
// 认证类型
|
|
16
|
+
const AUTH_TYPE = {
|
|
17
|
+
BEARER: 'Bearer',
|
|
18
|
+
BASIC: 'basic',
|
|
19
|
+
AUTH1: 'auth1',
|
|
20
|
+
AUTH2: 'auth2'
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// http method
|
|
24
|
+
const METHOD = {
|
|
25
|
+
GET: 'get',
|
|
26
|
+
POST: 'post'
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* axios请求
|
|
31
|
+
* @param url 请求地址
|
|
32
|
+
* @param method {METHOD} http method
|
|
33
|
+
* @param params 请求参数
|
|
34
|
+
* @param config
|
|
35
|
+
* @returns {Promise<AxiosResponse<T>>}
|
|
36
|
+
*/
|
|
37
|
+
async function request (url, method, params, config) {
|
|
38
|
+
switch (method) {
|
|
39
|
+
case METHOD.GET:
|
|
40
|
+
return axios.get(url, { params, ...config })
|
|
41
|
+
case METHOD.POST:
|
|
42
|
+
return axios.post(url, params, config)
|
|
43
|
+
default:
|
|
44
|
+
return axios.get(url, { params, ...config })
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* 设置认证信息
|
|
50
|
+
* @param auth {Object}
|
|
51
|
+
* @param authType {AUTH_TYPE} 认证类型,默认:{AUTH_TYPE.BEARER}
|
|
52
|
+
*/
|
|
53
|
+
function setAuthorization (auth, authType = AUTH_TYPE.BEARER) {
|
|
54
|
+
switch (authType) {
|
|
55
|
+
case AUTH_TYPE.BEARER:
|
|
56
|
+
Cookie.set(xsrfHeaderName, 'Bearer ' + auth.token, { expires: auth.expireAt })
|
|
57
|
+
break
|
|
58
|
+
case AUTH_TYPE.BASIC:
|
|
59
|
+
case AUTH_TYPE.AUTH1:
|
|
60
|
+
case AUTH_TYPE.AUTH2:
|
|
61
|
+
default:
|
|
62
|
+
break
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* 移出认证信息
|
|
68
|
+
* @param authType {AUTH_TYPE} 认证类型
|
|
69
|
+
*/
|
|
70
|
+
function removeAuthorization (authType = AUTH_TYPE.BEARER) {
|
|
71
|
+
switch (authType) {
|
|
72
|
+
case AUTH_TYPE.BEARER:
|
|
73
|
+
Cookie.remove(xsrfHeaderName)
|
|
74
|
+
break
|
|
75
|
+
case AUTH_TYPE.BASIC:
|
|
76
|
+
case AUTH_TYPE.AUTH1:
|
|
77
|
+
case AUTH_TYPE.AUTH2:
|
|
78
|
+
default:
|
|
79
|
+
break
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* 检查认证信息
|
|
85
|
+
* @param authType
|
|
86
|
+
* @returns {boolean}
|
|
87
|
+
*/
|
|
88
|
+
function checkAuthorization (authType = AUTH_TYPE.BEARER) {
|
|
89
|
+
switch (authType) {
|
|
90
|
+
case AUTH_TYPE.BEARER:
|
|
91
|
+
if (Cookie.get(xsrfHeaderName)) {
|
|
92
|
+
return true
|
|
93
|
+
}
|
|
94
|
+
break
|
|
95
|
+
case AUTH_TYPE.BASIC:
|
|
96
|
+
case AUTH_TYPE.AUTH1:
|
|
97
|
+
case AUTH_TYPE.AUTH2:
|
|
98
|
+
default:
|
|
99
|
+
break
|
|
100
|
+
}
|
|
101
|
+
return false
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* 加载 axios 拦截器
|
|
106
|
+
* @param interceptors
|
|
107
|
+
* @param options
|
|
108
|
+
*/
|
|
109
|
+
function loadInterceptors () {
|
|
110
|
+
// 加载请求拦截器
|
|
111
|
+
axios.interceptors.request.use(config => {
|
|
112
|
+
const token = localStorage.getItem(ACCESS_TOKEN)
|
|
113
|
+
// 如果 token 存在
|
|
114
|
+
// 让每个请求携带自定义 token 请根据实际情况自行修改
|
|
115
|
+
if (token) {
|
|
116
|
+
config.headers['Access-Token'] = token
|
|
117
|
+
}
|
|
118
|
+
if (!config.headers['Content-Type']) {
|
|
119
|
+
config.headers['Content-Type'] = 'application/json;charset=UTF-8'
|
|
120
|
+
}
|
|
121
|
+
return config
|
|
122
|
+
}, errorHandler)
|
|
123
|
+
// 加载响应拦截器
|
|
124
|
+
axios.interceptors.response.use((response) => {
|
|
125
|
+
return response.data
|
|
126
|
+
}, errorHandler)
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
// 异常拦截处理器
|
|
130
|
+
const errorHandler = (error) => {
|
|
131
|
+
if (error.response) {
|
|
132
|
+
const data = error.response.data
|
|
133
|
+
// 从 localstorage 获取 token
|
|
134
|
+
const token = localStorage.getItem(ACCESS_TOKEN)
|
|
135
|
+
if (error.response.status === 403) {
|
|
136
|
+
notification.error({
|
|
137
|
+
message: '禁止访问',
|
|
138
|
+
description: data
|
|
139
|
+
})
|
|
140
|
+
} else if (error.response.status === 401 && !(data.result && data.result.isLogin)) {
|
|
141
|
+
notification.error({
|
|
142
|
+
message: '鉴权失败',
|
|
143
|
+
description: data
|
|
144
|
+
})
|
|
145
|
+
if (token) {
|
|
146
|
+
Vue.$store.dispatch('Logout').then(() => {
|
|
147
|
+
setTimeout(() => {
|
|
148
|
+
window.location.reload()
|
|
149
|
+
}, 1500)
|
|
150
|
+
})
|
|
151
|
+
}
|
|
152
|
+
} else if (error.response.status === 500) {
|
|
153
|
+
notification.error({
|
|
154
|
+
message: '系统异常',
|
|
155
|
+
description: data
|
|
156
|
+
})
|
|
157
|
+
} else {
|
|
158
|
+
notification.error({
|
|
159
|
+
message: '数据异常',
|
|
160
|
+
description: data
|
|
161
|
+
})
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
return Promise.reject(error)
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* 解析 url 中的参数
|
|
169
|
+
* @param url
|
|
170
|
+
* @returns {Object}
|
|
171
|
+
*/
|
|
172
|
+
function parseUrlParams (url) {
|
|
173
|
+
const params = {}
|
|
174
|
+
if (!url || url === '' || typeof url !== 'string') {
|
|
175
|
+
return params
|
|
176
|
+
}
|
|
177
|
+
const paramsStr = url.split('?')[1]
|
|
178
|
+
if (!paramsStr) {
|
|
179
|
+
return params
|
|
180
|
+
}
|
|
181
|
+
const paramsArr = paramsStr.replace(/&|=/g, ' ').split(' ')
|
|
182
|
+
for (let i = 0; i < paramsArr.length / 2; i++) {
|
|
183
|
+
const value = paramsArr[i * 2 + 1]
|
|
184
|
+
params[paramsArr[i * 2]] = value === 'true' ? true : (value === 'false' ? false : value)
|
|
185
|
+
}
|
|
186
|
+
return params
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
export {
|
|
190
|
+
METHOD,
|
|
191
|
+
AUTH_TYPE,
|
|
192
|
+
request,
|
|
193
|
+
setAuthorization,
|
|
194
|
+
removeAuthorization,
|
|
195
|
+
checkAuthorization,
|
|
196
|
+
loadInterceptors,
|
|
197
|
+
parseUrlParams
|
|
198
|
+
}
|