slide-item.vue 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <template>
  2. <el-sub-menu
  3. :index="index"
  4. v-if="data.children?.length"
  5. :class="{ 'is-active': active }"
  6. @click="clickHandler"
  7. >
  8. <template #title>
  9. <div
  10. class="menu-layout"
  11. @mouseenter="hover?.enterHandler(props.data)"
  12. @mouseleave="hover?.leaveHandler(props.data)"
  13. >
  14. <Icon :name="showAttr.icon" size="24px" />
  15. <span>{{ showAttr.name }}</span>
  16. </div>
  17. </template>
  18. <SlideItem v-for="item in data.children" :data="item" />
  19. </el-sub-menu>
  20. <el-menu-item
  21. v-else
  22. :index="index"
  23. :class="{ 'is-active': active }"
  24. @click="clickHandler"
  25. >
  26. <div
  27. class="menu-layout"
  28. @mouseenter="hover?.enterHandler(props.data)"
  29. @mouseleave="hover?.leaveHandler(props.data)"
  30. >
  31. <Icon :name="showAttr.icon" size="22px" />
  32. <span>{{ showAttr.name }}</span>
  33. </div>
  34. </el-menu-item>
  35. </template>
  36. <script lang="ts" setup>
  37. import { ElSubMenu, ElMenuItem } from "element-plus";
  38. import { MenuItem } from "./menu";
  39. import { computed } from "vue";
  40. import { hoverManage } from "@/utils/shared";
  41. const props = defineProps<{
  42. data: MenuItem;
  43. viewData?: Pick<MenuItem, "icon" | "name">;
  44. enterHandler?: (data: MenuItem) => (data: MenuItem) => void;
  45. }>();
  46. const emit = defineEmits<{
  47. (e: "update:activeIndex", value: string): void;
  48. }>();
  49. const index = computed(() => props.data.value || props.data.name);
  50. const showAttr = computed(() => props.viewData || props.data);
  51. const active = computed(() => false);
  52. const clickHandler = () => {
  53. if (props.data.children?.length) {
  54. const item = props.data.children[0];
  55. emit("update:activeIndex", item.value || item.name);
  56. }
  57. };
  58. const hover = props.enterHandler && hoverManage(props.enterHandler);
  59. </script>
  60. <style lang="scss">
  61. .is-active .menu-layout {
  62. background: var(--el-color-primary-light-7);
  63. // background: rgba(88,185,234,0.3);
  64. }
  65. </style>