11-wms/src/permission.js
2022-10-19 17:01:55 +08:00

66 lines
2.3 KiB
JavaScript

// /*
// * @Date: 2020-12-14 09:07:03
// * @LastEditors: gtz
// * @LastEditTime: 2021-02-25 09:42:36
// * @FilePath: \basic-admin\src\permission.js
// * @Description: 路由权限检查
// */
// import router from './router'
// import { Message } from 'element-ui'
// import NProgress from 'nprogress' // progress bar
// import 'nprogress/nprogress.css' // progress bar style
// import { getToken } from '@/utils/auth' // get token from cookie
// import getPageTitle from '@/utils/get-page-title'
// NProgress.configure({ showSpinner: true }) // NProgress Configuration
// import store from '@/store'
// const whiteList = ['/login', '/auth-redirect'] // no redirect whitelist
// router.beforeEach(async(to, from, next) => {
// // start progress bar
// NProgress.start()
// // set page title
// document.title = getPageTitle(to.meta.title)
// // determine whether the user has logged in
// console.log('to.path=' + to.path)
// if (to.path === '/login') {
// // if is logged in, redirect to the home page
// // console.log('/login', store.getters.menus)
// next({ path: '/' })
// NProgress.done() // hack: https://github.com/PanJiaChen/vue-element-admin/pull/2939
// } else {
// const hasRoles = store.getters.menus && store.getters.menus.length > 0
// console.log('store.getters.menus', store.getters.menus)
// console.log('store.getters', store.getters)
// console.log('hasRoles=', hasRoles)
// if (hasRoles) {
// console.log('hasRoles=', store.getters.menus)
// next()
// NProgress.done()
// } else {
// try {
// // // generate accessible routes map based on roles
// const { menus } = await store.dispatch('user/getInfo')
// console.log(menus)
// const accessRoutes = await store.dispatch('permission/generateRoutes', menus)
// console.log('accessRoutes', accessRoutes)
// router.addRoutes(accessRoutes)
// next({ ...to, replace: true })
// } catch (error) {
// // remove token and go to login page to re-login
// next(`/login?redirect=${to.path}`)
// await store.dispatch('user/resetToken')
// Message.error(error || 'Has Error')
// NProgress.done()
// }
// }
// }
// })
// router.afterEach(() => {
// // finish progress bar
// NProgress.done()
// })