nav-menu-bar.vue 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. <template>
  2. <!-- 左下:菜单栏 -->
  3. <div class="menu-box-1">
  4. <div class="menu-box-2">
  5. <!--
  6. 菜单:
  7. unique-opened = 是否只有菜单打开
  8. default-active = 正在高亮的菜单id
  9. collapse = 是否折叠
  10. 参考文档:https://element.eleme.cn/#/zh-CN/component/menu
  11. -->
  12. <el-menu
  13. class="el-menu-style-1"
  14. :default-active="$root.activeMenuId"
  15. :collapse="!$root.isOpen"
  16. @select="selectMenu"
  17. >
  18. <div v-for="(menu, index) in $root.menuList" v-if="!menu.show" :key="index">
  19. <!-- 1 如果是子菜单 -->
  20. <el-menu-item v-if="!menu.parent && menu.isShow !== false && $root.showList.indexOf(menu.id) > -1" :index="menu.id + '' ">
  21. <span class="menu-i"><i :class="menu.icon" :title="menu.name"></i></span>
  22. <span class="menu-name">{{menu.name}}</span>
  23. </el-menu-item>
  24. <!-- 1 如果是父菜单 -->
  25. <el-submenu v-if="menu.parent && menu.isShow !== false && $root.showList.indexOf(menu.id) > -1" :index="menu.id + '' ">
  26. <template slot="title">
  27. <span class="menu-i"><i :class="menu.icon" :title="menu.name"></i></span>
  28. <span class="menu-name">{{menu.name}}</span>
  29. </template>
  30. <!-- 遍历其子项 -->
  31. <div v-for="(menu2, index) in menu.childList" :key="index">
  32. <!-- 2 如果是子菜单 -->
  33. <el-menu-item v-if="!menu2.parent && menu2.isShow !== false && $root.showList.indexOf(menu2.id) > -1" :index="menu2.id + '' ">
  34. <span class="menu-i"><i :class="menu2.icon" :title="menu2.name"></i></span>
  35. <span class="menu-name">{{menu2.name}}</span>
  36. </el-menu-item>
  37. <!-- 2 如果是父菜单 -->
  38. <el-submenu v-if="menu2.parent && menu2.isShow !== false && $root.showList.indexOf(menu2.id) > -1" :index="menu2.id + '' ">
  39. <template slot="title">
  40. <span class="menu-i"><i :class="menu2.icon" :title="menu2.name"></i></span>
  41. <span class="menu-name">{{menu2.name}}</span>
  42. </template>
  43. <!-- 遍历其子项 -->
  44. <div v-for="(menu3, index) in menu2.childList" :key="index">
  45. <!-- 3 如果是子菜单 -->
  46. <el-menu-item v-if="!menu3.parent && menu3.isShow !== false && $root.showList.indexOf(menu3.id) > -1" :index="menu3.id + '' ">
  47. <span class="menu-i"><i :class="menu3.icon" :title="menu3.name"></i></span>
  48. <span class="menu-name">{{menu3.name}}</span>
  49. </el-menu-item>
  50. <!-- 3 如果是父菜单 -->
  51. <el-submenu v-if="menu3.parent && menu3.isShow !== false && $root.showList.indexOf(menu3.id) > -1" :index="menu3.id + '' ">
  52. <template slot="title">
  53. <span class="menu-i"><i :class="menu3.icon" :title="menu3.name"></i></span>
  54. <span class="menu-name">{{menu3.name}}</span>
  55. </template>
  56. <!-- 4 -->
  57. <div v-for="(menu4, index) in menu3.childList" :key="index">
  58. <el-menu-item v-if="menu4.isShow !== false && $root.showList.indexOf(menu4.id) > -1" :index="menu4.id + '' ">
  59. <span class="menu-i"><i :class="menu4.icon" :title="menu4.name"></i></span>
  60. <span class="menu-name">{{menu4.name}}</span>
  61. </el-menu-item>
  62. </div>
  63. </el-submenu>
  64. </div>
  65. </el-submenu>
  66. </div>
  67. </el-submenu>
  68. </div>
  69. </el-menu>
  70. <!-- tab被拖拽时的遮罩(左拖拽:关闭) -->
  71. <div class="shade-fox" v-if="$root.isDrag"
  72. @dragover="$event.preventDefault();"
  73. @drop="$event.preventDefault(); $event.stopPropagation(); $root.$refs['com-right-menu'].rightTab = $root.dragTab; $root.$refs['com-right-menu'].right_close();">
  74. <span style="font-size: 16px;">关闭</span>
  75. </div>
  76. </div>
  77. </div>
  78. </template>
  79. <script>
  80. module.exports = {
  81. data() {
  82. return {
  83. }
  84. },
  85. methods: {
  86. // 点击子菜单时触发的回调
  87. // 参数:index=点击菜单index标识(不是下标,是菜单id),
  88. // indexArray=所有已经打开的菜单id数组,形如:['1', '1-1', '1-1-1']
  89. selectMenu: function(index, indexArray) {
  90. this.$root.showMenuById(index);
  91. },
  92. },
  93. created() {
  94. }
  95. }
  96. </script>
  97. <style scoped>
  98. /* 1 2 配合,把滚动条隐藏 */
  99. .menu-box-1{width: calc(var(--nav-left-width) + 20px); height: 100%; overflow-y: auto;}
  100. .menu-box-2{width: calc(var(--nav-left-width) + 1px); padding-bottom: 200px;}
  101. .menu-box-1 i[class^=el-icon-]{font-size: 16px;}
  102. .menu-box-2 .menu-i{display: inline-block; vertical-align: top; width: 29px;}
  103. /* 动画速度加快 */
  104. .menu-box-1,.menu-box-2 *{transition: all 0.2s;}
  105. /* 隐藏右边框 */
  106. .el-menu{border: 0px;}
  107. /* 一级菜单,高度45px */
  108. .el-menu-item,
  109. .el-submenu__title{height: 45px !important; line-height: 45px !important;}
  110. /* 二级以下菜单,高度40px */
  111. .el-submenu .el-menu-item,
  112. .el-submenu .el-submenu .el-submenu__title{height: 40px !important; line-height: 40px !important;}
  113. /* 二级菜单 左边距 */
  114. .el-submenu .el-menu-item,
  115. .el-submenu .el-submenu .el-submenu__title{padding-left: 2.5em !important;}
  116. /* 三级菜单 左边距 */
  117. .el-submenu .el-submenu .el-menu-item,
  118. .el-submenu .el-submenu .el-submenu .el-submenu__title{padding-left: 3.6em !important;}
  119. /* 四级菜单 左边距 */
  120. .el-submenu .el-submenu .el-submenu .el-menu-item{padding-left: 4.7em !important;}
  121. </style>