import { Card, Space, CardProps, Spin, Button } from 'antd'; import { theme } from 'antd/lib'; import { VideoPlayer, type VideoViewRef } from '@zhst/meta'; import React, { useState, useEffect, ReactNode, useRef } from 'react'; import { CloseOutlined, LoadingOutlined } from '@ant-design/icons'; import './index.less' export interface VideoPlayerCardProps { windowKey?: string; selectedWindowKey?: string; showType?: 'video' | "image"; imgSrc?: string; videoSrc?: string; cardProps?: CardProps; errorReasonText?: string; isWindowLoading?: boolean; size?: 'large' | 'small'; title?: string | ReactNode handleCloseButtonClick?: (key?: string) => void; handleWindowClick?: (key?: string) => void; } export const VideoPlayerCard: React.FC = (props) => { const componentName = `zhst-biz-video-player-card`; const { showType, imgSrc, videoSrc, cardProps, isWindowLoading, errorReasonText, size, title, handleCloseButtonClick, handleWindowClick, windowKey, selectedWindowKey = '' } = props; const [cardContent, setCardContent] = useState(null); const { useToken } = theme const { token } = useToken() const videoRef = useRef(null) const selectedBorderStyle = { border: `2px solid ${token.colorPrimary}`, boxShadow: " 0px 2px 9px 0px rgba(0,0,0,0.16)" } const cardStyle: React.CSSProperties = { ...(size === 'large' ? { height: 931 } : { height: 456, cursor: 'pointer' }), ...(size === 'small' && selectedWindowKey === windowKey ? selectedBorderStyle : {}) }; const videoPlayerCardStyle = size === 'small' ? { width: "calc(50% - 20px)" } : { flex: 1 } useEffect(() => { if (!isWindowLoading && (videoSrc || imgSrc)) { let contentElement: JSX.Element | null = null; if (videoSrc) { contentElement = ( ); videoRef.current?.setShowCrop(true) } else if (imgSrc) { contentElement = ( 首帧图 ); } setCardContent(contentElement); } else { setCardContent(null) } }, [showType, imgSrc, videoSrc, isWindowLoading]); return (
{ handleWindowClick?.(windowKey) }} style={videoPlayerCardStyle}>
{title}
} style={{ display: "flex", flexDirection: "column", borderRadius: 4, overflow: "hidden", ...cardStyle }} bodyStyle={{ flex: 1 }} {...cardProps} > {cardContent ? ( <> {cardContent} ) : (
{ isWindowLoading ?
} />
: !!errorReasonText && {errorReasonText} }
)} {/* 其他内容 */}
); }; export default VideoPlayerCard;