add menu permission

木子李·De 3 years ago
parent 09ea18d1e3
commit a73dc0f934

@ -33,49 +33,29 @@ export default {
destroyed () {
},
methods: {
hasPermission (permissionStr, orgIds) {
//判断用户权限列表是否为空
if (this.opAuthorities == null) {
return false
}
if (permissionStr && permissionStr.indexOf('|') !== -1) {
let flag = false
let arr = permissionStr.split('|')
for (let i = 0; i < arr.length; i++) {
let a = arr[i].replace(/(^\s*)|(\s*$)/g, "");
if (this.opAuthorities.hasOwnProperty(a)) {
flag = true
}
}
return flag
hasPermission (permissionStr) {
if (permissionStr == null || permissionStr.length == 0) {
return true
}
//登录用户没有某个操作权限
if (!this.opAuthorities.hasOwnProperty(permissionStr)) {
// 登录用户权限列表
if (this.opAuthorities == null) {
return false
}
//如果当前验证,不包含项目级别验证,直接返回
if (typeof (orgIds) == 'undefined' || orgIds == null) {
return true
}
//验证登录用户是否有某个项目的有操作权限
var orgIdsHasPermission = this.opAuthorities[permissionStr]
//如果projectIds是个数字只要验证登录用户是否有该项目的操作权限
if (typeof orgIds == 'number') {
if (orgIdsHasPermission.indexOf(orgIds) > -1) {
// 用户有的全部权限码
var opAuthoritiesStr = JSON.stringify(this.opAuthorities)
// permissionStr可能是authorityManage、authorityManage:insert、authorityManage:insert|authorityManage:update
var needPermissionArray = permissionStr.split('|')
for (var i = 0; i < needPermissionArray.length; i++) {
// 只要有其中的一个权限就返回true
var needPermission = needPermissionArray[i] // authorityManage、authorityManage:insert
needPermission = needPermission.replace(/\ /g, "") // 去除authorityManage : insert中:前后的空格
if(opAuthoritiesStr.indexOf(needPermission)>=0){
return true
} else {
return false
}
} else {
var result = false
for (var i in orgIdsHasPermission) {
var flag = orgIds.indexOf(orgIdsHasPermission[i]) > -1
if (flag) {
result = true
}
}
return result
}
return false
},
}
}

@ -28,31 +28,31 @@ import Layout from '../views/layout/Layout'
export const constantRouterMap = [
{ path: '/login', component: () => import('@/views/login'), hidden: true },
{
path: '/index', component: Layout, redirect: '/access/accessAuthority', name: '首页', meta: { title: '首页', icon: 'iconhome2' },
path: '/index', component: Layout, name: 'index', meta: { title: '首页', icon: 'iconhome2' },
children: [
{ path: '', name: 'accessUser', component: () => import('@/views/home/index'), meta: { title: '首页', icon: 'iconhome2', keepAlive: true, isBack: true, requireAuth: true } },
{ path: '', component: () => import('@/views/home/index'), meta: { title: '首页', icon: 'iconhome2', keepAlive: true, requireAuth: true } },
]
},
{
path: '/access', component: Layout, name: 'access', meta: { title: '用户权限', icon: 'icondfzq-' },
path: '/access', name: 'access', component: Layout, meta: { title: '用户权限', icon: 'icondfzq-', requireAuth: true, permission: 'authorityManage|roleManage|userManage' },
children: [
{ path: 'authority', name: 'authority', component: () => import('@/views/accessAuthority/index'), meta: { title: '权限管理', icon: 'iconquanxian', keepAlive: true, isBack: true } },
{ path: 'role', name: 'role', component: () => import('@/views/accessRole/index'), meta: { title: '角色管理', icon: 'iconjiaose1', keepAlive: true, isBack: true } },
{ path: 'user', name: 'user', component: () => import('@/views/accessUser/index'), meta: { title: '用户管理', icon: 'iconyonghu', keepAlive: true, isBack: true } },
{ path: 'authority', name: 'authority', component: () => import('@/views/accessAuthority/index'), meta: { title: '权限管理', icon: 'iconquanxian', keepAlive: true, requireAuth: true, permission: 'authorityManage'} },
{ path: 'role', name: 'role', component: () => import('@/views/accessRole/index'), meta: { title: '角色管理', icon: 'iconjiaose1', keepAlive: true, requireAuth: true, permission: 'roleManage'} },
{ path: 'user', name: 'user', component: () => import('@/views/accessUser/index'), meta: { title: '用户管理', icon: 'iconyonghu', keepAlive: true, requireAuth: true, permission: 'userManage'} },
]
},
{
path: '/report', component: Layout, name: '报表设计', meta: { title: '报表设计', icon: 'iconnavicon-ywcs' },
path: '/report', name: 'report', component: Layout, meta: { title: '报表设计', icon: 'iconnavicon-ywcs', requireAuth: true, permission: 'datasourceManage|resultsetManage|reportManage|bigScreenManage' },
children: [
{ path: 'datasource', name: 'datasource', component: () => import('@/views/report/datasource/index'), meta: { title: '数据源', icon: 'iconeventbridgexiaoxishijianzongxian', keepAlive: true, isBack: true } },
{ path: 'resultset', name: 'resultset', component: () => import('@/views/report/resultset/index'), meta: { title: '数据集', icon: 'iconalikafkaxiaoxiduilieKafka', keepAlive: true, isBack: true } },
{ path: 'report', name: 'reportIndex', component: () => import('@/views/report/report/index'), meta: { title: '报表管理', icon: 'iconnavicon-ywcs', keepAlive: true, isBack: true } },
{ path: 'bigscreen', name: 'bigscreen', component: () => import('@/views/report/bigscreen/index'), meta: { title: '大屏报表', icon: 'iconchufaqipeizhi-hui', keepAlive: true, isBack: true }, },
//{ path: 'excelreport', name: 'excelreport', component: () => import('@/views/report/excelreport/index'), meta: { title: '表格报表', icon: 'iconliebiao', keepAlive: true, isBack: true } },
{ path: 'datasource', name: 'datasource', component: () => import('@/views/report/datasource/index'), meta: { title: '数据源', icon: 'iconeventbridgexiaoxishijianzongxian', keepAlive: true, requireAuth: true, permission: 'datasourceManage'} },
{ path: 'resultset', name: 'resultset', component: () => import('@/views/report/resultset/index'), meta: { title: '数据集', icon: 'iconalikafkaxiaoxiduilieKafka', keepAlive: true, requireAuth: true, permission: 'resultsetManage'} },
{ path: 'report', name: 'reportIndex', component: () => import('@/views/report/report/index'), meta: { title: '报表管理', icon: 'iconnavicon-ywcs', keepAlive: true, requireAuth: true, permission: 'reportManage'} },
{ path: 'bigscreen', name: 'bigscreen', component: () => import('@/views/report/bigscreen/index'), meta: { title: '大屏报表', icon: 'iconchufaqipeizhi-hui', keepAlive: true, requireAuth: true, permission: 'bigScreenManage'}, },
//{ path: 'excelreport', name: 'excelreport', component: () => import('@/views/report/excelreport/index'), meta: { title: '表格报表', icon: 'iconliebiao', keepAlive: true, requireAuth: true, permission: 'excelManage'} },
]
},
{ path: '/bigscreen/viewer', component: () => import('@/views/report/bigscreen/viewer'), hidden: true },
{ path: '/bigscreen/designer', component: () => import('@/views/report/bigscreen/designer'), hidden: true },
{ path: '/bigscreen/viewer', component: () => import('@/views/report/bigscreen/viewer'), hidden: true, meta: { requireAuth: true }},
{ path: '/bigscreen/designer', component: () => import('@/views/report/bigscreen/designer'), hidden: true, meta: { requireAuth: true }},
{ path: '/404', component: () => import('@/views/404'), hidden: true },
{ path: '*', redirect: '/login', hidden: true },
/*

@ -1,52 +1,32 @@
<template>
<div v-if="!item.hidden&&item.children"
class="menu-wrapper">
<div v-if="!item.hidden&&item.children" class="menu-wrapper">
<template v-if="hasOneShowingChild(item.children,item) && (!onlyOneChild.children||onlyOneChild.noShowingChildren)&&!item.alwaysShow">
<app-link :to="resolvePath(onlyOneChild.path)">
<el-menu-item :index="resolvePath(onlyOneChild.path)"
:class="{'submenu-title-noDropdown':!isNest}">
<item v-if="onlyOneChild.meta"
:icon="onlyOneChild.meta.icon||item.meta.icon"
:title="onlyOneChild.meta.title " />
<el-menu-item :index="resolvePath(onlyOneChild.path)" :class="{'submenu-title-noDropdown':!isNest}">
<item v-if="onlyOneChild.meta" :icon="onlyOneChild.meta.icon||item.meta.icon" :title="onlyOneChild.meta.title " />
</el-menu-item>
</app-link>
</template>
<!-- && secondLevelChildren.length > 0 -->
<el-submenu v-else
:index="resolvePath(item.path)">
<template slot="title">
<item v-if="item.meta"
:icon="item.meta.icon"
:title="item.meta.title" />
</template>
<template v-for="child in item.children"
v-if="!child.hidden">
<!-- <template v-if="!child.hidden && hasPermission(item.meta.AuthKey)"> -->
<!-- <template v-for="child in secondLevelChildren(item.children)"> -->
<sidebar-item v-if="child.children&&child.children.length>0"
:is-nest="true"
:item="child"
:key="child.path"
:base-path="resolvePath(child.path)"
class="nest-menu" />
<!-- 一级菜单有两个以上的子菜单 -->
<template v-else>
<el-submenu v-if="hasPermission(item.meta.permission)" :index="resolvePath(item.path)">
<template slot="title">
<item :icon="item.meta.icon" :title="item.meta.title" />
</template>
<template v-for="child in item.children">
<template v-if="hasPermission(child.meta.permission) && child.hidden!=true">
<sidebar-item v-if="child.children&&child.children.length>0" :is-nest="true" :item="child" :key="child.path" :base-path="resolvePath(child.path)" class="nest-menu" />
<app-link :to="resolvePath(child.path)"
:key="child.name">
<el-menu-item :index="resolvePath(child.path)">
<item v-if="child.meta"
:icon="child.meta.icon"
:title="child.meta.title" />
</el-menu-item>
</app-link>
<!-- <app-link v-else :to="resolvePath(child.path)" :key="child.name">
<el-menu-item :index="resolvePath(child.path)">
<item v-if="child.meta" :icon="child.meta.icon" :title="child.meta.title" />
</el-menu-item>
</app-link> -->
</template>
<!-- </template> -->
</el-submenu>
<app-link :to="resolvePath(child.path)" :key="child.name">
<el-menu-item :index="resolvePath(child.path)">
<item v-if="child.meta" :icon="child.meta.icon" :title="child.meta.title" />
</el-menu-item>
</app-link>
</template>
</template>
</el-submenu>
</template>
</div>
</template>
@ -64,20 +44,20 @@ export default {
// route object
item: {
type: Object,
required: true
required: true,
},
isNest: {
type: Boolean,
default: false
default: false,
},
basePath: {
type: String,
default: ''
}
default: '',
},
},
data () {
data() {
return {
onlyOneChild: null
onlyOneChild: null,
}
},
computed: {
@ -89,8 +69,8 @@ export default {
// }
},
methods: {
hasOneShowingChild (children, parent) {
const showingChildren = children.filter(item => {
hasOneShowingChild(children, parent) {
const showingChildren = children.filter((item) => {
if (item.hidden) {
return false
} else {
@ -112,16 +92,16 @@ export default {
return false
},
resolvePath (routePath) {
resolvePath(routePath) {
if (this.isExternalLink(routePath)) {
return routePath
}
return path.resolve(this.basePath, routePath)
},
isExternalLink (routePath) {
isExternalLink(routePath) {
return isExternal(routePath)
}
}
},
},
}
</script>
<style lang="scss" scoped>

@ -1,19 +1,10 @@
<template>
<el-scrollbar wrap-class="scrollbar-wrapper">
<div class="admin-title"
@click="goBigScreen">
<img src="../../../../../static/logo-dp.png"
width="50"
class="mt10" />
<div class="admin-title" @click="goBigScreen">
<img src="../../../../../static/logo-dp.png" width="50" class="mt10" />
</div>
<el-menu :show-timeout="200"
:default-active="$route.path"
:collapse="isCollapse"
mode="vertical">
<sidebar-item v-for="route in routes"
:key="route.path"
:item="route"
:base-path="route.path" />
<el-menu :show-timeout="200" :default-active="$route.path" :collapse="isCollapse" mode="vertical">
<sidebar-item v-for="route in routes" :key="route.path" :item="route" :base-path="route.path" />
</el-menu>
</el-scrollbar>
</template>
@ -25,25 +16,22 @@ import SidebarItem from './SidebarItem'
export default {
components: { SidebarItem },
computed: {
...mapGetters([
'sidebar'
]),
routes () {
...mapGetters(['sidebar']),
routes() {
return this.$router.options.routes
},
isCollapse () {
isCollapse() {
return !this.sidebar.opened
},
},
methods: {
goBigScreen () {
goBigScreen() {
let routeUrl = this.$router.resolve({
path: "/report/bigScreen"
});
window.open(routeUrl.href, '_blank');
}
}
path: '/report/bigScreen',
})
window.open(routeUrl.href, '_blank')
},
},
}
</script>

Loading…
Cancel
Save