fix bug checktoken

This commit is contained in:
yuping
2023-07-28 03:12:53 +08:00
parent 7c35352bb6
commit a5b81ac712
3 changed files with 22 additions and 13 deletions

View File

@@ -53,7 +53,6 @@ function beforeunloadHandler() {
}
async function init() {
await validateToken();
initDict("content_type"); //内容分类
initDict("project_level"); //项目级别
initDict("project_sys"); //培训分类
@@ -64,17 +63,6 @@ async function init() {
initDict("band"); //band
}
async function validateToken() {
try{
await request(VALIDATE_TOKEN)
await getUserInfo();
await getUserPermission();
}catch (e) {
console.log('token失效 跳转到登录页')
}
}
function unloadHandler() {
time2.value = new Date().getTime() - time1.value;
if (time2.value <= 5) {

View File

@@ -413,6 +413,7 @@ export async function request(_url, params) {
localStorage.removeItem('refreshPage')
return Promise.reject(res);
}else if(res.code=== 1001){
setCookie('token',getCookieForName('refreshToken'))
request(REFRESH_TOKEN).then((res)=>{
if(res.code===0 || res.code === 200){
setCookie('token',res.data)

View File

@@ -16,6 +16,9 @@ import 'element-plus/dist/index.css'
import "@/assets/scss/common.scss"
import Antd from 'ant-design-vue';
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'
// axios.defaults.withCredentials = true;
// import zhCN from 'ant-design-vue/es/locale/zh_CN';
@@ -25,7 +28,24 @@ app.config.warnHandler = () => null;
// app.use(ElementPlus, {
// 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(router);
app.use(store);
app.mount('#app');
app.mount('#app');