add menu permission

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

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

@ -28,31 +28,31 @@ import Layout from '../views/layout/Layout'
export const constantRouterMap = [ export const constantRouterMap = [
{ path: '/login', component: () => import('@/views/login'), hidden: true }, { 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: [ 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: [ children: [
{ path: 'authority', name: 'authority', component: () => import('@/views/accessAuthority/index'), meta: { title: '权限管理', icon: 'iconquanxian', 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, isBack: true } }, { 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, isBack: true } }, { 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: [ children: [
{ path: 'datasource', name: 'datasource', component: () => import('@/views/report/datasource/index'), meta: { title: '数据源', icon: 'iconeventbridgexiaoxishijianzongxian', 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, isBack: true } }, { 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, isBack: true } }, { 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, isBack: true }, }, { 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, isBack: true } }, //{ 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/viewer', component: () => import('@/views/report/bigscreen/viewer'), hidden: true, meta: { requireAuth: true }},
{ path: '/bigscreen/designer', component: () => import('@/views/report/bigscreen/designer'), hidden: true }, { path: '/bigscreen/designer', component: () => import('@/views/report/bigscreen/designer'), hidden: true, meta: { requireAuth: true }},
{ path: '/404', component: () => import('@/views/404'), hidden: true }, { path: '/404', component: () => import('@/views/404'), hidden: true },
{ path: '*', redirect: '/login', hidden: true }, { path: '*', redirect: '/login', hidden: true },
/* /*

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

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

Loading…
Cancel
Save