智慧园区前端大屏
shuishen
2024-12-02 b67f46b4a768b4cd72d4e463c5dffefe977ddeb7
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/*
 * @Author: shuishen 1109946754@qq.com
 * @Date: 2024-10-30 17:03:57
 * @LastEditors: shuishen 1109946754@qq.com
 * @LastEditTime: 2024-10-30 17:07:40
 * @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.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 => {
 
})