index.tsx 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. import React, { useRef, useState } from "react";
  2. import styles from "./index.module.scss";
  3. import { Swiper, SwiperSlide } from 'swiper/react'
  4. import 'media-chrome';
  5. import 'swiper/css'
  6. import 'swiper/css/effect-coverflow'
  7. import 'swiper/css/pagination'
  8. import 'swiper/css/navigation'
  9. import { EffectCoverflow, Pagination, Navigation } from 'swiper/modules'
  10. function VideoList({ style }: { style?: React.CSSProperties }) {
  11. const swiperRef = useRef<any>(null);
  12. const [isModalOpen, setIsModalOpen] = useState(false);
  13. const [currentVideoSrc, setCurrentVideoSrc] = useState('/myData/video/bgVideo.mp4');
  14. const modalVideoRef = useRef<HTMLVideoElement>(null);
  15. const handleVideoClick = (src: string) => {
  16. setCurrentVideoSrc(src);
  17. setIsModalOpen(true);
  18. setTimeout(() => {
  19. if (modalVideoRef.current) {
  20. modalVideoRef.current.play();
  21. }
  22. }, 0);
  23. };
  24. const handleCloseModal = () => {
  25. setIsModalOpen(false);
  26. if (modalVideoRef.current) {
  27. modalVideoRef.current.pause();
  28. }
  29. };
  30. return (
  31. <div className={styles.VideoList} style={style}>
  32. <div className="name">视频名称</div>
  33. <Swiper
  34. ref={swiperRef}
  35. loop={true}
  36. loopPreventsSliding={false}
  37. effect={'coverflow'}
  38. grabCursor={true}
  39. centeredSlides={true}
  40. slidesPerView={'1'}
  41. coverflowEffect={{
  42. rotate: 0,
  43. stretch: 30,
  44. depth: 180,
  45. modifier: 4,
  46. }}
  47. pagination={{ el: '.swiper-pagination', clickable: true }}
  48. modules={[EffectCoverflow, Pagination, Navigation]}
  49. className='swiper_container'
  50. // onTransitionEnd={(swiper: unknown) => {
  51. // const swiperInternal = swiper as { loopFix: () => void }
  52. // swiperInternal.loopFix()
  53. // }}
  54. >
  55. {[1, 2, 3, 4, 5, 6, 7, 8].map((item: any, index: any) => (
  56. <SwiperSlide key={index}>
  57. <div
  58. className='itemCard'
  59. key={index}
  60. onClick={() => handleVideoClick('/myData/video/bgVideo.mp4')}
  61. >
  62. <div className='itemImage'>
  63. <video
  64. src='/myData/video/bgVideo.mp4'
  65. preload="metadata"
  66. />
  67. </div>
  68. </div>
  69. </SwiperSlide>
  70. ))}
  71. </Swiper>
  72. <div className="swiper-pagination"></div>
  73. <div className={`videoModal ${isModalOpen ? 'active' : ''}`}>
  74. <div className="content">
  75. <media-controller class="custom-media-controller">
  76. <video
  77. ref={modalVideoRef}
  78. slot="media"
  79. src={currentVideoSrc}
  80. className="modal-video"
  81. ></video>
  82. <media-control-bar>
  83. <media-play-button></media-play-button>
  84. <div className="progress">
  85. <media-time-range></media-time-range>
  86. <div className="time">
  87. <media-time-display></media-time-display>
  88. <media-duration-display></media-duration-display>
  89. </div>
  90. </div>
  91. </media-control-bar>
  92. </media-controller>
  93. </div>
  94. <div className="close" onClick={handleCloseModal}>
  95. <img src={require('@/assets/img/close.png')} alt='关闭' />
  96. </div>
  97. </div>
  98. </div>
  99. )
  100. }
  101. const MemoVideoList = React.memo(VideoList);
  102. export default MemoVideoList;