index.vue 4.3 KB

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