ContainerAside.vue 3.4 KB

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