Browse Source

判断当前菜单栏是否显示所有菜单

master
aBin 3 years ago
parent
commit
97a3c11cdb
  1. 12
      src/api/jurisdiction.js
  2. 1
      src/router/menus/approval.js
  3. 1
      src/router/menus/building.js
  4. 1
      src/router/menus/department.js
  5. 2
      src/router/menus/index.js
  6. 1
      src/router/menus/information.js
  7. 1
      src/router/menus/news.js
  8. 1
      src/router/menus/notice.js
  9. 2
      src/router/menus/others.js
  10. 1
      src/router/menus/production.js
  11. 1
      src/router/menus/profile.js
  12. 1
      src/router/menus/system.js
  13. 2
      src/router/modules/privilegeManagement.js
  14. 18
      src/views/layout/components/Sidebar/SidebarItem.vue
  15. 8
      src/views/layout/components/Sidebar/index.vue

12
src/api/jurisdiction.js

@ -1,5 +1,6 @@
import request from '@/utils/request' import request from '@/utils/request'
const admin = '/back/admin' const admin = '/back/admin'
const home = '/back/home'
const role = '/back/role' const role = '/back/role'
const permission = '/back/permission' const permission = '/back/permission'
@ -157,3 +158,14 @@ export function GET_ALL_HAVE(params) {
data: params data: params
}).then(res => res.data) }).then(res => res.data)
} }
/**
* 获取当前角色展示的菜单
*/
export function GET_ALL_MENUS(params) {
return request({
url: `${home}/menus`,
method: 'post',
data: params
}).then(res => res.data)
}

1
src/router/menus/approval.js

@ -3,6 +3,7 @@ import Layout from '@/views/layout/Layout'
const approval = { const approval = {
path: '/approval', path: '/approval',
component: Layout, component: Layout,
code: '0700',
meta: {title: '审批事项', icon: 'dingdan', noCache: true, affix: false}, meta: {title: '审批事项', icon: 'dingdan', noCache: true, affix: false},
children: [ children: [
{ {

1
src/router/menus/building.js

@ -3,6 +3,7 @@ import Layout from '@/views/layout/Layout'
const building = { const building = {
path: '/building', path: '/building',
component: Layout, component: Layout,
code: '0300',
meta: {title: '党的建设', icon: 'dingdan', noCache: true, affix: false}, meta: {title: '党的建设', icon: 'dingdan', noCache: true, affix: false},
children: [ children: [
{ {

1
src/router/menus/department.js

@ -3,6 +3,7 @@ import Layout from '@/views/layout/Layout'
const department = { const department = {
path: '/department', path: '/department',
component: Layout, component: Layout,
code: '0900',
meta: {title: '部门首页', icon: 'dingdan', noCache: true, affix: false}, meta: {title: '部门首页', icon: 'dingdan', noCache: true, affix: false},
children: [ children: [
{ {

2
src/router/menus/index.js

@ -3,12 +3,14 @@ import Layout from '@/views/layout/Layout'
const commodityManagement = { const commodityManagement = {
path: '/index', path: '/index',
component: Layout, component: Layout,
code: '0000',
meta: {title: '首页', icon: 'yemian-copy', noCache: true, affix: false}, meta: {title: '首页', icon: 'yemian-copy', noCache: true, affix: false},
children: [ children: [
{ {
path: '/index/index', path: '/index/index',
component: () => import('@/views/index/index'), component: () => import('@/views/index/index'),
name: '首页', name: '首页',
code: '0000',
meta: {title: '首页', noCache: false, affix: false} meta: {title: '首页', noCache: false, affix: false}
}, },
] ]

1
src/router/menus/information.js

@ -3,6 +3,7 @@ import Layout from '@/views/layout/Layout'
const commodityManagement = { const commodityManagement = {
path: '/information', path: '/information',
component: Layout, component: Layout,
code: '0600',
meta: {title: '信息公开', icon: 'dingdan', noCache: true, affix: false}, meta: {title: '信息公开', icon: 'dingdan', noCache: true, affix: false},
children: [ children: [
{ {

1
src/router/menus/news.js

@ -3,6 +3,7 @@ import Layout from '@/views/layout/Layout'
const commodityManagement = { const commodityManagement = {
path: '/news', path: '/news',
component: Layout, component: Layout,
code: '0200',
meta: {title: '新闻中心', icon: 'dingdan', noCache: true, affix: false}, meta: {title: '新闻中心', icon: 'dingdan', noCache: true, affix: false},
children: [ children: [
{ {

1
src/router/menus/notice.js

@ -3,6 +3,7 @@ import Layout from '@/views/layout/Layout'
const commodityManagement = { const commodityManagement = {
path: '/notice', path: '/notice',
component: Layout, component: Layout,
code: '0500',
meta: {title: '通知公告', icon: 'dingdan', noCache: true, affix: false}, meta: {title: '通知公告', icon: 'dingdan', noCache: true, affix: false},
children: [ children: [
{ {

2
src/router/menus/others.js

@ -3,8 +3,8 @@ import Layout from '@/views/layout/Layout'
const others = { const others = {
path: '/others', path: '/others',
component: Layout, component: Layout,
meta: {title: '其他', icon: 'dingdan', noCache: true, affix: false},
code: '9900', code: '9900',
meta: {title: '其他', icon: 'dingdan', noCache: true, affix: false},
children: [ children: [
{ {
path: '/configuration', path: '/configuration',

1
src/router/menus/production.js

@ -3,6 +3,7 @@ import Layout from '@/views/layout/Layout'
const commodityManagement = { const commodityManagement = {
path: '/production', path: '/production',
component: Layout, component: Layout,
code: '0400',
meta: {title: '安全生产', icon: 'dingdan', noCache: true, affix: false}, meta: {title: '安全生产', icon: 'dingdan', noCache: true, affix: false},
children: [ children: [
{ {

1
src/router/menus/profile.js

@ -3,6 +3,7 @@ import Layout from '@/views/layout/Layout'
const commodityManagement = { const commodityManagement = {
path: '/profile', path: '/profile',
component: Layout, component: Layout,
code: '0100',
meta: {title: '公司概况', icon: 'dingdan', noCache: true, affix: false}, meta: {title: '公司概况', icon: 'dingdan', noCache: true, affix: false},
children: [ children: [
{ {

1
src/router/menus/system.js

@ -3,6 +3,7 @@ import Layout from '@/views/layout/Layout'
const commodityManagement = { const commodityManagement = {
path: '/system', path: '/system',
component: Layout, component: Layout,
code: '0800',
meta: {title: '制度资料', icon: 'dingdan', noCache: true, affix: false}, meta: {title: '制度资料', icon: 'dingdan', noCache: true, affix: false},
children: [ children: [
{ {

2
src/router/modules/privilegeManagement.js

@ -3,8 +3,8 @@ import Layout from '@/views/layout/Layout'
const commodityManagement = { const commodityManagement = {
path: '/privilegeManagement', path: '/privilegeManagement',
component: Layout, component: Layout,
meta: {title: '权限管理', icon: 'shouquanguanli', noCache: true, affix: false},
code: '6600', code: '6600',
meta: {title: '权限管理', icon: 'shouquanguanli', noCache: true, affix: false},
children: [ children: [
{ {
path: '/privilegeManagement/account', path: '/privilegeManagement/account',

18
src/views/layout/components/Sidebar/SidebarItem.vue

@ -1,6 +1,6 @@
<template> <template>
<div v-if="!item.hidden" class="menu-wrapper"> <div v-if="!item.hidden" 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 && getShow(item.code)">
<!-- v-if="item.code && item.code === '0001'" --> <!-- v-if="item.code && item.code === '0001'" -->
<div @click="storageCode(item.code ? item.code : '')"> <div @click="storageCode(item.code ? item.code : '')">
<app-link v-if="onlyOneChild.meta" :to="resolvePath(onlyOneChild.path)"> <app-link v-if="onlyOneChild.meta" :to="resolvePath(onlyOneChild.path)">
@ -11,7 +11,7 @@
</div> </div>
</template> </template>
<el-submenu v-else ref="subMenu" :index="resolvePath(item.path)" popper-append-to-body> <el-submenu v-else-if="getShow(item.code)" ref="subMenu" :index="resolvePath(item.path)" popper-append-to-body>
<template slot="title"> <template slot="title">
<div @click="storageCode(item.code ? item.code : '')"> <div @click="storageCode(item.code ? item.code : '')">
<item v-if="item.meta" :icon="item.meta && item.meta.icon" :title="item.meta.title" /> <item v-if="item.meta" :icon="item.meta && item.meta.icon" :title="item.meta.title" />
@ -24,6 +24,7 @@
:item="child" :item="child"
:base-path="resolvePath(child.path)" :base-path="resolvePath(child.path)"
class="nest-menu" class="nest-menu"
:permission-list="permissionList"
/> />
</el-submenu> </el-submenu>
@ -55,6 +56,10 @@ export default {
basePath: { basePath: {
type: String, type: String,
default: '' default: ''
},
permissionList : {
type: Array,
default: () => []
} }
}, },
data() { data() {
@ -96,6 +101,15 @@ export default {
}, },
storageCode(code){ storageCode(code){
localStorage.setItem('code', code) localStorage.setItem('code', code)
},
//
getShow(code) {
const arr = [...this.permissionList]
for(let i=0;i<arr.length;i++) {
if(arr[i] === code) {
return true
}
}
} }
// generateTitle // generateTitle
} }

8
src/views/layout/components/Sidebar/index.vue

@ -15,6 +15,7 @@
:key="route.path" :key="route.path"
:item="route" :item="route"
:base-path="route.path" :base-path="route.path"
:permission-list="permissionList"
/> />
</el-menu> </el-menu>
</el-scrollbar> </el-scrollbar>
@ -59,10 +60,11 @@
import { mapGetters, mapActions } from "vuex"; import { mapGetters, mapActions } from "vuex";
import SidebarItem from "./SidebarItem"; import SidebarItem from "./SidebarItem";
import variables from "@/styles/variables.scss"; import variables from "@/styles/variables.scss";
import { GET_ALL_HAVE } from '@/api/jurisdiction' import { GET_ALL_MENUS } from '@/api/jurisdiction'
export default { export default {
components: { SidebarItem }, components: { SidebarItem },
data() { return { permissionList: []} },
mounted() {}, mounted() {},
computed: { computed: {
...mapGetters(["app_routes", "sidebar"]), ...mapGetters(["app_routes", "sidebar"]),
@ -84,8 +86,8 @@ export default {
this.toggleSideBar(); this.toggleSideBar();
}, },
getAllPermission() { getAllPermission() {
GET_ALL_HAVE({}).then(res => { GET_ALL_MENUS({}).then(res => {
console.log(res) this.permissionList = res.data
}) })
} }
} }

Loading…
Cancel
Save