You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

107 lines
2.2 KiB

2 years ago
  1. <template>
  2. <section :class="[
  3. 'swiper-container stickyBar tw-w-full tw-bg-white tw-shadow-[0_1px_2px_rgba(0,0,0,0.1)] md:tw-px-[16px] xl:tw-hidden',
  4. fixBar
  5. ? 'tw-fixed tw-left-0 tw-top-[64px] tw-z-[8] md:tw-top-[72px]'
  6. : 'tw-hidden',
  7. ]">
  8. <div :class="[
  9. 'tw-w-full tw-flex swiper-wrapper tw-px-[25px] tw-py-[12px] md:tw-mx-[40px] md:tw-px-[12px]',
  10. ]">
  11. <template v-for="(item, index) in list">
  12. <a :key="index" v-if="item.show" :class="[
  13. 'swiper-slide crollactive-item tw-body-3 tw-w-fit tw-text-base-tertiary',
  14. step == item.id ? 'active tw-text-primary-1' : 'tw-text-black',
  15. ]" href="#" v-scroll-to="{
  16. el: `#${item.id}`,
  17. offset: -140,
  18. }" @click="activeStep(item.id)">{{ $t(item.title) }}</a></template>
  19. </div>
  20. </section>
  21. </template>
  22. <script>
  23. import Swiper from "swiper/bundle";
  24. export default {
  25. components: {
  26. Swiper,
  27. },
  28. props: {
  29. fixBar: {
  30. type: Boolean,
  31. },
  32. currStep: {
  33. type: String,
  34. },
  35. list: {
  36. type: Array,
  37. },
  38. },
  39. data() {
  40. return {
  41. stickySwiper: null,
  42. step: '',
  43. click: false,
  44. };
  45. },
  46. watch: {
  47. currStep: {
  48. handler: function () {
  49. if (!this.click) {
  50. this.step = this.currStep;
  51. }
  52. }
  53. }
  54. },
  55. mounted() {
  56. let vm = this;
  57. vm.$nextTick(function () {
  58. vm.stickySwiper = new Swiper(".swiper-container.stickyBar", {
  59. observer: true,
  60. observeParents: true,
  61. slidesPerView: 3,
  62. breakpoints: {
  63. // when window width is >= 768px
  64. 768: {
  65. slidesPerView: 5,
  66. },
  67. },
  68. });
  69. vm.stickySwiper.init();
  70. vm.stickySwiper.update();
  71. });
  72. },
  73. methods: {
  74. slideTo(index) {
  75. if (!this.click) {
  76. this.stickySwiper.slideTo(index);
  77. }
  78. },
  79. activeStep(id) {
  80. this.click = true;
  81. this.step = id;
  82. setTimeout(() => {
  83. this.click = false;
  84. }, 300)
  85. }
  86. },
  87. };
  88. </script>
  89. <style lang="scss" scoped>
  90. .swiper-slide {
  91. margin-right: 20px;
  92. }
  93. .active {
  94. position: relative;
  95. &::after {
  96. content: "";
  97. display: block;
  98. position: absolute;
  99. bottom: -12px;
  100. width: 100%;
  101. height: 2px;
  102. background-color: #f48800;
  103. }
  104. }
  105. </style>