Merge remote-tracking branch 'origin/dev' into bus
Showing
7 changed files
with
175 additions
and
44 deletions
1 | <!-- | 1 | <!-- |
2 | * @Description: | 2 | * @Description: |
3 | * @Autor: renchao | 3 | * @Autor: renchao |
4 | <<<<<<< HEAD | ||
4 | * @LastEditTime: 2023-05-30 15:08:51 | 5 | * @LastEditTime: 2023-05-30 15:08:51 |
6 | ======= | ||
7 | * @LastEditTime: 2023-05-26 16:57:47 | ||
8 | >>>>>>> origin/dev | ||
5 | --> | 9 | --> |
6 | <!DOCTYPE html> | 10 | <!DOCTYPE html> |
7 | <html> | 11 | <html> |
... | @@ -18,8 +22,24 @@ | ... | @@ -18,8 +22,24 @@ |
18 | </title> | 22 | </title> |
19 | </head> | 23 | </head> |
20 | <script> | 24 | <script> |
25 | <<<<<<< HEAD | ||
21 | window.baseUrl = location.origin || location.protocol + '//' + location.host | 26 | window.baseUrl = location.origin || location.protocol + '//' + location.host |
22 | const authorization = "bearer ATT-7-TiYJVcoDnfhNGs160E6MbQ-QA9Ot3Tby" | 27 | const authorization = "bearer ATT-7-TiYJVcoDnfhNGs160E6MbQ-QA9Ot3Tby" |
28 | ======= | ||
29 | window._config = { | ||
30 | // 是否微服务模式,业务系统根据需要读取 | ||
31 | cloudEnable: false, | ||
32 | // 是否启用单点登录 | ||
33 | casEnable: true, | ||
34 | // cas 基地址 | ||
35 | casBaseURL: 'http://192.168.2.38/cas', | ||
36 | services: { | ||
37 | // 配置到 contextPath 前一级 | ||
38 | management: 'http://192.168.2.38', | ||
39 | business: 'http://localhost:7001' | ||
40 | } | ||
41 | } | ||
42 | >>>>>>> origin/dev | ||
23 | fetch('<%= BASE_URL %>config.json') | 43 | fetch('<%= BASE_URL %>config.json') |
24 | .then(response => response.json()) | 44 | .then(response => response.json()) |
25 | .then(config => { | 45 | .then(config => { | ... | ... |
1 | /* | 1 | /* |
2 | * @Description: 项目权限 | 2 | * @Description: 项目权限 |
3 | * @Autor: renchao | 3 | * @Autor: renchao |
4 | * @LastEditTime: 2023-05-16 14:10:26 | 4 | * @LastEditTime: 2023-05-30 16:27:26 |
5 | */ | 5 | */ |
6 | import Vue from 'vue' | 6 | import Vue from 'vue' |
7 | import router from './router' | 7 | import router from './router' |
8 | import store from './store' | 8 | import store from './store' |
9 | import axios from 'axios' | ||
9 | import { getMenuInfo } from '@/api/user' | 10 | import { getMenuInfo } from '@/api/user' |
11 | import { getUrlParam } from '@/utils/operation' | ||
10 | import NProgress from 'nprogress' // progress bar | 12 | import NProgress from 'nprogress' // progress bar |
11 | import 'nprogress/nprogress.css' // progress bar style | 13 | import 'nprogress/nprogress.css' // progress bar style |
12 | import getPageTitle from '@/utils/get-page-title' | 14 | import getPageTitle from '@/utils/get-page-title' |
... | @@ -19,24 +21,76 @@ router.beforeEach(async (to, from, next) => { | ... | @@ -19,24 +21,76 @@ router.beforeEach(async (to, from, next) => { |
19 | document.title = getPageTitle(to.meta.title) | 21 | document.title = getPageTitle(to.meta.title) |
20 | let hasAddDict = store.state.dict.addDict | 22 | let hasAddDict = store.state.dict.addDict |
21 | let hasAddRoute = store.state.permission.addRoutes | 23 | let hasAddRoute = store.state.permission.addRoutes |
22 | if (!hasAddDict) { | 24 | // cas操作 |
23 | store.dispatch('dict/generateDic') | 25 | const token = localStorage.getItem("token") |
26 | if (to.path === '/login') { | ||
27 | if (token) { | ||
28 | next('/') | ||
29 | } else { | ||
30 | next() | ||
31 | } | ||
32 | return | ||
24 | } | 33 | } |
25 | if (hasAddRoute) { | 34 | if (window._config.casEnable === true) { |
26 | next() | 35 | let locationUrl = window.location.protocol + '//' + window.location.host + window.location.pathname; |
27 | // next({ ...to, replace: true }) | 36 | if (!token) { |
28 | } else { | 37 | let ticket = getUrlParam('ticket'); |
29 | const { result: getMenuData } = await getMenuInfo() | 38 | if (ticket) { |
30 | const accessRoutes = await store.dispatch('permission/generateRoutes', getMenuData) | 39 | axios.get("http://192.168.2.38/management/cas/validate", { |
31 | // 获取用户信息 | 40 | params: { |
32 | await store.dispatch('user/getUserInfo') | 41 | 'ticket': ticket, |
33 | router.addRoutes([...accessRoutes, { path: '*', redirect: '/404', hidden: true }]) | 42 | 'service': locationUrl |
34 | const routeTo = Cookies.get('routerTo') | 43 | } |
35 | if (routeTo && routeTo !== '/') { | 44 | }).then(async (res) => { |
36 | next({ ...to, replace: true }) | 45 | localStorage.setItem('token', res.data.content.accessToken) |
46 | window.location.href = localStorage.getItem('location') | ||
47 | // cas | ||
48 | if (!hasAddDict) { | ||
49 | store.dispatch('dict/generateDic') | ||
50 | } | ||
51 | if (hasAddRoute) { | ||
52 | next() | ||
53 | // next({ ...to, replace: true }) | ||
54 | } else { | ||
55 | const { result: getMenuData } = await getMenuInfo() | ||
56 | const accessRoutes = await store.dispatch('permission/generateRoutes', getMenuData) | ||
57 | // 获取用户信息 | ||
58 | await store.dispatch('user/getUserInfo') | ||
59 | router.addRoutes([...accessRoutes, { path: '*', redirect: '/404', hidden: true }]) | ||
60 | const routeTo = Cookies.get('routerTo') | ||
61 | if (routeTo && routeTo !== '/') { | ||
62 | next({ ...to, replace: true }) | ||
63 | } else { | ||
64 | next('/home') | ||
65 | } | ||
66 | } | ||
67 | |||
68 | }).catch(e => { | ||
69 | console.log(e) | ||
70 | }) | ||
71 | } else { | ||
72 | localStorage.setItem("location", window.location.href) | ||
73 | window.location.href = window._config.casBaseURL + '/login?service=' + encodeURIComponent(locationUrl); | ||
74 | } | ||
37 | } else { | 75 | } else { |
38 | next('/home') | 76 | next() |
77 | } | ||
78 | } else { | ||
79 | if (!token) { | ||
80 | const redirectData = { | ||
81 | path: '/login', | ||
82 | replace: true, | ||
83 | } | ||
84 | if (to.path) { | ||
85 | redirectData.query = { | ||
86 | ...redirectData.query, | ||
87 | redirect: to.path, | ||
88 | }; | ||
89 | } | ||
90 | next(redirectData) | ||
91 | return | ||
39 | } | 92 | } |
93 | next() | ||
40 | } | 94 | } |
41 | NProgress.done() | 95 | NProgress.done() |
42 | }) | 96 | }) | ... | ... |
1 | /* | 1 | /* |
2 | * @Description: 全局路由 | 2 | * @Description: 全局路由 |
3 | * @Autor: renchao | 3 | * @Autor: renchao |
4 | * @LastEditTime: 2023-05-16 14:09:37 | 4 | * @LastEditTime: 2023-05-26 17:11:19 |
5 | */ | 5 | */ |
6 | import Vue from 'vue' | 6 | import Vue from 'vue' |
7 | import Router from 'vue-router' | 7 | import Router from 'vue-router' | ... | ... |
1 | @import "~@/styles/mixin.scss"; | 1 | @import "~@/styles/mixin.scss"; |
2 | .dialogBox { | 2 | .dialogBox { |
3 | border-radius: 8px; | 3 | border-radius: 4px; |
4 | overflow: hidden; | 4 | overflow: hidden; |
5 | background: #FFFFFF; | 5 | background: #FFFFFF; |
6 | box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.10); | 6 | box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.10); |
... | @@ -8,15 +8,33 @@ | ... | @@ -8,15 +8,33 @@ |
8 | .dialog_title { | 8 | .dialog_title { |
9 | display: flex; | 9 | display: flex; |
10 | position: relative; | 10 | position: relative; |
11 | top: -2px; | 11 | top: -4px; |
12 | 12 | ||
13 | b { | 13 | b { |
14 | @include flex-center; | 14 | display: flex; |
15 | justify-content:left; | ||
16 | align-items: center; | ||
15 | flex: 1; | 17 | flex: 1; |
16 | width: 100%; | 18 | width: 100%; |
19 | margin-left: 10px; | ||
20 | width: 79px; | ||
21 | height: 12px; | ||
22 | font-size: 16px; | ||
23 | font-family: AlibabaPuHuiTi_2_65_Medium; | ||
24 | color: #31333C; | ||
25 | line-height: 10px; | ||
17 | } | 26 | } |
18 | } | 27 | } |
19 | 28 | .dialog_title::before{ | |
29 | content: ""; | ||
30 | display: block; | ||
31 | width: 4px; | ||
32 | height: 18px; | ||
33 | background: #2E74D8; | ||
34 | position: absolute; | ||
35 | top: -4px; | ||
36 | left: 0px; | ||
37 | } | ||
20 | .dialog_full { | 38 | .dialog_full { |
21 | position: absolute; | 39 | position: absolute; |
22 | top: 0; | 40 | top: 0; |
... | @@ -46,10 +64,7 @@ | ... | @@ -46,10 +64,7 @@ |
46 | } | 64 | } |
47 | 65 | ||
48 | .el-dialog__header { | 66 | .el-dialog__header { |
49 | margin-bottom: 10px; | 67 | background: linear-gradient(270deg, #F2F3FB 0%, #5C95E5 100%); |
50 | color: #FFFFFF; | ||
51 | background-color: #FCFDFD; | ||
52 | border-bottom: 1px solid #E4EBF4; | ||
53 | } | 68 | } |
54 | 69 | ||
55 | .el-dialog__body { | 70 | .el-dialog__body { |
... | @@ -87,4 +102,4 @@ | ... | @@ -87,4 +102,4 @@ |
87 | top: 50% !important; | 102 | top: 50% !important; |
88 | left: 50% !important; | 103 | left: 50% !important; |
89 | transform: translate(-50%, -50%) !important; | 104 | transform: translate(-50%, -50%) !important; |
90 | } | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
105 | } | ... | ... |
... | @@ -110,3 +110,26 @@ export function down (index, data) { | ... | @@ -110,3 +110,26 @@ export function down (index, data) { |
110 | data.splice(index, 0, downData); | 110 | data.splice(index, 0, downData); |
111 | } | 111 | } |
112 | } | 112 | } |
113 | |||
114 | |||
115 | export function getUrlParam (paraName) { | ||
116 | let url = document.location.toString(); | ||
117 | let arrObj = url.split('?'); | ||
118 | |||
119 | if (arrObj.length > 1) { | ||
120 | let arrPara = arrObj[1].split('&'); | ||
121 | let arr; | ||
122 | |||
123 | for (let i = 0; i < arrPara.length; i++) { | ||
124 | arr = arrPara[i].split('='); | ||
125 | |||
126 | if (arr != null && arr[0] === paraName) { | ||
127 | const index = arr[1].indexOf("#"); | ||
128 | return arr[1].substring(0, index); | ||
129 | } | ||
130 | } | ||
131 | return ''; | ||
132 | } else { | ||
133 | return ''; | ||
134 | } | ||
135 | } | ... | ... |
1 | /* | 1 | /* |
2 | * @Description: 此文件主要创建 axios 实例,然后添加请求拦截器和响应拦截器 | 2 | * @Description: 此文件主要创建 axios 实例,然后添加请求拦截器和响应拦截器 |
3 | * @Autor: renchao | 3 | * @Autor: renchao |
4 | * @LastEditTime: 2023-05-16 14:07:58 | 4 | * @LastEditTime: 2023-05-26 16:52:25 |
5 | */ | 5 | */ |
6 | import axios from 'axios' | 6 | import axios from 'axios' |
7 | import { Message } from 'element-ui' | 7 | import { Message } from 'element-ui' |
... | @@ -9,10 +9,6 @@ import { endLoadingSubCount } from './requestLoading' | ... | @@ -9,10 +9,6 @@ import { endLoadingSubCount } from './requestLoading' |
9 | 9 | ||
10 | // create an axios instance | 10 | // create an axios instance |
11 | const service = axios.create({ | 11 | const service = axios.create({ |
12 | baseURL: | ||
13 | process.env.NODE_ENV == "development" | ||
14 | ? process.env.VUE_APP_BASE_API | ||
15 | : window.baseUrl + "/", | ||
16 | withCredentials: true, //是否允许跨域 | 12 | withCredentials: true, //是否允许跨域 |
17 | headers: { | 13 | headers: { |
18 | 'Content-Type': 'application/json; charset=utf-8' | 14 | 'Content-Type': 'application/json; charset=utf-8' |
... | @@ -23,13 +19,14 @@ const service = axios.create({ | ... | @@ -23,13 +19,14 @@ const service = axios.create({ |
23 | // request interceptor | 19 | // request interceptor |
24 | service.interceptors.request.use( | 20 | service.interceptors.request.use( |
25 | config => { | 21 | config => { |
26 | // do something before request is sent | 22 | const token = localStorage.getItem('token') |
27 | if (process.env.NODE_ENV === "production") { | 23 | // 添加请求头 |
28 | return config; | 24 | if (token) { |
25 | config.headers['Authorization'] = "Bearer " + token | ||
29 | } else { | 26 | } else { |
30 | config.headers.Authorization = authorization; | 27 | config.headers.delete('Authorization') |
31 | return config; | ||
32 | } | 28 | } |
29 | return config; | ||
33 | }, | 30 | }, |
34 | error => { | 31 | error => { |
35 | // do something with request error | 32 | // do something with request error |
... | @@ -55,13 +52,35 @@ service.interceptors.response.use( | ... | @@ -55,13 +52,35 @@ service.interceptors.response.use( |
55 | }, | 52 | }, |
56 | error => { | 53 | error => { |
57 | endLoadingSubCount() | 54 | endLoadingSubCount() |
58 | // 对响应错误做点什么 | 55 | if (error.response.status === 401) { |
59 | Message({ | 56 | //todo: 需要解决 一个页面多个请求,刷新后此处会触发多次 |
60 | message: '服务器异常,请联系管理员', | 57 | if (window.__isNeedLogin) { |
61 | type: 'error', | 58 | window.__isNeedLogin = false |
62 | duration: 5 * 1000, | 59 | this.$message.error('token失效,请重新登录'); |
63 | customClass: 'messageIndex' | 60 | let locationUrl = window.location.protocol + '//' + window.location.host + window.location.pathname; |
64 | }) | 61 | localStorage.removeItem('token') |
62 | if (window._config.casEnable) { | ||
63 | window.location.href = window._config.casBaseURL + '/logout?service=' + encodeURIComponent(locationUrl); | ||
64 | } else { | ||
65 | router.replace({ | ||
66 | path: '/login', | ||
67 | query: { | ||
68 | redirect: router.currentRoute.value.fullPath | ||
69 | } | ||
70 | }) | ||
71 | return false | ||
72 | } | ||
73 | } | ||
74 | |||
75 | } else { | ||
76 | // 对响应错误做点什么 | ||
77 | Message({ | ||
78 | message: '服务器异常,请联系管理员', | ||
79 | type: 'error', | ||
80 | duration: 5 * 1000, | ||
81 | customClass: 'messageIndex' | ||
82 | }) | ||
83 | } | ||
65 | return Promise.reject(error); | 84 | return Promise.reject(error); |
66 | } | 85 | } |
67 | ) | 86 | ) | ... | ... |
-
Please register or sign in to post a comment