index.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. <template>
  2. <div class="leftMenu">
  3. <a-menu theme="dark"
  4. mode="inline"
  5. class="left-menu"
  6. v-model:selectedKeys="selectedKeys"
  7. v-model:openKeys="openKeys"
  8. @click="menuClick">
  9. <a-sub-menu v-for="item in menuList"
  10. :key="item.key">
  11. <template #title>
  12. <span>
  13. <span class="menu-item_title"
  14. v-show="!collapsed">{{ item.title }}</span>
  15. </span>
  16. </template>
  17. <a-menu-item :key="subItem.key"
  18. v-for="subItem in item.children">
  19. <span>{{ subItem.title }}</span>
  20. </a-menu-item>
  21. </a-sub-menu>
  22. </a-menu>
  23. </div>
  24. </template>
  25. <script lang="ts">
  26. import { defineComponent, ref, PropType, SetupContext } from 'vue';
  27. import { MenuList } from '@/services/go/ermcp/goodsInfo/interface';
  28. import { initMenu } from '../../setup';
  29. // 菜单栏
  30. const handleMenu = (context: SetupContext) => {
  31. const collapsed = ref<boolean>(false);
  32. const selectedKeys = ref<string[]>(['1-0']);
  33. const openKeys = ref<string[]>(['1']);
  34. const preOpenKeys = ref<string[]>(['1']);
  35. // 控制菜单是否隐藏
  36. function collapse(collapsed: boolean) {
  37. if (collapsed) {
  38. preOpenKeys.value = openKeys.value;
  39. openKeys.value = [];
  40. } else {
  41. openKeys.value = preOpenKeys.value;
  42. }
  43. }
  44. function menuClick(value: any) {
  45. context.emit('chooseMenu', value.key);
  46. }
  47. return { collapsed, selectedKeys, openKeys, collapse, menuClick };
  48. };
  49. export default defineComponent({
  50. name: 'leftMenu',
  51. props: {
  52. menuList: {
  53. default: initMenu,
  54. type: Object as PropType<MenuList[]>,
  55. },
  56. },
  57. components: {},
  58. setup(props, context) {
  59. const { collapsed, selectedKeys, openKeys, collapse, menuClick } = handleMenu(context);
  60. return {
  61. menuClick,
  62. collapsed,
  63. collapse,
  64. selectedKeys,
  65. openKeys,
  66. };
  67. },
  68. });
  69. </script>
  70. <style lang="less">
  71. .leftMenu {
  72. height: 100%;
  73. ul.ant-menu.ant-menu-inline {
  74. background-color: transparent;
  75. li.ant-menu-submenu {
  76. padding-bottom: 0;
  77. .ant-menu-submenu-title {
  78. color: @m-grey2;
  79. font-size: 16px;
  80. height: 45px;
  81. line-height: 45px;
  82. margin-top: 0;
  83. margin-bottom: 0;
  84. padding: 0;
  85. padding-left: 32px !important;
  86. .icon {
  87. font-size: 20px;
  88. }
  89. .menu-item_title {
  90. display: inline-block;
  91. font-size: 16px;
  92. color: @m-grey2;
  93. }
  94. .ant-menu-submenu-arrow {
  95. left: 12px;
  96. color: @m-white0;
  97. }
  98. }
  99. .ant-menu-inline.ant-menu-sub {
  100. background-color: transparent;
  101. box-shadow: none;
  102. .ant-menu-item {
  103. padding-left: 64px !important;
  104. height: 30px;
  105. line-height: 30px;
  106. color: @m-grey2;
  107. font-size: 14px;
  108. margin-top: 0;
  109. margin-bottom: 0;
  110. padding-right: 0;
  111. }
  112. }
  113. }
  114. li.ant-menu-submenu-open {
  115. .ant-menu-submenu-title {
  116. color: @m-white0;
  117. .icon {
  118. color: @m-white0;
  119. }
  120. }
  121. .ant-menu-sub {
  122. .ant-menu-item.ant-menu-item-selected {
  123. color: @m-blue0;
  124. background-color: transparent;
  125. }
  126. }
  127. }
  128. }
  129. }
  130. .ant-menu-vertical {
  131. .ant-menu-submenu-vertical {
  132. height: 60px;
  133. line-height: 60px;
  134. padding: 5px 0;
  135. .ant-menu-submenu-title {
  136. height: 50px;
  137. line-height: 50px;
  138. .icon {
  139. font-size: 20px;
  140. }
  141. }
  142. }
  143. .ant-menu-submenu {
  144. .ant-menu-submenu-title {
  145. .menu-item_title {
  146. display: none;
  147. }
  148. }
  149. }
  150. }
  151. </style
  152. >;