nav-menu-bar.vue 5.9 KB

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