index.vue 2.6 KB

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