| | |
| | | import usePermissionStore from '@/store/modules/permission'; |
| | | |
| | | NProgress.configure({ showSpinner: false }); |
| | | const whiteList = ['/login', '/register', '/social-callback','/index']; |
| | | const whiteList = ['/login', '/register', '/social-callback']; |
| | | |
| | | router.beforeEach(async (to, from, next) => { |
| | | NProgress.start(); |
| | | if (getToken()) { |
| | | console.log('有token',to.path); |
| | | console.log('判断当前用户是否已拉取完user_info信息'); |
| | | to.meta.title && useSettingsStore().setTitle(to.meta.title as string); |
| | | /* has token*/ |
| | | if (to.path === '/login') { |
| | | next({ path: '/' }); |
| | | NProgress.done(); |
| | | } else { |
| | | console.log(useUserStore().roles); |
| | | if (useUserStore().roles.length === 0) { |
| | | isRelogin.show = true; |
| | | // 判断当前用户是否已拉取完user_info信息 |
| | | |
| | | const [err] = await tos(useUserStore().getInfo()); |
| | | if (err) { |
| | | await useUserStore().logout(); |
| | |
| | | } |
| | | } else { |
| | | // 没有token |
| | | console.log("没有token"); |
| | | if (whiteList.indexOf(to.path) !== -1) { |
| | | // 在免登录白名单,直接进入 |
| | | next(); |
| | | } else { |
| | | // next(`/login?redirect=${to.fullPath}`); // 否则全部重定向到登录页 |
| | | next(`/index`); // 否则全部重定向到登录页 |
| | | next(`/login?redirect=${to.fullPath}`); // 否则全部重定向到登录页 |
| | | NProgress.done(); |
| | | } |
| | | } |