书院官网
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

AboutMe.vue 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. <template>
  2. <div class="about">
  3. <div class="about-box">
  4. <van-sticky>
  5. <div class="form-tab">
  6. <span
  7. v-for="item in tabArr"
  8. :key="item.value"
  9. :class="[currentTab == item.value ? 'active' : '']"
  10. @click="changeTab(item.value)"
  11. >
  12. {{ item.label }}
  13. </span>
  14. </div>
  15. </van-sticky>
  16. <template v-if="!loading">
  17. <About
  18. :id="'tab' + index"
  19. class="scroll-item"
  20. v-for="(item, index) in tabArr"
  21. :key="item.value"
  22. :aboutItem="{
  23. label: item.label,
  24. value: homeData[tab[index].key],
  25. }"
  26. ></About>
  27. </template>
  28. </div>
  29. </div>
  30. </template>
  31. <script setup>
  32. import { onMounted, onUnmounted, ref } from "vue";
  33. import About from "./About.vue";
  34. import useHomeStore from "@/store/module/home";
  35. import VueScrollTo from "vue-scrollto";
  36. import { debounce } from "@/utils/common.js";
  37. const homeStore = useHomeStore();
  38. let homeData = ref({});
  39. const tab = [
  40. {
  41. label: "区位优势",
  42. value: 0,
  43. key: "regionalAdvantages",
  44. },
  45. {
  46. label: "发展机遇",
  47. value: 1,
  48. key: "developmentOpportunity",
  49. },
  50. {
  51. label: "配套建设",
  52. value: 2,
  53. key: "supportingConstruction",
  54. },
  55. {
  56. label: "发展趋势",
  57. value: 3,
  58. key: "developmentTendency",
  59. },
  60. {
  61. label: "交通优势",
  62. value: 4,
  63. key: "transportationAdvantage",
  64. },
  65. {
  66. label: "镇域概况",
  67. value: 5,
  68. key: "townProfile",
  69. },
  70. {
  71. label: "书院介绍",
  72. value: 6,
  73. key: "academyHistory",
  74. },
  75. ];
  76. const tabArr = ref(tab);
  77. const currentTab = ref(0);
  78. const loading = ref(true);
  79. const changeTab = val => {
  80. currentTab.value = val;
  81. VueScrollTo.scrollTo(`#tab${val}`, 500, { offset: -132 });
  82. };
  83. const scrollListenerHandler = debounce(() => {
  84. const scrollTop =
  85. window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop; // 滚动条偏移量
  86. document.querySelectorAll(".scroll-item").forEach((item, index) => {
  87. if (item.offsetTop - 132 <= scrollTop) {
  88. currentTab.value = index;
  89. }
  90. });
  91. }, 100);
  92. onMounted(() => {
  93. loading.value = true;
  94. homeData.value = homeStore.homeData.value;
  95. loading.value = false;
  96. window.addEventListener("scroll", scrollListenerHandler);
  97. });
  98. onUnmounted(() => {
  99. window.removeEventListener("scroll", scrollListenerHandler);
  100. });
  101. </script>
  102. <style lang="scss" scoped>
  103. .about {
  104. background: rgba(245, 245, 245, 1);
  105. &-box {
  106. @include size($contentWidth, auto);
  107. margin: 0 auto;
  108. padding: 20px 0 58px;
  109. @include border-box;
  110. }
  111. .form-tab {
  112. background: rgba(245, 245, 245, 1);
  113. @include size($contentWidth, auto);
  114. padding: 25px 0;
  115. @include flex(row, space-between, center, nowrap);
  116. @include border-box;
  117. span {
  118. width: 200px;
  119. height: 82px;
  120. @include font(24px, $color-black);
  121. font-weight: 500;
  122. @include flex(row, center, center, nowrap);
  123. border-radius: 20px;
  124. cursor: pointer;
  125. @include border-box;
  126. }
  127. .active {
  128. @include font(24px, $color-white);
  129. background: rgba(0, 153, 255, 1);
  130. }
  131. }
  132. }
  133. </style>