videoNews.tsx 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. import React, { useState } from "react"
  2. import style from './index.less'
  3. import { Image, ImageProps, Modal } from 'antd'
  4. import { getVideoImgUrl } from "@/utils/utils"
  5. import play from "../../../../../public/image/play.png"
  6. import { CloseOutlined } from '@ant-design/icons';
  7. import './index1.less'
  8. interface Props extends ImageProps {
  9. maskBodyStyle?: React.CSSProperties
  10. maskImgStyle?: React.CSSProperties
  11. }
  12. const VideoNews: React.FC<Props> = ({ preview = false, src, maskBodyStyle, maskImgStyle, ...data }) => {
  13. /*****************************/
  14. const [toPlay, setToPlay] = useState<boolean>(false)
  15. /*****************************/
  16. return <>
  17. <div className={`${style.imgNews} imgNews`}>
  18. <Image src={src ? getVideoImgUrl(src) : 'error'} preview={false} {...data} className={style.img}/>
  19. <div className={style.mask} style={maskBodyStyle}>
  20. <img src={play} style={maskImgStyle} onClick={(e) => { e.stopPropagation(); e.preventDefault(); setToPlay(true) }} />
  21. </div>
  22. </div>
  23. {toPlay && <Modal
  24. open={toPlay}
  25. bodyStyle={{ backgroundColor: 'rgba(0,0,0,0.8)', overflow: 'hidden', borderRadius: 6 }}
  26. footer={null}
  27. closeIcon={<CloseOutlined style={{ color: '#FFF' }}/>}
  28. onCancel={(e) => {e.stopPropagation(); setToPlay(false)}}
  29. >
  30. <video className={style.video} style={{ borderRadius: 6 }} src={src} autoPlay controls>您的浏览器不支持 video 标签。</video>
  31. </Modal>}
  32. </>
  33. }
  34. export default React.memo(VideoNews)