ContainerAside.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. <script>
  2. import {requireImg} from "@/utils/requireImg";
  3. export default {
  4. data() {
  5. return {
  6. selectedKeys: [],
  7. highLight: {backgroundColor: '#e9f6fd'},
  8. routers: [],
  9. menuList: [],
  10. height: '100%',
  11. }
  12. },
  13. mounted() {
  14. let app = this;
  15. this.routers = this.$router.options.routes;
  16. this.$nextTick(() => {
  17. app.getCurrMenuList()
  18. })
  19. },
  20. methods: {
  21. requireImg,
  22. getCurrMenuList() {
  23. let arr = this.$route.matched;
  24. let route = this.routers[0].children;
  25. if (arr.length>1) {
  26. let obj = route.find((e) => (e.path == arr[1].path));
  27. route = obj.children;
  28. }
  29. this.menuList = JSON.parse(JSON.stringify(route))
  30. this.selectedKeys = [];
  31. if (arr.length>2) {
  32. for (let i = 0; i < arr.length; i++) {
  33. this.selectedKeys.push(arr[i].path)
  34. }
  35. } else if (arr.length===2) {
  36. if (this.menuList.length>0 && !this.menuList[0].children) {
  37. this.handleClick(this.menuList[0]);
  38. this.selectedKeys.push(this.menuList[0].path)
  39. }
  40. }
  41. },
  42. handleClick(item) {
  43. let path = item.path?item.path:item.key
  44. this.$router.push({path: path})
  45. this.$forceUpdate()
  46. }
  47. }
  48. }
  49. </script>
  50. <template>
  51. <div class="containerAside" :style="{height: '100%'}">
  52. <a-menu
  53. style="width: 100%;padding-top: 8px;height: 100%"
  54. mode="inline"
  55. theme="dark"
  56. v-model:selectedKeys="selectedKeys"
  57. @click="handleClick"
  58. >
  59. <template v-for="item in menuList">
  60. <a-menu-item class="menuItem" :key="item.path" :route="item.key" v-if="!item.children">
  61. <span class="anticon" style="vertical-align: text-top">
  62. <a-avatar class="function-avatar" shape="square" :size="20" :src="requireImg(item.icon)"></a-avatar>
  63. </span>
  64. <span >
  65. {{ item.meta.breadcrumb }}
  66. </span>
  67. </a-menu-item>
  68. <a-sub-menu :key="item.name" v-else>
  69. <template #title>
  70. <span class="anticon" style="vertical-align: text-top">
  71. <a-avatar class="function-avatar" shape="square" :size="20" :src="requireImg(item.icon)"></a-avatar>
  72. </span>
  73. <span>{{ item.meta.breadcrumb }}</span>
  74. </template>
  75. <a-menu-item v-for="subItem in item.children" :key="subItem.path" :route="subItem.path">
  76. <span class="anticon" style="vertical-align: text-top">
  77. <a-avatar class="function-avatar" shape="square" :size="20" :src="requireImg(item.icon)"></a-avatar>
  78. </span>
  79. <span>{{ subItem.meta.breadcrumb }}</span>
  80. </a-menu-item>
  81. </a-sub-menu>
  82. </template>
  83. </a-menu>
  84. </div>
  85. </template>
  86. <style lang="less" scoped>
  87. @menu-dark-bg: #ffffff;
  88. @menu-dark-submenu-bg: #ffffff;
  89. @menu-dark-color: #808080;
  90. @menu-dark-arrow-color: #808080;
  91. @menu-dark-highlight-color: #808080;
  92. @menu-dark-item-active-bg: #e5f4ff;
  93. @menu-dark-selected-item-icon-color: #808080;
  94. @menu-dark-selected-item-text-color: #808080;
  95. .containerAside {
  96. width: 170px;
  97. height: 100%;
  98. border-right: 1px solid #eeeeee;
  99. display: inline-block;
  100. vertical-align: top;
  101. .menuItem {
  102. margin: 15px 0;
  103. }
  104. /deep/ .ant-menu-sub {
  105. box-shadow: none !important;
  106. background-color: white;
  107. margin: 0 !important;
  108. }
  109. /deep/ .ant-menu-item-selected {
  110. color: @menu-dark-selected-item-text-color !important;
  111. }
  112. /deep/ .ant-menu-dark .ant-menu-submenu-title:hover {
  113. color: @menu-dark-selected-item-text-color;
  114. }
  115. .ant-menu-inline-collapsed > .ant-menu-item {
  116. padding: 0 !important;
  117. margin-left: 0 !important;
  118. padding-left: 33% !important;
  119. }
  120. /deep/ .ant-menu-inline-collapsed > .ant-menu-item-group > .ant-menu-item-group-list > .ant-menu-item {
  121. padding: 0 !important;
  122. margin-left: 0 !important;
  123. padding-left: 33% !important;
  124. }
  125. }
  126. </style>