MenuContent.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. <template>
  2. <ul class="menu-content"
  3. :style="{width: lang.lang === 'en' ? '260px' : '180px'}"
  4. >
  5. <template v-for="(menu, index) in menus" :key="menu.text || index">
  6. <li
  7. v-if="!menu.hide"
  8. class="menu-item"
  9. @click.stop="handleClickMenuItem(menu)"
  10. :class="{'divider': menu.divider, 'disable': menu.disable}"
  11. >
  12. <div
  13. class="menu-item-content"
  14. :class="{
  15. 'has-children': menu.children,
  16. 'has-handler': menu.handler,
  17. }"
  18. v-if="!menu.divider"
  19. >
  20. <span class="text">{{menu.text}}</span>
  21. <span class="sub-text" v-if="menu.subText && !menu.children">{{menu.subText}}</span>
  22. <menu-content
  23. class="sub-menu"
  24. :menus="menu.children"
  25. v-if="menu.children && menu.children.length"
  26. :handleClickMenuItem="handleClickMenuItem"
  27. />
  28. </div>
  29. </li>
  30. </template>
  31. </ul>
  32. </template>
  33. <script lang="ts" setup>
  34. import type { ContextmenuItem } from './types'
  35. import { lang } from '@/main'
  36. defineProps<{
  37. menus: ContextmenuItem[]
  38. handleClickMenuItem: (item: ContextmenuItem) => void
  39. }>()
  40. </script>
  41. <style lang="scss" scoped>
  42. $menuWidth: 180px;
  43. $menuHeight: 30px;
  44. $subMenuWidth: 120px;
  45. .menu-content {
  46. width: $menuWidth;
  47. padding: 5px 0;
  48. background: #fff;
  49. border: 1px solid $borderColor;
  50. box-shadow: $boxShadow;
  51. border-radius: $borderRadius;
  52. list-style: none;
  53. margin: 0;
  54. }
  55. .menu-item {
  56. padding: 0 20px;
  57. color: #555;
  58. font-size: 12px;
  59. transition: all $transitionDelayFast;
  60. white-space: nowrap;
  61. height: $menuHeight;
  62. line-height: $menuHeight;
  63. background-color: #fff;
  64. cursor: pointer;
  65. &:not(.disable):hover > .menu-item-content > .sub-menu {
  66. display: block;
  67. }
  68. &:not(.disable):hover > .has-children.has-handler::after {
  69. transform: scale(1);
  70. }
  71. &:hover:not(.disable) {
  72. background-color: rgba($color: $themeColor, $alpha: .2);
  73. }
  74. &.divider {
  75. height: 1px;
  76. overflow: hidden;
  77. margin: 5px;
  78. background-color: #e5e5e5;
  79. line-height: 0;
  80. padding: 0;
  81. }
  82. &.disable {
  83. color: #b1b1b1;
  84. cursor: no-drop;
  85. }
  86. }
  87. .menu-item-content {
  88. display: flex;
  89. align-items: center;
  90. justify-content: space-between;
  91. position: relative;
  92. &.has-children::before {
  93. content: '';
  94. display: inline-block;
  95. width: 8px;
  96. height: 8px;
  97. border-width: 1px;
  98. border-style: solid;
  99. border-color: #666 #666 transparent transparent;
  100. position: absolute;
  101. right: 0;
  102. top: 50%;
  103. transform: translateY(-50%) rotate(45deg);
  104. }
  105. &.has-children.has-handler::after {
  106. content: '';
  107. display: inline-block;
  108. width: 1px;
  109. height: 24px;
  110. background-color: rgba($color: #fff, $alpha: .3);
  111. position: absolute;
  112. right: 18px;
  113. top: 3px;
  114. transform: scale(0);
  115. transition: transform $transitionDelay;
  116. }
  117. .sub-text {
  118. opacity: 0.6;
  119. }
  120. .sub-menu {
  121. width: $subMenuWidth;
  122. position: absolute;
  123. display: none;
  124. left: 112%;
  125. top: -6px;
  126. }
  127. }
  128. </style>