Commit f2d0e769 authored by 刘梦焕's avatar 刘梦焕

fix: 轮播交互修改

parent ba6b52f9
...@@ -49,10 +49,18 @@ const Demo = () => { ...@@ -49,10 +49,18 @@ const Demo = () => {
}, },
]; ];
const _JessibucaObj = {
operateBtns: {
screenshot: false,
},
loadingText: '视频加载中',
decoder: '/JessibucaVideo/decoder.js',
};
return ( return (
<> <>
<Button onClick={() => setShowModal(true)}>打开弹窗</Button> <Button onClick={() => setShowModal(true)}>打开弹窗</Button>
<VideoSliderModal modalInfo={modalInfo} videoInfos={videos} /> <VideoSliderModal modalInfo={modalInfo} videoInfos={videos} JessibucaObj={_JessibucaObj} />
</> </>
); );
}; };
......
import VmsVideo from '@wisdom-components/VmsVideo'; import VmsVideo from '@wisdom-components/VmsVideo';
import { Modal, Space } from 'antd'; import { Modal } from 'antd';
import React, { useState } from 'react'; import React from 'react';
import SwiperCore, { Autoplay, Lazy, Navigation, Pagination, Virtual } from 'swiper'; import SwiperCore, { Autoplay, Lazy, Navigation, Pagination, Virtual } from 'swiper';
import { Swiper, SwiperSlide } from 'swiper/react'; import { Swiper, SwiperSlide } from 'swiper/react';
import 'swiper/swiper.min.css'; import 'swiper/swiper.min.css';
...@@ -10,36 +10,24 @@ SwiperCore.use([Virtual, Navigation, Lazy, Autoplay, Pagination]); ...@@ -10,36 +10,24 @@ SwiperCore.use([Virtual, Navigation, Lazy, Autoplay, Pagination]);
const VideoSliderModal = (props) => { const VideoSliderModal = (props) => {
const { modalInfo, videoInfos, JessibucaObj } = props; const { modalInfo, videoInfos, JessibucaObj } = props;
const [swiper, setSwiper] = useState(null);
const [activeIndex, setActiveIndex] = useState(0);
const handleNavigation = (direction) => { // 切换轮播页 控制按钮是否显示
if (swiper) { const handleSlideChange = (swiper) => {
if (direction === 'prev') { const nextButton = document.querySelector('.swiper-button-next');
swiper.slidePrev(); const prevButton = document.querySelector('.swiper-button-prev');
} else if (direction === 'next') { if (swiper.isBeginning) {
swiper.slideNext(); prevButton.style.display = 'none'; // 隐藏左侧按钮
} } else {
prevButton.style.display = 'block'; // 显示左侧按钮
} }
};
const handlePaginationClick = (index) => { if (swiper.isEnd) {
setActiveIndex(index); nextButton.style.display = 'none'; // 隐藏右侧按钮
if (swiper) { } else {
swiper.slideTo(index); nextButton.style.display = 'block'; // 显示右侧按钮
} }
}; };
// 默认配置
const _JessibucaObj = {
operateBtns: {
screenshot: false,
},
loadingText: '视频加载中',
decoder: '/JessibucaVideo/decoder.js',
...JessibucaObj,
};
return ( return (
<Modal <Modal
footer={null} footer={null}
...@@ -51,45 +39,37 @@ const VideoSliderModal = (props) => { ...@@ -51,45 +39,37 @@ const VideoSliderModal = (props) => {
getContainer={document.body} getContainer={document.body}
destroyOnClose destroyOnClose
> >
<Swiper <>
onSwiper={setSwiper} {videoInfos.length === 1 ? (
slidesPerView={1} videoInfos.map((item, index) => <VmsVideo VideoInfo={item} JessibucaObj={JessibucaObj} />)
spaceBetween={0} ) : (
pagination={{ <>
clickable: true, <Swiper
}} slidesPerView={1}
loop spaceBetween={0}
lazy initialSlide={0}
virtual pagination={{
onActiveIndexChange={(e) => { clickable: true,
setActiveIndex(e.activeIndex); }}
}} lazy
navigation virtual
> navigation
{videoInfos.map((item, index) => ( onSlideChange={(swiper) => handleSlideChange(swiper)}
<SwiperSlide key={index}> >
<div className={styles['swiper-wrap']}> {videoInfos.map((item, index) => (
<div className={styles['swiper-title']}>{item.name}</div> <SwiperSlide key={index}>
<div className={styles['swiper-content']}> <div className={styles['swiper-wrap']}>
<VmsVideo VideoInfo={item} JessibucaObj={_JessibucaObj} /> <div className={styles['swiper-title']}>{item.name}</div>
</div> <div className={styles['swiper-content']}>
</div> <VmsVideo VideoInfo={item} JessibucaObj={JessibucaObj} />
</SwiperSlide> </div>
))} </div>
</Swiper> </SwiperSlide>
))}
<div className={styles['swiper-dots-wrap']}> </Swiper>
<Space size={16}> </>
{videoInfos.map((video, index) => ( )}
<div </>
className={styles['swiper-dots']}
key={index}
onClick={() => handlePaginationClick(index)}
style={{ background: activeIndex === index ? '#007aff' : '#919090' }}
/>
))}
</Space>
</div>
</Modal> </Modal>
); );
}; };
......
...@@ -29,23 +29,4 @@ ...@@ -29,23 +29,4 @@
flex: 1; flex: 1;
} }
} }
.swiper-dots-wrap {
position: absolute;
bottom: 8px;
left: 0;
z-index: 1;
display: flex;
align-items: center;
justify-content: center;
width: 100%;
height: 22px;
.swiper-dots {
width: 8px;
height: 8px;
background: #919090;
border-radius: 50%;
}
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment