index.js 2.84 KB
Newer Older
1
import VmsVideo from '@wisdom-components/VmsVideo';
刘梦焕's avatar
刘梦焕 committed
2 3
import { Modal } from 'antd';
import React from 'react';
4 5 6 7 8 9 10 11 12 13
import SwiperCore, { Autoplay, Lazy, Navigation, Pagination, Virtual } from 'swiper';
import { Swiper, SwiperSlide } from 'swiper/react';
import 'swiper/swiper.min.css';
import styles from './index.less';

SwiperCore.use([Virtual, Navigation, Lazy, Autoplay, Pagination]);

const VideoSliderModal = (props) => {
  const { modalInfo, videoInfos, JessibucaObj } = props;

刘梦焕's avatar
刘梦焕 committed
14 15 16 17 18 19 20 21
  // 切换轮播页 控制按钮是否显示
  const handleSlideChange = (swiper) => {
    const nextButton = document.querySelector('.swiper-button-next');
    const prevButton = document.querySelector('.swiper-button-prev');
    if (swiper.isBeginning) {
      prevButton.style.display = 'none'; // 隐藏左侧按钮
    } else {
      prevButton.style.display = 'block'; // 显示左侧按钮
22 23
    }

刘梦焕's avatar
刘梦焕 committed
24 25 26 27
    if (swiper.isEnd) {
      nextButton.style.display = 'none'; // 隐藏右侧按钮
    } else {
      nextButton.style.display = 'block'; // 显示右侧按钮
28 29 30 31 32 33
    }
  };

  return (
    <Modal
      footer={null}
34 35
      width={1000}
      title="视频预览"
36 37 38
      {...modalInfo}
      wrapClassName={styles['video-carousel-modal']}
      bodyStyle={{ padding: 0 }}
39 40
      getContainer={document.body}
      destroyOnClose
41
    >
刘梦焕's avatar
刘梦焕 committed
42 43
      <>
        {videoInfos.length === 1 ? (
44 45 46 47
          videoInfos.map((item, index) => (
            <div className={styles['swiper-wrap']} key={index}>
              <div className={styles['swiper-title']}>{item.name}</div>
              <div className={styles['swiper-content']}>
48 49 50 51
                <VmsVideo
                  VideoInfo={{ ...item, width: modalInfo?.width ?? 1000, height: 500 }}
                  JessibucaObj={JessibucaObj}
                />
52 53 54
              </div>
            </div>
          ))
刘梦焕's avatar
刘梦焕 committed
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
        ) : (
          <>
            <Swiper
              slidesPerView={1}
              spaceBetween={0}
              initialSlide={0}
              pagination={{
                clickable: true,
              }}
              lazy
              virtual
              navigation
              onSlideChange={(swiper) => handleSlideChange(swiper)}
            >
              {videoInfos.map((item, index) => (
                <SwiperSlide key={index}>
                  <div className={styles['swiper-wrap']}>
                    <div className={styles['swiper-title']}>{item.name}</div>
                    <div className={styles['swiper-content']}>
74 75 76 77
                      <VmsVideo
                        VideoInfo={{ ...item, width: modalInfo?.width ?? 1000, height: 500 }}
                        JessibucaObj={JessibucaObj}
                      />
刘梦焕's avatar
刘梦焕 committed
78 79 80 81 82 83 84 85
                    </div>
                  </div>
                </SwiperSlide>
              ))}
            </Swiper>
          </>
        )}
      </>
86 87 88 89 90
    </Modal>
  );
};

export default VideoSliderModal;