|
@@ -1,6 +1,7 @@
|
|
|
import router from './router'
|
|
import router from './router'
|
|
|
import store from './store'
|
|
import store from './store'
|
|
|
import { Message } from 'element-ui'
|
|
import { Message } from 'element-ui'
|
|
|
|
|
+import { getToken } from '@/utils/auth'
|
|
|
import NProgress from 'nprogress' // progress bar
|
|
import NProgress from 'nprogress' // progress bar
|
|
|
import 'nprogress/nprogress.css'// progress bar style
|
|
import 'nprogress/nprogress.css'// progress bar style
|
|
|
// import { getToken } from '@/utils/auth' // getToken from cookie
|
|
// import { getToken } from '@/utils/auth' // getToken from cookie
|
|
@@ -8,17 +9,22 @@ import 'nprogress/nprogress.css'// progress bar style
|
|
|
NProgress.configure({ showSpinner: false })// NProgress Configuration
|
|
NProgress.configure({ showSpinner: false })// NProgress Configuration
|
|
|
|
|
|
|
|
const whiteList = ['/login', '/config', '/', '/editor', '/posTool']// no redirect whitelist
|
|
const whiteList = ['/login', '/config', '/', '/editor', '/posTool']// no redirect whitelist
|
|
|
-const Store = require('electron-store')
|
|
|
|
|
-const localStore = new Store()
|
|
|
|
|
|
|
|
|
|
router.beforeEach((to, from, next) => {
|
|
router.beforeEach((to, from, next) => {
|
|
|
NProgress.start() // start progress bar
|
|
NProgress.start() // start progress bar
|
|
|
- if (localStore.get('token')) {
|
|
|
|
|
|
|
+ if (getToken()) {
|
|
|
if (to.path === '/login') {
|
|
if (to.path === '/login') {
|
|
|
next({ path: '/index/dashboard' })
|
|
next({ path: '/index/dashboard' })
|
|
|
NProgress.done()
|
|
NProgress.done()
|
|
|
} else {
|
|
} else {
|
|
|
- next()
|
|
|
|
|
|
|
+ if (!store.getters.addRouters.length) {
|
|
|
|
|
+ store.dispatch('GenerateRoutes', {}).then(() => { // 根据roles权限生成可访问的路由表
|
|
|
|
|
+ router.addRoutes(store.getters.addRouters) // 动态添加可访问路由表
|
|
|
|
|
+ next({ ...to, replace: true }) // hack方法 确保addRoutes已完成 ,set the replace: true so the navigation will not leave a history record
|
|
|
|
|
+ })
|
|
|
|
|
+ } else {
|
|
|
|
|
+ next()
|
|
|
|
|
+ }
|
|
|
// if (store.getters.menuList.length === 0) {
|
|
// if (store.getters.menuList.length === 0) {
|
|
|
// store.dispatch('GetInfo').then(res => {
|
|
// store.dispatch('GetInfo').then(res => {
|
|
|
// debugger
|
|
// debugger
|