mirror of
https://codeup.aliyun.com/67762337eccfc218f6110e0e/vue/fe-manage.git
synced 2025-12-10 19:36:46 +08:00
fix bug checktoken
This commit is contained in:
12
src/App.vue
12
src/App.vue
@@ -53,7 +53,6 @@ function beforeunloadHandler() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function init() {
|
async function init() {
|
||||||
await validateToken();
|
|
||||||
initDict("content_type"); //内容分类
|
initDict("content_type"); //内容分类
|
||||||
initDict("project_level"); //项目级别
|
initDict("project_level"); //项目级别
|
||||||
initDict("project_sys"); //培训分类
|
initDict("project_sys"); //培训分类
|
||||||
@@ -64,17 +63,6 @@ async function init() {
|
|||||||
initDict("band"); //band
|
initDict("band"); //band
|
||||||
}
|
}
|
||||||
|
|
||||||
async function validateToken() {
|
|
||||||
try{
|
|
||||||
await request(VALIDATE_TOKEN)
|
|
||||||
await getUserInfo();
|
|
||||||
await getUserPermission();
|
|
||||||
}catch (e) {
|
|
||||||
console.log('token失效 跳转到登录页')
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
function unloadHandler() {
|
function unloadHandler() {
|
||||||
time2.value = new Date().getTime() - time1.value;
|
time2.value = new Date().getTime() - time1.value;
|
||||||
if (time2.value <= 5) {
|
if (time2.value <= 5) {
|
||||||
|
|||||||
@@ -413,6 +413,7 @@ export async function request(_url, params) {
|
|||||||
localStorage.removeItem('refreshPage')
|
localStorage.removeItem('refreshPage')
|
||||||
return Promise.reject(res);
|
return Promise.reject(res);
|
||||||
}else if(res.code=== 1001){
|
}else if(res.code=== 1001){
|
||||||
|
setCookie('token',getCookieForName('refreshToken'))
|
||||||
request(REFRESH_TOKEN).then((res)=>{
|
request(REFRESH_TOKEN).then((res)=>{
|
||||||
if(res.code===0 || res.code === 200){
|
if(res.code===0 || res.code === 200){
|
||||||
setCookie('token',res.data)
|
setCookie('token',res.data)
|
||||||
|
|||||||
20
src/main.js
20
src/main.js
@@ -16,6 +16,9 @@ import 'element-plus/dist/index.css'
|
|||||||
import "@/assets/scss/common.scss"
|
import "@/assets/scss/common.scss"
|
||||||
import Antd from 'ant-design-vue';
|
import Antd from 'ant-design-vue';
|
||||||
import 'ant-design-vue/dist/antd.css';
|
import 'ant-design-vue/dist/antd.css';
|
||||||
|
import {getCookieForName} from "@/api/method";
|
||||||
|
import {request} from "@/api/request";
|
||||||
|
import {VALIDATE_TOKEN} from "@/api/apis";
|
||||||
// import axios from 'axios'
|
// import axios from 'axios'
|
||||||
// axios.defaults.withCredentials = true;
|
// axios.defaults.withCredentials = true;
|
||||||
// import zhCN from 'ant-design-vue/es/locale/zh_CN';
|
// import zhCN from 'ant-design-vue/es/locale/zh_CN';
|
||||||
@@ -25,6 +28,23 @@ app.config.warnHandler = () => null;
|
|||||||
// app.use(ElementPlus, {
|
// app.use(ElementPlus, {
|
||||||
// locale: zhCn,
|
// locale: zhCn,
|
||||||
// })
|
// })
|
||||||
|
|
||||||
|
router.beforeEach(async (to, from, next) => {
|
||||||
|
if (!getCookieForName("token")) {
|
||||||
|
window.location.href = process.env.VUE_APP_LOGIN_URL + encodeURIComponent(window.location.protocol + process.env.VUE_APP_BOE_API_URL + process.env.VUE_APP_BASE + router.currentRoute.value.fullPath)
|
||||||
|
}
|
||||||
|
//第一次进入 没有用户信息
|
||||||
|
if(!store.state.userInfo.userId){
|
||||||
|
try{
|
||||||
|
await request(VALIDATE_TOKEN)
|
||||||
|
await getUserInfo();
|
||||||
|
await getUserPermission();
|
||||||
|
next();
|
||||||
|
}catch (e){
|
||||||
|
console.log('token失效 跳转到登录页')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
app.use(Antd);
|
app.use(Antd);
|
||||||
app.use(router);
|
app.use(router);
|
||||||
app.use(store);
|
app.use(store);
|
||||||
|
|||||||
Reference in New Issue
Block a user