index.vue 4.9 KB

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