nav-menu-bar.vue 5.2 KB

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