123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125 |
- <!-- @format -->
- <script lang="ts" setup>
- import { Swiper, SwiperSlide } from 'swiper/vue'
- import { Mousewheel, Navigation } from 'swiper/modules'
- import 'swiper/css'
- import 'swiper/css/navigation'
- defineProps({
- data: {
- type: Object,
- default: () => ({}),
- },
- })
- const modules = [Navigation, Mousewheel]
- const swiperVertical = ref<any>(null)
- const swiperHorizontal = ref<any>(null)
- const selectedIndex = ref<number | null>(null)
- function onSlideChange(swiper: any) {
- swiperHorizontal.value.slideTo(swiper.activeIndex)
- swiperVertical.value.slideTo(swiper.activeIndex)
- selectedIndex.value = swiper.activeIndex
- }
- function syncHorizontalSwiper(index: number) {
- nextTick(() => {
- swiperHorizontal.value.slideTo(index)
- selectedIndex.value = index
- })
- }
- function onVerticalSwiper(swiper: any) {
- swiperVertical.value = swiper
- }
- function onHorizontalSwiper(swiper: any) {
- swiperHorizontal.value = swiper
- }
- function isSelected(index: number) {
- return selectedIndex.value === index ? 'selected-border' : ''
- }
- </script>
- <template>
- <div class="mr-50px">
- <div class="flex">
- <div class="vertical-swiper mr-40px h-600px w-165px">
- <Swiper
- v-if="data?.goodsImgOrVideoList && data?.goodsImgOrVideoList.length"
- direction="vertical"
- :modules="modules"
- :slides-per-view="3"
- :space-between="50"
- :navigation="true"
- :mousewheel="{
- enabled: false,
- }"
- :style="{ height: `${600}px` }"
- @swiper="onVerticalSwiper"
- @slide-change="onSlideChange"
- >
- <SwiperSlide
- v-for="(item, index) in data?.goodsImgOrVideoList"
- :key="index"
- @click="syncHorizontalSwiper(index)"
- >
- <img :src="item" class="w-165px h-165px object-cover cursor-pointer b-rd-10px" :class="[isSelected(index)]" alt="" srcset="">
- </SwiperSlide>
- </Swiper>
- </div>
- <div class="h-swiper w-600px h-600px">
- <Swiper
- v-if="data?.goodsImgOrVideoList && data?.goodsImgOrVideoList.length"
- :modules="modules"
- :navigation="true"
- :style="{ height: `${600}px` }"
- @slide-change="onSlideChange"
- @swiper="onHorizontalSwiper"
- >
- <SwiperSlide v-for="item, index in data?.goodsImgOrVideoList" :key="index">
- <img :src="item" class="w-full h-full object-cover b-rd-10px" alt="" srcset="">
- </SwiperSlide>
- </Swiper>
- </div>
- </div>
- </div>
- </template>
- <style lang="less" scoped>
- .selected-border {
- border: 2px solid #c58c64;
- }
- .vertical-swiper {
- :deep(.swiper-button-prev) {
- transform: rotate(90deg) translateY(25%);
- top: 4% !important;
- left: 50% !important;
- &:after {
- content: url('@/assets/icons/swiperLeft.svg');
- }
- }
- :deep(.swiper-button-next) {
- transform: rotate(90deg) translateY(25%);
- top: 94% !important;
- left: 50% !important;
- &:after {
- content: url('@/assets/icons/swiperRight.svg');
- }
- }
- }
- .h-swiper {
- :deep(.swiper-button-prev) {
- left: 16px!important;
- &:after {
- content: url('@/assets/icons/swiperLeft.svg');
- }
- }
- :deep(.swiper-button-next) {
- right: 16px!important;
- &:after {
- content: url('@/assets/icons/swiperRight.svg');
- }
- }
- }
- </style>
|