/* * @Author: shuishen 1109946754@qq.com * @Date: 2024-10-30 17:03:57 * @LastEditors: shuishen 1109946754@qq.com * @LastEditTime: 2024-12-16 19:35:12 * @FilePath: \bigScreen\src\permission.js * @Description: * * Copyright (c) 2024 by shuishen, All Rights Reserved. */ import router from './router/' import store from './store' import { useLogin } from '@/store/login' import NProgress from 'nprogress' // progress bar import 'nprogress/nprogress.css' // progress bar style NProgress.configure({ showSpinner: false }) router.beforeEach((to, from, next) => { const store = useLogin() const token = store.token const meta = to.meta || {} if (token) { if (!to.matched.length) { // 如果路由不存在 next({ path: '/' }) } else { if (to.path === '/login') { //如果登录成功访问登录页跳转到主页 next({ path: '/' }) } else { if (token.length === 0) { next({ path: '/login' }) } else { next() } } } } else { //判断是否需要认证,没有登录访问去登录页 if (meta.isAuth === false) { next() } else { next('/login') } } }) router.afterEach(to => { })