diff --git a/report-ui/src/mixins/access.js b/report-ui/src/mixins/access.js index 4eea888e..894819b4 100644 --- a/report-ui/src/mixins/access.js +++ b/report-ui/src/mixins/access.js @@ -1,5 +1,4 @@ -import { setItem, getItem } from '@/utils/storage'; - +import { getToken, getAccessUser } from '@/utils/auth' export default { data () { return { @@ -7,12 +6,16 @@ export default { }, computed: { operator: function () { - var operator = getItem('loginName') - return operator + return this.getUser.loginName + }, + operatorText: function () { + return `${this.getUser.realName}[${this.getUser.loginName}]` + }, + operatorToken: function (){ + return getToken() }, getUser: function () { - // var user = getItem('user'); - var user = JSON.parse(localStorage.getItem('user')) + var user = getAccessUser() if (user != null) { return user; } else { @@ -20,7 +23,7 @@ export default { } }, opAuthorities () { - return this.getUser == null ? [] : this.getUser.authorityWithOrgIds + return this.getUser == null ? [] : this.getUser.authorities } }, created () { diff --git a/report-ui/src/mixins/common.js b/report-ui/src/mixins/common.js index a20150bf..34411f43 100644 --- a/report-ui/src/mixins/common.js +++ b/report-ui/src/mixins/common.js @@ -1,4 +1,5 @@ import Cookies from 'js-cookie' +import { getStorageItem } from '@/utils/storage' export default { data () { return { @@ -308,7 +309,7 @@ export default { // 根据数据字典,查询指定字典dict指定值code的,返回整个dictItem{id, text, extend} getDictItemByCode (dict, code) { - var dicts = JSON.parse(localStorage.getItem('gaeaDict')) + var dicts = getStorageItem('gaeaDict') if (!dicts.hasOwnProperty(dict)) { return null } diff --git a/report-ui/src/permission.js b/report-ui/src/permission.js index 4a72028d..cf27aebf 100644 --- a/report-ui/src/permission.js +++ b/report-ui/src/permission.js @@ -2,16 +2,15 @@ import router from './router' import store from './store' import NProgress from 'nprogress' // Progress 进度条 import 'nprogress/nprogress.css'// Progress 进度条样式 -import { setItem, getItem } from '@/utils/storage'; - +import { getToken, getAccessUser } from "@/utils/auth"; export default router var whiteList = ['/login'] // 判断是否需要登录权限 以及是否登录 router.beforeEach((to, from, next) => { NProgress.start() - var token = getItem('token'); - var accessUser = getItem('accessUser'); + var token = getToken(); + var gaeaUser = getAccessUser(); // 如果有token if (token) { if (to.path == '/login') { @@ -20,32 +19,15 @@ router.beforeEach((to, from, next) => { }else{ next() } - // 如果没有token }else { - /* has no token */ - console.log(token,to.meta) - if ((token == null || token == '' || token ==undefined || accessUser == {}) && (to.meta != null && to.meta.requireAuth == true)) { // 在免登录白名单,直接进入 + // 如果没有token + if ((token == null || token == '' || token ==undefined || gaeaUser == {}) && (to.meta != null && to.meta.requireAuth == true)) { // 在免登录白名单,直接进入 next(`/login?redirect=${to.path}`) // 否则全部重定向到登录页 NProgress.done() } else { 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(() => {