index.vue 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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 }"
  9. @click="menu.onClick && menu.onClick(menu)"
  10. >
  11. <template v-if="$slots.default">
  12. <slot :data="menu" />
  13. </template>
  14. <ui-icon :type="menu.icon || 'close'" class="icon" v-else/>
  15. <p v-if="menu.text">{{ menu.text }}</p>
  16. </div>
  17. </ButtonPane>
  18. </template>
  19. <script setup lang="ts">
  20. import ButtonPane from '@/components/button-pane/index.vue'
  21. import UiIcon from "@/components/base/components/icon/index.vue";
  22. import {computed} from "vue";
  23. type Menu = {
  24. key: any,
  25. text?: string,
  26. icon?: string,
  27. onClick?: (menu: Menu) => void
  28. }
  29. const props = withDefaults(
  30. defineProps<{ menus: Menu[], activeKey?: any, dire?: 'row' | 'column', size?: number }>(),
  31. {dire: 'row', size: 64}
  32. )
  33. const menuStyle = computed(() => {
  34. const offset = props.size / 4;
  35. return props.dire === 'row'
  36. ? {
  37. padding: `0 10px`,
  38. marginRight: '8px'
  39. }
  40. :
  41. {
  42. padding: `10px 0 `,
  43. marginBottom: '8px'
  44. }
  45. })
  46. </script>
  47. <style lang="scss" scoped>
  48. .menu {
  49. min-width: 56px;
  50. display: flex;
  51. flex-direction: column;
  52. cursor: pointer;
  53. height: 100%;
  54. text-align: center;
  55. transition: color .3s ease;
  56. color: #fff;
  57. border-radius: 4px;
  58. &.active,
  59. &:hover {
  60. color: var(--colors-primary-base);
  61. }
  62. &.active {
  63. background: rgba(255, 255, 255, 0.1);;
  64. }
  65. .icon {
  66. display: flex;
  67. align-items: center;
  68. justify-content: center;
  69. font-size: 20px;
  70. flex: 1;
  71. }
  72. p {
  73. line-height: 17px;
  74. font-size: 12px;
  75. white-space:nowrap;
  76. }
  77. }
  78. </style>