index.vue 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. <template>
  2. <ButtonPane class="menus" :size="size" :dire="dire">
  3. <div
  4. v-for="menu in menus"
  5. :key="menu.key"
  6. class="menu"
  7. :style="menuStyle"
  8. :class="{ active: activeKey === menu.key, dire, disabled: disabledMap[menu.key], border: menu.border }"
  9. @click="menu.onClick && menu.onClick(menu)"
  10. v-show="!menu.hide"
  11. >
  12. <template v-if="$slots.default">
  13. <slot :data="menu" />
  14. </template>
  15. <ui-icon :type="menu.icon || 'close'" class="icon" v-else/>
  16. <p v-if="menu.text">{{ menu.text }}</p>
  17. </div>
  18. </ButtonPane>
  19. </template>
  20. <script setup lang="ts">
  21. import ButtonPane from '@/components/button-pane/index.vue'
  22. import UiIcon from "@/components/base/components/icon/index.vue";
  23. import {computed} from "vue";
  24. type Menu = {
  25. key: any,
  26. text?: string,
  27. hide?: boolean
  28. border?: boolean
  29. icon?: string,
  30. disabled?: boolean | (() => boolean)
  31. onClick?: (menu: Menu) => void
  32. }
  33. const props = withDefaults(
  34. defineProps<{ menus: Menu[], activeKey?: any, dire?: 'row' | 'column', size?: number }>(),
  35. {dire: 'row', size: 64}
  36. )
  37. const disabledMap = computed(() => {
  38. const map = {}
  39. for (let menu of props.menus) {
  40. map[menu.key] = !menu.disabled ? false :
  41. typeof menu.disabled === "boolean" ? menu.disabled : menu.disabled()
  42. }
  43. return map
  44. })
  45. const menuStyle = computed(() => {
  46. const offset = props.size / 4;
  47. return props.dire === 'row'
  48. ? {
  49. padding: `0 10px`,
  50. marginRight: '8px'
  51. }
  52. :
  53. {
  54. padding: `10px 0 `,
  55. marginBottom: '8px'
  56. }
  57. })
  58. </script>
  59. <style lang="scss" scoped>
  60. .menu {
  61. &:first-child:last-child {
  62. position: absolute;
  63. left: 50%;
  64. top: 50%;
  65. height: 80%;
  66. transform: translate(-50%, -50%);
  67. }
  68. min-width: 56px;
  69. display: flex;
  70. flex-direction: column;
  71. cursor: pointer;
  72. height: 100%;
  73. text-align: center;
  74. transition: color .3s ease;
  75. color: #fff;
  76. border-radius: 4px;
  77. align-items: center;
  78. justify-content: center;
  79. &.border {
  80. position: relative;
  81. &:after {
  82. content: "";
  83. position: absolute;
  84. border-bottom: 1px solid rgba(255, 255, 255, 0.2);
  85. left: 10px;
  86. right: 10px;
  87. bottom: 0;
  88. }
  89. }
  90. &.active {
  91. color: var(--colors-primary-base);
  92. }
  93. &.active {
  94. background: rgba(255, 255, 255, 0.1);;
  95. }
  96. .icon {
  97. display: flex;
  98. align-items: center;
  99. justify-content: center;
  100. font-size: 20px;
  101. }
  102. p {
  103. flex: 1;
  104. flex: none;
  105. margin-top: 4px;
  106. line-height: 17px;
  107. font-size: 14px;
  108. white-space:nowrap;
  109. }
  110. }
  111. </style>