import router from './router'
import store from './store'
import { Message } from 'element-ui'

// let accessToken = localStorage.getItem("accessToken")
router.beforeEach((to, from, next) => {
    let accessToken = localStorage.getItem("accessToken")
    // let ToAcess =  to.matched[1].meta.roles[0];
    // let FromAcess =  from.matched[1].meta.roles[0];
    // if (ToAcess !== FromAcess){
    //     debugger
    //     return
    // }
    if (to.matched.some(record => record.meta.requireAuth)) { // 判断该路由是否需要登录权限
            if (accessToken) { // 判断缓存里面是否有 accessToken  //在登录的时候设置它的值
                next();
            } else {
                Message.error('登陆权限验证失败,请重新登录!')
                next({
                    path: '/Login'
                })
            }
        } else {
            next();
        }
});