mirror of
https://codeup.aliyun.com/67762337eccfc218f6110e0e/vue/fe-manage.git
synced 2025-12-10 03:16:44 +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() {
|
||||
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) {
|
||||
|
||||
@@ -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)
|
||||
|
||||
22
src/main.js
22
src/main.js
@@ -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');
|
||||
Reference in New Issue
Block a user