cas sso单点登录对接ok,但后端需要根路径才能使用

This commit is contained in:
clay
2022-09-01 23:30:04 +08:00
parent 5bb43271fe
commit 812a7b4595
11 changed files with 70 additions and 16 deletions

View File

@@ -3,7 +3,7 @@ ENV = 'development'
# EBTS/开发环境
#VUE_APP_BASE_API = '/dev-api'
VUE_APP_BASE_API = 'http://localhost:8096/dev-api'
VUE_APP_BASE_API = 'http://192.168.190.67'
#VUE_APP_BASE_API = 'http://sistapi.hchyun.cn/dev-api'
# 路由懒加载

View File

@@ -3,4 +3,4 @@ ENV = 'production'
# EBTS/生产环境
#VUE_APP_BASE_API = '/prod-api'
VUE_APP_BASE_API = 'http://192.168.190.67:8096/dev-api'
VUE_APP_BASE_API = 'http://192.168.190.67/dev-api'

View File

@@ -5,4 +5,4 @@ ENV = 'staging'
# EBTS/测试环境
#VUE_APP_BASE_API = '/dev-api'
VUE_APP_BASE_API = 'http://sistapi.hchyun.cn:88/dev-api'
VUE_APP_BASE_API = 'http://sistapi.hchyun.cn/dev-api'

View File

@@ -2,7 +2,14 @@
<div class="navbar">
<hamburger id="hamburger-container" :is-active="sidebar.opened" class="hamburger-container" @toggleClick="toggleSideBar" />
<breadcrumb id="breadcrumb-container" class="breadcrumb-container" />
<!-- <breadcrumb id="breadcrumb-container" class="breadcrumb-container" />-->
<breadcrumb
id="breadcrumb-container"
class="breadcrumb-container"
v-if="!topNav"
/>
<!-- <top-nav id="topmenu-container" class="topmenu-container" v-if="topNav" />-->
<div class="right-menu">
<template v-if="device!=='mobile'">
@@ -69,7 +76,12 @@ export default {
value: val
})
}
}
},
topNav: {
get() {
return this.$store.state.settings.topNav;
},
},
},
methods: {
toggleSideBar() {
@@ -81,9 +93,14 @@ export default {
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
this.$store.dispatch('LogOut').then(() => {
location.href = '/index';
})
// this.$store.dispatch('LogOut').then(() => {
// location.href = '/index';
// }
this.$store.dispatch("LogOut").then(() => {
if (!settings.casEnable) {
location.href = this.$router.options.base + "/index";
}
});
})
}
}

View File

@@ -7,7 +7,9 @@ import { getToken } from '@/utils/auth'
NProgress.configure({ showSpinner: false })
const whiteList = ['/login', '/auth-redirect', '/bind', '/register']
const defaultSettings = require('@/settings.js')
router.beforeEach((to, from, next) => {
NProgress.start()
@@ -48,12 +50,21 @@ router.beforeEach((to, from, next) => {
}
}
} else {
debugger
// 没有token
if (whiteList.indexOf(to.path) !== -1) {
// 在免登录白名单,直接进入
next()
} else {
// next(`/login?redirect=${to.fullPath}`) // 否则全部重定向到登录页
// NProgress.done()
if (!defaultSettings.casEnable) {
next(`/login?redirect=${to.fullPath}`) // 否则全部重定向到登录页
}
//开启cas
if (defaultSettings.casEnable) {
window.location.href = defaultSettings.casloginUrl // 否则全部重定向到登录页
}
NProgress.done()
}
}

View File

@@ -200,6 +200,7 @@ export const constantRoutes = [
export default new Router({
mode: 'history', // 去掉url中的#
base:"/admin",
scrollBehavior: () => ({ y: 0 }),
routes: constantRoutes
})

View File

@@ -1,5 +1,21 @@
module.exports = {
title: 'EBTS',
/**
* 开启cas
*/
casEnable: true,
/**
* 单点登录url
*/
casloginUrl: 'https://cas.swjtu.edu.cn/authserver/login?service=http://192.168.190.67/dev-api/dev',
/**
* 单点登出url
*/
// caslogoutUrl: 'http://localhost:8888/cas/logout?service=http://localhost:8080',
caslogoutUrl: 'https://cas.swjtu.edu.cn/authserver/logout?service=http://192.168.190.67',
/**
* 是否系统布局配置

View File

@@ -1,6 +1,6 @@
import { login, logout, getInfo } from '@/api/login'
import { getToken, setToken, removeToken } from '@/utils/auth'
const defaultSettings = require('@/settings')
const user = {
state: {
token: getToken(),
@@ -82,6 +82,7 @@ const user = {
commit('SET_PERMISSIONS', [])
removeToken()
resolve()
window.location.href = defaultSettings.caslogoutUrl
}).catch(error => {
reject(error)
})

View File

@@ -5,6 +5,7 @@ import { getToken } from '@/utils/auth'
import errorCode from '@/utils/errorCode'
axios.defaults.headers['Content-Type'] = 'application/json;charset=utf-8'
const defaultSettings = require('@/settings')
// 创建axios实例
const service = axios.create({
// axios中请求配置有baseURL选项表示请求URL公共部分
@@ -39,8 +40,13 @@ service.interceptors.response.use(res => {
}
).then(() => {
store.dispatch('LogOut').then(() => {
if (!defaultSettings.casEnable) {
location.href = '/index';
}
})
// store.dispatch('LogOut').then(() => {
// location.href = '/index';
// })
})
} else if (code === 500) {
Message({

View File

@@ -248,12 +248,13 @@ export default {
getArticleType().then(res => {
let dictCodes = res.data
let articleList = this.articleTypeOptions
console.log("dictCodes",dictCodes,"articleList",articleList)
for (let i = 0; i < articleList.length; i++) {
for (let j = 0; j < dictCodes.length; j++) {
if (articleList[i].dictCode === dictCodes[j]) {
if (articleList[i].attribute2 === 1) {
if (articleList[i].dictCode == dictCodes[j]) {
if (articleList[i].attribute2 == 1) {
this.sistArticleTypeOption.push(articleList[i])
} else if (articleList[i].attribute2 === 2) {
} else if (articleList[i].attribute2 == 2) {
this.labArticleTypeOption.push(articleList[i])
}
}

View File

@@ -16,8 +16,9 @@ const port = process.env.port || process.env.npm_config_port || 80 // 端口
module.exports = {
// 部署生产环境和开发环境下的URL。
// 默认情况下Vue CLI 会假设你的应用是被部署在一个域名的根路径上
// 例如 https://www.hchyun.vip/。如果应用被部署在一个子路径上,你就需要用这个选项指定这个子路径。例如,如果你的应用被部署在 https://www.hchyun.vip/admin/,则设置 baseUrl 为 /admin/。
publicPath: process.env.NODE_ENV === "production" ? "/" : "/",
// 例如 https://www.hchyun.com/。如果应用被部署在一个子路径上,你就需要用这个选项指定这个子路径。例如,如果你的应用被部署在 https://www.hchyun.com/admin/,则设置 baseUrl 为 /admin/。
// publicPath: "/admin/",
publicPath: "/",
// 在npm run build 或 yarn build 时 生成文件的目录名称要和baseUrl的生产环境路径一致默认dist
outputDir: 'dist',
// 用于放置生成的静态资源 (js、css、img、fonts) 的;(项目打包之后,静态资源会放在这个文件夹下)