index.vue 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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: menu.disabled }"
  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. disabled?: boolean
  28. onClick?: (menu: Menu) => void
  29. }
  30. const props = withDefaults(
  31. defineProps<{ menus: Menu[], activeKey?: any, dire?: 'row' | 'column', size?: number }>(),
  32. {dire: 'row', size: 64}
  33. )
  34. const menuStyle = computed(() => {
  35. const offset = props.size / 4;
  36. return props.dire === 'row'
  37. ? {
  38. padding: `0 10px`,
  39. marginRight: '8px'
  40. }
  41. :
  42. {
  43. padding: `10px 0 `,
  44. marginBottom: '8px'
  45. }
  46. })
  47. </script>
  48. <style lang="scss" scoped>
  49. .menu {
  50. min-width: 56px;
  51. display: flex;
  52. flex-direction: column;
  53. cursor: pointer;
  54. height: 100%;
  55. text-align: center;
  56. transition: color .3s ease;
  57. color: #fff;
  58. border-radius: 4px;
  59. &.active,
  60. &:hover {
  61. color: var(--colors-primary-base);
  62. }
  63. &.active {
  64. background: rgba(255, 255, 255, 0.1);;
  65. }
  66. .icon {
  67. display: flex;
  68. align-items: center;
  69. justify-content: center;
  70. font-size: 20px;
  71. flex: 1;
  72. }
  73. p {
  74. line-height: 17px;
  75. font-size: 14px;
  76. white-space:nowrap;
  77. }
  78. }
  79. </style>