index.vue 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <template>
  2. <div
  3. class="page-nav"
  4. data-aria-viewport-area
  5. aria-description="You've reached the secondary menu under the Exhibition section. This menu contains four options. To browse the content, please use the tab key."
  6. >
  7. <ul>
  8. <li
  9. v-for="(item, index) in list"
  10. :key="index"
  11. :class="{
  12. active: isActive(index, item.name),
  13. }"
  14. @click="$router.push(item.routeParams)"
  15. @keydown.enter.passive="$router.push(item.routeParams)"
  16. tabindex="0"
  17. aria-label="Link"
  18. :aria-description="item.name"
  19. >
  20. <img :src="item.img" alt="" />
  21. <p>
  22. {{ item.name }}
  23. </p>
  24. </li>
  25. </ul>
  26. </div>
  27. </template>
  28. <script lang="ts" setup>
  29. import { isNumber } from "lodash-unified";
  30. import type { PageNavListItemType } from "./types";
  31. const props = defineProps<{
  32. /**
  33. * 导航列表
  34. */
  35. list: PageNavListItemType[];
  36. /**
  37. * 当前所在路由名称
  38. */
  39. curRouteName?: string;
  40. /**
  41. * 当前所在导航索引,默认通过路由名称判断
  42. */
  43. activeIndex?: number;
  44. }>();
  45. const isActive = (idx: number, name: string) => {
  46. if (isNumber(props.activeIndex)) {
  47. return props.activeIndex === idx;
  48. }
  49. return props.curRouteName === name;
  50. };
  51. </script>
  52. <style lang="scss" scoped>
  53. .page-nav {
  54. width: 100%;
  55. padding-bottom: 8px;
  56. background: url("@/assets/images/Visit/bg_3.png") left bottom repeat-x #f1f1f1;
  57. overflow: hidden;
  58. ul {
  59. margin: 0 auto;
  60. display: flex;
  61. width: 1180px;
  62. li {
  63. display: flex;
  64. flex-direction: column;
  65. align-items: center;
  66. justify-content: center;
  67. width: 168px;
  68. height: 108px;
  69. cursor: pointer;
  70. &.active {
  71. background: url("@/assets/images/Visit/bg_1.jpg") center top no-repeat
  72. #f1f1f1;
  73. }
  74. p {
  75. margin-top: 5px;
  76. font-size: 14px;
  77. line-height: 18px;
  78. }
  79. }
  80. }
  81. }
  82. </style>