/**
|
* 全站权限配置
|
*
|
*/
|
// 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
|
if (to.fullPath.indexOf("token") > 0) {
|
tag = true
|
}
|
const meta = to.meta || {}
|
const isMenu = meta.menu === undefined ? to.query.menu : meta.menu
|
store.commit('SET_IS_MENU', isMenu === undefined)
|
|
if (hrefIdx > -1) {
|
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 {
|
// console.log(to.path, 66666)
|
// if (to.path == '/security/security') {
|
// // console.log('进入首页-----')
|
// var a = to.query.securitySupervisionSystem
|
// if (a == undefined || typeof a != "string") {
|
// // console.log("无securitySupervisionSystem参数 跳回登入");
|
// next('/login')
|
// next('/login')
|
// return
|
// }
|
// // console.log("有securitySupervisionSystem参数");
|
// try {
|
// // console.log("判断securitySupervisionSystem是否能被JSOn解码");
|
// var obj = JSON.parse(a)
|
// if (typeof obj == "object" && obj && obj.tokenMY == '987654321S') {
|
// debugger
|
// var data = {
|
// tenantId: obj.data.dip,
|
// username: obj.data.rese,
|
// password: md5(obj.data.sap),
|
// grant_type: 'password',
|
// scope: 'all',
|
// type: 'account'
|
// }
|
// request({
|
// url: '/api/blade-auth/oauth/token',
|
// method: 'post',
|
// headers: {
|
// 'Authorization': 'Basic c2FiZXI6c2FiZXJfc2VjcmV0',
|
// "Tenant-Id": "000000"
|
// },
|
// params: data
|
// }).then(res => {
|
// const data = res.data
|
// if (data.error_description) {
|
// // console.log("登入失败");
|
// Message({
|
// message: data.error_description,
|
// type: 'error'
|
// })
|
// next('/login')
|
// next('/login')
|
// return
|
// } else {
|
// // console.log("登入成功");
|
// store.commit('SET_TOKEN', data.access_token)
|
// store.commit('SET_REFRESH_TOKEN', data.refresh_token)
|
// store.commit('SET_TENANT_ID', data.tenant_id)
|
// store.commit('SET_USER_INFO', data)
|
// store.commit('DEL_ALL_TAG')
|
// store.commit('CLEAR_LOCK')
|
// next(to.path)
|
// return
|
// }
|
// })
|
// return
|
// } else {
|
// // console.log("成功解码 不是对象");
|
// next('/login')
|
// return
|
// }
|
// } catch {
|
// // console.log('不是Json对象 跳回登入');
|
// next('/login')
|
// return
|
// }
|
// }
|
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)
|
})
|