上饶市警务平台后台管理前端
zhongrj
2025-01-21 c393f8b721c1e7f6ea65ff0f3ad3a47dce71cfbc
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/**
 * 全站权限配置
 *
 */
// import md5 from 'js-md5'
// import request from '@/router/axios'
// import { Message } from 'element-ui'
 
import router from './router/router'
import store from './store'
import { validatenull } from '@/util/validate'
import { getToken } from '@/util/auth'
import NProgress from 'nprogress' // progress bar
import 'nprogress/nprogress.css' // progress bar style
NProgress.configure({ showSpinner: false })
const lockPage = store.getters.website.lockPage //锁屏页
router.beforeEach((to, from, next) => {
    let hrefIdx = window.location.href.indexOf('token=') // url中是否携带token
 
    var tag = false
    const meta = to.meta || {}
    const isMenu = meta.menu === undefined ? to.query.menu : meta.menu
    store.commit('SET_IS_MENU', isMenu === undefined)
 
    if (hrefIdx > -1) {
        tag = true
        let token = window.location.href.slice(hrefIdx + 6)
        store.commit('SET_TOKEN', token)
    }
 
    if (getToken()) {
        if (store.getters.isLock && to.path !== lockPage) { //如果系统激活锁屏,全部跳转到锁屏页
            next({ path: lockPage })
        } else if (to.path === '/login') { //如果登录成功访问登录页跳转到主页
            next({ path: '/' })
        } else {
            //如果用户信息为空则获取用户信息,获取用户信息失败,跳转到登录页
            if (store.getters.token.length === 0 && tag == false) {
                // if (store.getters.token.length === 0) {
                store.dispatch('FedLogOut').then(() => {
                    next({ path: '/login' })
                })
            } else {
                const value = to.query.src || to.fullPath
                const label = to.query.name || to.name
                const meta = to.meta || router.$avueRouter.meta || {}
                const i18n = to.query.i18n
                if (to.query.target) {
                    window.open(value)
                    // } else if (meta.isTab !== false && !validatenull(value) && !validatenull(label)) {
                } else if (meta.isTab !== false && !validatenull(value) && !validatenull(label) && tag == false) {
                    store.commit('ADD_TAG', {
                        label: label,
                        value: value,
                        params: to.params,
                        query: to.query,
                        meta: (() => {
                            if (!i18n) {
                                return meta
                            }
                            return {
                                i18n: i18n
                            }
                        })(),
                        group: router.$avueRouter.group || []
                    })
                }
                next()
            }
        }
    } else {
        //判断是否需要认证,没有登录访问去登录页
        if (meta.isAuth === false) {
            next()
        } else {
            next('/login')
        }
    }
})
 
router.afterEach(() => {
    NProgress.done()
    let title = store.getters.tag.label
    let i18n = store.getters.tag.meta.i18n
    title = router.$avueRouter.generateTitle(title, i18n)
    //判断登录页的情况
    if (router.history.current.fullPath === "/login") {
        title = "登录"
    }
    //根据当前的标签也获取label的值动态设置浏览器标题
    router.$avueRouter.setTitle(title)
})