left.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. <!-- @format -->
  2. <script lang="ts" setup>
  3. import { Swiper, SwiperSlide } from 'swiper/vue'
  4. import { Mousewheel, Navigation } from 'swiper/modules'
  5. import 'swiper/css'
  6. import 'swiper/css/navigation'
  7. defineProps({
  8. data: {
  9. type: Object,
  10. default: () => ({}),
  11. },
  12. })
  13. const modules = [Navigation, Mousewheel]
  14. const swiperVertical = ref<any>(null)
  15. const swiperHorizontal = ref<any>(null)
  16. const selectedIndex = ref<number | null>(null)
  17. function onSlideChange(swiper: any) {
  18. swiperHorizontal.value.slideTo(swiper.activeIndex)
  19. swiperVertical.value.slideTo(swiper.activeIndex)
  20. selectedIndex.value = swiper.activeIndex
  21. }
  22. function syncHorizontalSwiper(index: number) {
  23. nextTick(() => {
  24. swiperHorizontal.value.slideTo(index)
  25. selectedIndex.value = index
  26. })
  27. }
  28. function onVerticalSwiper(swiper: any) {
  29. swiperVertical.value = swiper
  30. }
  31. function onHorizontalSwiper(swiper: any) {
  32. swiperHorizontal.value = swiper
  33. }
  34. function isSelected(index: number) {
  35. return selectedIndex.value === index ? 'selected-border' : ''
  36. }
  37. </script>
  38. <template>
  39. <div class="mr-50px">
  40. <div class="flex">
  41. <div class="vertical-swiper mr-40px h-600px w-165px">
  42. <Swiper
  43. v-if="data?.goodsImgOrVideoList && data?.goodsImgOrVideoList.length"
  44. direction="vertical"
  45. :modules="modules"
  46. :slides-per-view="3"
  47. :space-between="50"
  48. :navigation="true"
  49. :mousewheel="{
  50. enabled: false,
  51. }"
  52. :style="{ height: `${600}px` }"
  53. @swiper="onVerticalSwiper"
  54. @slide-change="onSlideChange"
  55. >
  56. <SwiperSlide
  57. v-for="(item, index) in data?.goodsImgOrVideoList"
  58. :key="index"
  59. @click="syncHorizontalSwiper(index)"
  60. >
  61. <img :src="item" class="w-165px h-165px object-cover cursor-pointer b-rd-10px" :class="[isSelected(index)]" alt="" srcset="">
  62. </SwiperSlide>
  63. </Swiper>
  64. </div>
  65. <div class="h-swiper w-600px h-600px">
  66. <Swiper
  67. v-if="data?.goodsImgOrVideoList && data?.goodsImgOrVideoList.length"
  68. :modules="modules"
  69. :navigation="true"
  70. :style="{ height: `${600}px` }"
  71. @slide-change="onSlideChange"
  72. @swiper="onHorizontalSwiper"
  73. >
  74. <SwiperSlide v-for="item, index in data?.goodsImgOrVideoList" :key="index">
  75. <img :src="item" class="w-full h-full object-cover b-rd-10px" alt="" srcset="">
  76. </SwiperSlide>
  77. </Swiper>
  78. </div>
  79. </div>
  80. </div>
  81. </template>
  82. <style lang="less" scoped>
  83. .selected-border {
  84. border: 2px solid #c58c64;
  85. }
  86. .vertical-swiper {
  87. :deep(.swiper-button-prev) {
  88. transform: rotate(90deg) translateY(25%);
  89. top: 4% !important;
  90. left: 50% !important;
  91. &:after {
  92. content: url('@/assets/icons/swiperLeft.svg');
  93. }
  94. }
  95. :deep(.swiper-button-next) {
  96. transform: rotate(90deg) translateY(25%);
  97. top: 94% !important;
  98. left: 50% !important;
  99. &:after {
  100. content: url('@/assets/icons/swiperRight.svg');
  101. }
  102. }
  103. }
  104. .h-swiper {
  105. :deep(.swiper-button-prev) {
  106. left: 16px!important;
  107. &:after {
  108. content: url('@/assets/icons/swiperLeft.svg');
  109. }
  110. }
  111. :deep(.swiper-button-next) {
  112. right: 16px!important;
  113. &:after {
  114. content: url('@/assets/icons/swiperRight.svg');
  115. }
  116. }
  117. }
  118. </style>