f7049097 by renchao@pashanhoo.com

style:cas部署

1 parent 219c12d6
......@@ -28,6 +28,7 @@
</template>
<script>
import axios from 'axios'
import Cookies from 'js-cookie'
import { mapGetters } from 'vuex'
import NoticeBar from '@/components/NoticeBar/index'
import {
......@@ -64,7 +65,6 @@
window.removeEventListener('message')
},
methods: {
queryNoticeList () {
getHomeNoticeList().then(res => {
if (res.result) {
......@@ -74,7 +74,11 @@
},
logout () {
axios.post(this.BASE_API.ip + "/management/logout").then(() => {
localStorage.removeItem('token')
if (process.env.NODE_ENV === 'development') {
localStorage.removeItem('token')
} else {
Cookies.remove('token')
}
if (window._config.casEnable) {
window.location.href = window._config.casBaseURL + '/logout?service=' + encodeURIComponent(window.location.href);
} else {
......
/*
* @Description: 项目权限
* @Autor: renchao
* @LastEditTime: 2023-05-31 15:55:14
* @LastEditTime: 2023-06-01 16:16:04
*/
import Vue from 'vue'
import axios from 'axios'
import router from './router'
import store from './store'
import axios from 'axios'
import Cookies from 'js-cookie'
import { getMenuInfo } from '@/api/user'
import { getUrlParam } from '@/utils/operation'
import NProgress from 'nprogress' // progress bar
import 'nprogress/nprogress.css' // progress bar style
import getPageTitle from '@/utils/get-page-title'
import Cookies from 'js-cookie'
NProgress.configure({ showSpinner: false }) // NProgress Configuration
router.beforeEach(async (to, from, next) => {
......@@ -42,7 +42,11 @@ router.beforeEach(async (to, from, next) => {
'service': locationUrl
}
}).then(async (res) => {
localStorage.setItem('token', res.data.content.accessToken)
if (process.env.NODE_ENV === 'development') {
localStorage.setItem('token', res.data.content.accessToken)
} else {
Cookies.set('ACCESS_TOKEN', res.data.content.accessToken)
}
window.location.href = localStorage.getItem('location')
}).catch(e => {
......
/*
* @Description: 此文件主要创建 axios 实例,然后添加请求拦截器和响应拦截器
* @Autor: renchao
* @LastEditTime: 2023-06-01 09:20:24
* @LastEditTime: 2023-06-01 16:05:00
*/
import axios from 'axios'
import Cookies from 'js-cookie'
import { Message } from 'element-ui'
import { endLoadingSubCount } from './requestLoading'
......@@ -23,14 +24,16 @@ const service = axios.create({
// request interceptor
service.interceptors.request.use(
config => {
const token = localStorage.getItem('token')
// 添加请求头
if (token) {
config.headers['Authorization'] = "Bearer " + token
} else {
config.headers.delete('Authorization')
if (process.env.NODE_ENV === 'development') {
const token = localStorage.getItem('token')
// 添加请求头
if (token) {
config.headers['Authorization'] = 'Bearer ' + token
} else {
config.headers.delete('Authorization')
}
}
return config;
return config
},
error => {
// do something with request error
......@@ -62,7 +65,12 @@ service.interceptors.response.use(
window.__isNeedLogin = false
Message.error('token失效,请重新登录');
let locationUrl = window.location.protocol + '//' + window.location.host + window.location.pathname;
localStorage.removeItem('token')
if (process.env.NODE_ENV === 'development') {
localStorage.removeItem('token')
} else {
Cookies.remove('token')
}
if (window._config.casEnable) {
window.location.href = window._config.casBaseURL + '/logout?service=' + encodeURIComponent(locationUrl);
} else {
......