style:集成cas完成
Showing
8 changed files
with
54 additions
and
32 deletions
| 1 | <!-- | 1 | <!-- |
| 2 | * @Description: | 2 | * @Description: |
| 3 | * @Autor: renchao | 3 | * @Autor: renchao |
| 4 | * @LastEditTime: 2023-05-26 16:57:47 | 4 | * @LastEditTime: 2023-05-31 15:33:18 |
| 5 | --> | 5 | --> |
| 6 | <!DOCTYPE html> | 6 | <!DOCTYPE html> |
| 7 | <html> | 7 | <html> |
| ... | @@ -18,6 +18,7 @@ | ... | @@ -18,6 +18,7 @@ |
| 18 | </title> | 18 | </title> |
| 19 | </head> | 19 | </head> |
| 20 | <script> | 20 | <script> |
| 21 | window.baseUrl = location.origin || location.protocol + '//' + location.host | ||
| 21 | window._config = { | 22 | window._config = { |
| 22 | // 是否微服务模式,业务系统根据需要读取 | 23 | // 是否微服务模式,业务系统根据需要读取 |
| 23 | cloudEnable: false, | 24 | cloudEnable: false, | ... | ... |
| ... | @@ -27,6 +27,7 @@ | ... | @@ -27,6 +27,7 @@ |
| 27 | </div> | 27 | </div> |
| 28 | </template> | 28 | </template> |
| 29 | <script> | 29 | <script> |
| 30 | import axios from 'axios' | ||
| 30 | import { mapGetters } from 'vuex' | 31 | import { mapGetters } from 'vuex' |
| 31 | import NoticeBar from '@/components/NoticeBar/index' | 32 | import NoticeBar from '@/components/NoticeBar/index' |
| 32 | import { | 33 | import { |
| ... | @@ -72,9 +73,20 @@ | ... | @@ -72,9 +73,20 @@ |
| 72 | }) | 73 | }) |
| 73 | }, | 74 | }, |
| 74 | logout () { | 75 | logout () { |
| 75 | const url = baseUrl + "/sso-logout?redirect_uri=" + baseUrl + "/bdcdj"; | 76 | axios.post(this.BASE_API.ip + "/management/logout").then(() => { |
| 76 | window.open(url, "_self"); | 77 | localStorage.removeItem('token') |
| 77 | sessionStorage.removeItem("navList"); | 78 | if (window._config.casEnable) { |
| 79 | window.location.href = window._config.casBaseURL + '/logout?service=' + encodeURIComponent(window.location.href); | ||
| 80 | } else { | ||
| 81 | this.$router.push({ | ||
| 82 | path: '/login', | ||
| 83 | replace: true, | ||
| 84 | query: { | ||
| 85 | redirect: router.currentRoute.value.fullPath | ||
| 86 | } | ||
| 87 | }) | ||
| 88 | } | ||
| 89 | }) | ||
| 78 | }, | 90 | }, |
| 79 | 91 | ||
| 80 | themeChange (val) { | 92 | themeChange (val) { | ... | ... |
| 1 | /* | 1 | /* |
| 2 | * @Description: 项目权限 | 2 | * @Description: 项目权限 |
| 3 | * @Autor: renchao | 3 | * @Autor: renchao |
| 4 | * @LastEditTime: 2023-05-30 16:27:26 | 4 | * @LastEditTime: 2023-05-31 15:55:14 |
| 5 | */ | 5 | */ |
| 6 | import Vue from 'vue' | 6 | import Vue from 'vue' |
| 7 | import router from './router' | 7 | import router from './router' |
| ... | @@ -36,7 +36,7 @@ router.beforeEach(async (to, from, next) => { | ... | @@ -36,7 +36,7 @@ router.beforeEach(async (to, from, next) => { |
| 36 | if (!token) { | 36 | if (!token) { |
| 37 | let ticket = getUrlParam('ticket'); | 37 | let ticket = getUrlParam('ticket'); |
| 38 | if (ticket) { | 38 | if (ticket) { |
| 39 | axios.get("http://192.168.2.38/management/cas/validate", { | 39 | axios.get(Vue.prototype.BASE_API.ip + "/management/cas/validate", { |
| 40 | params: { | 40 | params: { |
| 41 | 'ticket': ticket, | 41 | 'ticket': ticket, |
| 42 | 'service': locationUrl | 42 | 'service': locationUrl |
| ... | @@ -44,26 +44,6 @@ router.beforeEach(async (to, from, next) => { | ... | @@ -44,26 +44,6 @@ router.beforeEach(async (to, from, next) => { |
| 44 | }).then(async (res) => { | 44 | }).then(async (res) => { |
| 45 | localStorage.setItem('token', res.data.content.accessToken) | 45 | localStorage.setItem('token', res.data.content.accessToken) |
| 46 | window.location.href = localStorage.getItem('location') | 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 | 47 | ||
| 68 | }).catch(e => { | 48 | }).catch(e => { |
| 69 | console.log(e) | 49 | console.log(e) |
| ... | @@ -71,9 +51,31 @@ router.beforeEach(async (to, from, next) => { | ... | @@ -71,9 +51,31 @@ router.beforeEach(async (to, from, next) => { |
| 71 | } else { | 51 | } else { |
| 72 | localStorage.setItem("location", window.location.href) | 52 | localStorage.setItem("location", window.location.href) |
| 73 | window.location.href = window._config.casBaseURL + '/login?service=' + encodeURIComponent(locationUrl); | 53 | window.location.href = window._config.casBaseURL + '/login?service=' + encodeURIComponent(locationUrl); |
| 54 | permission() | ||
| 74 | } | 55 | } |
| 75 | } else { | 56 | } else { |
| 76 | next() | 57 | permission() |
| 58 | } | ||
| 59 | async function permission () { | ||
| 60 | if (!hasAddDict) { | ||
| 61 | store.dispatch('dict/generateDic') | ||
| 62 | } | ||
| 63 | if (hasAddRoute) { | ||
| 64 | next() | ||
| 65 | // next({ ...to, replace: true }) | ||
| 66 | } else { | ||
| 67 | const { result: getMenuData } = await getMenuInfo() | ||
| 68 | const accessRoutes = await store.dispatch('permission/generateRoutes', getMenuData) | ||
| 69 | // 获取用户信息 | ||
| 70 | await store.dispatch('user/getUserInfo') | ||
| 71 | router.addRoutes([...accessRoutes, { path: '*', redirect: '/404', hidden: true }]) | ||
| 72 | const routeTo = Cookies.get('routerTo') | ||
| 73 | if (routeTo && routeTo !== '/') { | ||
| 74 | next({ ...to, replace: true }) | ||
| 75 | } else { | ||
| 76 | next('/home') | ||
| 77 | } | ||
| 78 | } | ||
| 77 | } | 79 | } |
| 78 | } else { | 80 | } else { |
| 79 | if (!token) { | 81 | if (!token) { | ... | ... |
| 1 | /* | 1 | /* |
| 2 | * @Description: 此文件主要创建 axios 实例,然后添加请求拦截器和响应拦截器 | 2 | * @Description: 此文件主要创建 axios 实例,然后添加请求拦截器和响应拦截器 |
| 3 | * @Autor: renchao | 3 | * @Autor: renchao |
| 4 | * @LastEditTime: 2023-05-26 16:52:25 | 4 | * @LastEditTime: 2023-05-31 15:30:02 |
| 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,6 +9,10 @@ import { endLoadingSubCount } from './requestLoading' | ... | @@ -9,6 +9,10 @@ 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 + "/", | ||
| 12 | withCredentials: true, //是否允许跨域 | 16 | withCredentials: true, //是否允许跨域 |
| 13 | headers: { | 17 | headers: { |
| 14 | 'Content-Type': 'application/json; charset=utf-8' | 18 | 'Content-Type': 'application/json; charset=utf-8' | ... | ... |
| ... | @@ -18,7 +18,7 @@ module.exports = { | ... | @@ -18,7 +18,7 @@ module.exports = { |
| 18 | * Detail: https://cli.vuejs.org/config/#publicpath | 18 | * Detail: https://cli.vuejs.org/config/#publicpath |
| 19 | */ | 19 | */ |
| 20 | // 加载资源的路径 | 20 | // 加载资源的路径 |
| 21 | publicPath: '/bdcdj/', | 21 | publicPath: '/dj/', |
| 22 | // 设置项目打包生成的文件的存储目录,可以是静态路径也可以是相对路径 | 22 | // 设置项目打包生成的文件的存储目录,可以是静态路径也可以是相对路径 |
| 23 | outputDir: 'dist', | 23 | outputDir: 'dist', |
| 24 | // 设置放置打包生成的静态资源 (js、css、img、fonts) 的目录 | 24 | // 设置放置打包生成的静态资源 (js、css、img、fonts) 的目录 | ... | ... |
-
Please register or sign in to post a comment