update for permission

木子李·De 3 years ago
parent ed3a022c61
commit c6ca4c6556

@ -1,5 +1,4 @@
import { setItem, getItem } from '@/utils/storage'; import { getToken, getAccessUser } from '@/utils/auth'
export default { export default {
data () { data () {
return { return {
@ -7,12 +6,16 @@ export default {
}, },
computed: { computed: {
operator: function () { operator: function () {
var operator = getItem('loginName') return this.getUser.loginName
return operator },
operatorText: function () {
return `${this.getUser.realName}[${this.getUser.loginName}]`
},
operatorToken: function (){
return getToken()
}, },
getUser: function () { getUser: function () {
// var user = getItem('user'); var user = getAccessUser()
var user = JSON.parse(localStorage.getItem('user'))
if (user != null) { if (user != null) {
return user; return user;
} else { } else {
@ -20,7 +23,7 @@ export default {
} }
}, },
opAuthorities () { opAuthorities () {
return this.getUser == null ? [] : this.getUser.authorityWithOrgIds return this.getUser == null ? [] : this.getUser.authorities
} }
}, },
created () { created () {

@ -1,4 +1,5 @@
import Cookies from 'js-cookie' import Cookies from 'js-cookie'
import { getStorageItem } from '@/utils/storage'
export default { export default {
data () { data () {
return { return {
@ -308,7 +309,7 @@ export default {
// 根据数据字典查询指定字典dict指定值code的返回整个dictItem{id, text, extend} // 根据数据字典查询指定字典dict指定值code的返回整个dictItem{id, text, extend}
getDictItemByCode (dict, code) { getDictItemByCode (dict, code) {
var dicts = JSON.parse(localStorage.getItem('gaeaDict')) var dicts = getStorageItem('gaeaDict')
if (!dicts.hasOwnProperty(dict)) { if (!dicts.hasOwnProperty(dict)) {
return null return null
} }

@ -2,16 +2,15 @@ import router from './router'
import store from './store' import store from './store'
import NProgress from 'nprogress' // Progress 进度条 import NProgress from 'nprogress' // Progress 进度条
import 'nprogress/nprogress.css'// Progress 进度条样式 import 'nprogress/nprogress.css'// Progress 进度条样式
import { setItem, getItem } from '@/utils/storage'; import { getToken, getAccessUser } from "@/utils/auth";
export default router export default router
var whiteList = ['/login'] var whiteList = ['/login']
// 判断是否需要登录权限 以及是否登录 // 判断是否需要登录权限 以及是否登录
router.beforeEach((to, from, next) => { router.beforeEach((to, from, next) => {
NProgress.start() NProgress.start()
var token = getItem('token'); var token = getToken();
var accessUser = getItem('accessUser'); var gaeaUser = getAccessUser();
// 如果有token // 如果有token
if (token) { if (token) {
if (to.path == '/login') { if (to.path == '/login') {
@ -20,32 +19,15 @@ router.beforeEach((to, from, next) => {
}else{ }else{
next() next()
} }
// 如果没有token
}else { }else {
/* has no token */ // 如果没有token
console.log(token,to.meta) if ((token == null || token == '' || token ==undefined || gaeaUser == {}) && (to.meta != null && to.meta.requireAuth == true)) { // 在免登录白名单,直接进入
if ((token == null || token == '' || token ==undefined || accessUser == {}) && (to.meta != null && to.meta.requireAuth == true)) { // 在免登录白名单,直接进入
next(`/login?redirect=${to.path}`) // 否则全部重定向到登录页 next(`/login?redirect=${to.path}`) // 否则全部重定向到登录页
NProgress.done() NProgress.done()
} else { } else {
next() next()
} }
} }
// if (to.path == '/' || to.path == '/login') {
// if (token != null && token != '' && accessUser != null && accessUser != {}) {
// next('/index')
// NProgress.done()
// } else {
// next()
// }
// } else {
// if ((token == null || token == '' || accessUser == {}) && (to.meta != null && to.meta.requireAuth == true)) {
// next(`/login?redirect=${to.path}`) // 否则全部重定向到登录页
// NProgress.done()
// } else {
// next()
// }
// }
}) })
router.afterEach(() => { router.afterEach(() => {

Loading…
Cancel
Save