import React, { useRef } from 'react'; import { Button } from 'tdesign-mobile-react'; import { X } from 'lucide-react'; import { uploadImage } from '@/api/upload'; interface UploadVideoProps { value?: string; onChange?: (url: string) => void; accept?: string; disabled?: boolean; } const VIDEO_BOX_CLASS = 'relative flex items-center justify-center w-full aspect-[16/9] rounded-2xl border-2 border-dashed border-blue-300 bg-gray-50 overflow-hidden'; const UploadVideo: React.FC = ({ value, onChange, accept = 'video/mp4,video/webm,video/ogg,video/quicktime,video/x-msvideo,video/x-ms-wmv,video/x-flv,video/x-matroska', disabled, }) => { const inputRef = useRef(null); // 选择文件并上传 const handleFileChange = async (e: React.ChangeEvent) => { const file = e.target.files?.[0]; if (!file) return; try { const url = await uploadImage(file); onChange?.(url); } catch (err: any) { alert(err?.message || '上传失败'); } finally { if (inputRef.current) inputRef.current.value = ''; } }; // 触发文件选择 const handleClick = () => { if (!disabled) inputRef.current?.click(); }; // 删除视频 const handleDelete = () => { onChange?.(''); }; return (
{!value ? (
) : (
)}
); }; export default UploadVideo;