style:cas部署
Showing
3 changed files
with
31 additions
and
15 deletions
... | @@ -28,6 +28,7 @@ | ... | @@ -28,6 +28,7 @@ |
28 | </template> | 28 | </template> |
29 | <script> | 29 | <script> |
30 | import axios from 'axios' | 30 | import axios from 'axios' |
31 | import Cookies from 'js-cookie' | ||
31 | import { mapGetters } from 'vuex' | 32 | import { mapGetters } from 'vuex' |
32 | import NoticeBar from '@/components/NoticeBar/index' | 33 | import NoticeBar from '@/components/NoticeBar/index' |
33 | import { | 34 | import { |
... | @@ -64,7 +65,6 @@ | ... | @@ -64,7 +65,6 @@ |
64 | window.removeEventListener('message') | 65 | window.removeEventListener('message') |
65 | }, | 66 | }, |
66 | methods: { | 67 | methods: { |
67 | |||
68 | queryNoticeList () { | 68 | queryNoticeList () { |
69 | getHomeNoticeList().then(res => { | 69 | getHomeNoticeList().then(res => { |
70 | if (res.result) { | 70 | if (res.result) { |
... | @@ -74,7 +74,11 @@ | ... | @@ -74,7 +74,11 @@ |
74 | }, | 74 | }, |
75 | logout () { | 75 | logout () { |
76 | axios.post(this.BASE_API.ip + "/management/logout").then(() => { | 76 | axios.post(this.BASE_API.ip + "/management/logout").then(() => { |
77 | localStorage.removeItem('token') | 77 | if (process.env.NODE_ENV === 'development') { |
78 | localStorage.removeItem('token') | ||
79 | } else { | ||
80 | Cookies.remove('token') | ||
81 | } | ||
78 | if (window._config.casEnable) { | 82 | if (window._config.casEnable) { |
79 | window.location.href = window._config.casBaseURL + '/logout?service=' + encodeURIComponent(window.location.href); | 83 | window.location.href = window._config.casBaseURL + '/logout?service=' + encodeURIComponent(window.location.href); |
80 | } else { | 84 | } else { | ... | ... |
1 | /* | 1 | /* |
2 | * @Description: 项目权限 | 2 | * @Description: 项目权限 |
3 | * @Autor: renchao | 3 | * @Autor: renchao |
4 | * @LastEditTime: 2023-05-31 15:55:14 | 4 | * @LastEditTime: 2023-06-01 16:16:04 |
5 | */ | 5 | */ |
6 | import Vue from 'vue' | 6 | import Vue from 'vue' |
7 | import axios from 'axios' | ||
7 | import router from './router' | 8 | import router from './router' |
8 | import store from './store' | 9 | import store from './store' |
9 | import axios from 'axios' | 10 | import Cookies from 'js-cookie' |
10 | import { getMenuInfo } from '@/api/user' | 11 | import { getMenuInfo } from '@/api/user' |
11 | import { getUrlParam } from '@/utils/operation' | 12 | import { getUrlParam } from '@/utils/operation' |
12 | import NProgress from 'nprogress' // progress bar | 13 | import NProgress from 'nprogress' // progress bar |
13 | import 'nprogress/nprogress.css' // progress bar style | 14 | import 'nprogress/nprogress.css' // progress bar style |
14 | import getPageTitle from '@/utils/get-page-title' | 15 | import getPageTitle from '@/utils/get-page-title' |
15 | import Cookies from 'js-cookie' | ||
16 | NProgress.configure({ showSpinner: false }) // NProgress Configuration | 16 | NProgress.configure({ showSpinner: false }) // NProgress Configuration |
17 | 17 | ||
18 | router.beforeEach(async (to, from, next) => { | 18 | router.beforeEach(async (to, from, next) => { |
... | @@ -42,7 +42,11 @@ router.beforeEach(async (to, from, next) => { | ... | @@ -42,7 +42,11 @@ router.beforeEach(async (to, from, next) => { |
42 | 'service': locationUrl | 42 | 'service': locationUrl |
43 | } | 43 | } |
44 | }).then(async (res) => { | 44 | }).then(async (res) => { |
45 | localStorage.setItem('token', res.data.content.accessToken) | 45 | if (process.env.NODE_ENV === 'development') { |
46 | localStorage.setItem('token', res.data.content.accessToken) | ||
47 | } else { | ||
48 | Cookies.set('ACCESS_TOKEN', res.data.content.accessToken) | ||
49 | } | ||
46 | window.location.href = localStorage.getItem('location') | 50 | window.location.href = localStorage.getItem('location') |
47 | 51 | ||
48 | }).catch(e => { | 52 | }).catch(e => { | ... | ... |
1 | /* | 1 | /* |
2 | * @Description: 此文件主要创建 axios 实例,然后添加请求拦截器和响应拦截器 | 2 | * @Description: 此文件主要创建 axios 实例,然后添加请求拦截器和响应拦截器 |
3 | * @Autor: renchao | 3 | * @Autor: renchao |
4 | * @LastEditTime: 2023-06-01 09:20:24 | 4 | * @LastEditTime: 2023-06-01 16:05:00 |
5 | */ | 5 | */ |
6 | import axios from 'axios' | 6 | import axios from 'axios' |
7 | import Cookies from 'js-cookie' | ||
7 | import { Message } from 'element-ui' | 8 | import { Message } from 'element-ui' |
8 | import { endLoadingSubCount } from './requestLoading' | 9 | import { endLoadingSubCount } from './requestLoading' |
9 | 10 | ||
... | @@ -23,14 +24,16 @@ const service = axios.create({ | ... | @@ -23,14 +24,16 @@ const service = axios.create({ |
23 | // request interceptor | 24 | // request interceptor |
24 | service.interceptors.request.use( | 25 | service.interceptors.request.use( |
25 | config => { | 26 | config => { |
26 | const token = localStorage.getItem('token') | 27 | if (process.env.NODE_ENV === 'development') { |
27 | // 添加请求头 | 28 | const token = localStorage.getItem('token') |
28 | if (token) { | 29 | // 添加请求头 |
29 | config.headers['Authorization'] = "Bearer " + token | 30 | if (token) { |
30 | } else { | 31 | config.headers['Authorization'] = 'Bearer ' + token |
31 | config.headers.delete('Authorization') | 32 | } else { |
33 | config.headers.delete('Authorization') | ||
34 | } | ||
32 | } | 35 | } |
33 | return config; | 36 | return config |
34 | }, | 37 | }, |
35 | error => { | 38 | error => { |
36 | // do something with request error | 39 | // do something with request error |
... | @@ -62,7 +65,12 @@ service.interceptors.response.use( | ... | @@ -62,7 +65,12 @@ service.interceptors.response.use( |
62 | window.__isNeedLogin = false | 65 | window.__isNeedLogin = false |
63 | Message.error('token失效,请重新登录'); | 66 | Message.error('token失效,请重新登录'); |
64 | let locationUrl = window.location.protocol + '//' + window.location.host + window.location.pathname; | 67 | let locationUrl = window.location.protocol + '//' + window.location.host + window.location.pathname; |
65 | localStorage.removeItem('token') | 68 | if (process.env.NODE_ENV === 'development') { |
69 | localStorage.removeItem('token') | ||
70 | } else { | ||
71 | Cookies.remove('token') | ||
72 | } | ||
73 | |||
66 | if (window._config.casEnable) { | 74 | if (window._config.casEnable) { |
67 | window.location.href = window._config.casBaseURL + '/logout?service=' + encodeURIComponent(locationUrl); | 75 | window.location.href = window._config.casBaseURL + '/logout?service=' + encodeURIComponent(locationUrl); |
68 | } else { | 76 | } else { | ... | ... |
-
Please register or sign in to post a comment