HomeAside.vue 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. <script>
  2. import menuList from '@/data/json/menuList.json'
  3. import {requireImg} from "@/utils/requireImg";
  4. export default {
  5. props: {
  6. collapse: Boolean,
  7. },
  8. data() {
  9. return {
  10. selectedKey: [],
  11. iconVerticalAlign: '',
  12. asideStyle: {},
  13. menuList,
  14. }
  15. },
  16. watch: {
  17. collapse(val) {
  18. this.suitHeight(val)
  19. },
  20. $route() {
  21. this.getCurrRoute()
  22. this.$forceUpdate();
  23. }
  24. },
  25. mounted() {
  26. this.suitHeight(this.collapse)
  27. },
  28. emits: ['update:collapse'],
  29. setup(props, context) {
  30. const methods = {
  31. toggleCollapse() {
  32. const val = !props.collapse
  33. context.emit('update:collapse', val)
  34. },
  35. }
  36. return methods
  37. },
  38. methods: {
  39. requireImg,
  40. suitHeight(val) {
  41. this.getCurrRoute()
  42. this.$nextTick(() => {
  43. // let height = document.getElementsByClassName('home')[0].clientHeight
  44. this.asideStyle = { height: `100%` }
  45. if (val)
  46. this.asideStyle.width = '60px'
  47. if (this.collapse) {
  48. document.getElementsByClassName("aside-collapse")[0].style.textAlign = 'center'
  49. document.getElementsByClassName("aside-collapse")[0].style.marginLeft = '0'
  50. this.iconVerticalAlign = '';
  51. } else {
  52. document.getElementsByClassName("aside-collapse")[0].style.textAlign = ''
  53. document.getElementsByClassName("aside-collapse")[0].style.marginLeft = '5%'
  54. this.iconVerticalAlign = 'text-top';
  55. }
  56. })
  57. },
  58. getCurrRoute() {
  59. this.$nextTick(()=>{
  60. if (this.$route.matched.length>1) {
  61. this.selectedKey = [this.$route.matched[1].path+'']
  62. }
  63. let index = this.menuList.findIndex(i=>i.router==this.selectedKey)
  64. this.handleClickMenuItem(this.menuList[index])
  65. this.$forceUpdate()
  66. })
  67. },
  68. handleClickMenuItem(item) {
  69. this.$store.menuStore().currMenu = item;
  70. },
  71. handleSelected(item) {
  72. this.$router.push({path: item.key})
  73. },
  74. },
  75. }
  76. </script>
  77. <template>
  78. <div class="ioc-aside">
  79. <div title="收起" class="collapse-btn" style="right: 0;background-color: #23608c;border-radius: 15px 0px 0px 15px" @click="toggleCollapse" v-if="!collapse">
  80. <div style="margin-top: 30px;margin-left: 2px" >
  81. <a-icon title="收起" style="color: white;font-size: 12px;vertical-align: text-top" type="menu-fold" />
  82. </div>
  83. </div>
  84. <div title="展开" class="collapse-btn" @click="toggleCollapse" v-if="collapse">
  85. <div style="margin-top: 30px;" >
  86. <a-icon title="展开" style="color: white;font-size: 12px;vertical-align: text-top;" type="menu-unfold" />
  87. </div>
  88. </div>
  89. <a-menu
  90. class="menu"
  91. theme="dark"
  92. :style="asideStyle"
  93. v-model:selectedKeys="selectedKey"
  94. mode="inline"
  95. @select="handleSelected"
  96. >
  97. <!--<a-menu-item-group key="g1">-->
  98. <!-- <template slot="title">-->
  99. <!-- <div style="height: 12px"></div>-->
  100. <!-- <div class="aside-collapse" style="color: white; cursor: pointer;margin-left: 5%" @click="toggleCollapse">-->
  101. <!-- <a-icon style="font-size: 18px;vertical-align: text-top" type="menu-fold" v-if="!collapse" />-->
  102. <!-- <a-icon style="font-size: 18px;vertical-align: text-top;" type="menu-unfold" v-if="collapse" />-->
  103. <!-- <span style="margin-left: 15px;vertical-align: top" v-if="!collapse">展开/收起</span>-->
  104. <!-- </div>-->
  105. <!-- </template>-->
  106. <!--</a-menu-item-group>-->
  107. <a-menu-item v-for="item in menuList" :key="item.router" @click="handleClickMenuItem(item)" >
  108. <span class="anticon" :style="{verticalAlign: iconVerticalAlign}">
  109. <a-avatar class="function-avatar" shape="square" :size="20" :src="requireImg('function/'+item.icon)"></a-avatar>
  110. </span>
  111. <span >
  112. {{ item.name }}
  113. </span>
  114. </a-menu-item>
  115. </a-menu>
  116. </div>
  117. </template>
  118. <style lang="less" scoped>
  119. @menu-dark-bg: #266a99;
  120. @menu-dark-submenu-bg: #266a99;
  121. @menu-dark-color: #fff;
  122. @menu-dark-arrow-color: #fff;
  123. @menu-dark-highlight-color: #fff;
  124. .ioc-aside {
  125. //width: 100%;
  126. height: 100%;
  127. position: relative;
  128. .aside-collapse {
  129. width: 100%;
  130. }
  131. .aside-collapse:hover {
  132. span {
  133. color: #2ba8e4;
  134. }
  135. i {
  136. color: #2ba8e4;
  137. }
  138. }
  139. .collapse-btn {
  140. width: 14px;
  141. height: 80px;
  142. cursor: pointer;
  143. background-color: #266999;
  144. position: absolute;
  145. top: 40%;
  146. right: -10px;
  147. z-index: 999;
  148. border-top-right-radius: 12px;
  149. border-bottom-right-radius: 12px;
  150. }
  151. /*菜单样式*/
  152. /deep/ .ant-menu-sub {
  153. box-shadow: none !important;
  154. }
  155. /deep/ .ant-menu-item-selected {
  156. color: @menu-dark-selected-item-text-color !important;
  157. }
  158. .ant-menu-inline-collapsed > .ant-menu-item {
  159. padding: 0 !important;
  160. margin-left: 0 !important;
  161. padding-left: 33% !important;
  162. }
  163. /deep/ .ant-menu-inline-collapsed > .ant-menu-item-group > .ant-menu-item-group-list > .ant-menu-item {
  164. padding: 0 !important;
  165. margin-left: 0 !important;
  166. padding-left: 33% !important;
  167. }
  168. }
  169. </style>