diff --git a/src/compenents/upload-video-button/index.tsx b/src/compenents/upload-video-button/index.tsx index ffbcc27..9174393 100644 --- a/src/compenents/upload-video-button/index.tsx +++ b/src/compenents/upload-video-button/index.tsx @@ -42,9 +42,9 @@ interface FileItem { export const UploadVideoButton = (props: PropsInterface) => { const [showModal, setShowModal] = useState(false); - const [loading, setLoading] = useState(false); const localFileList = useRef([]); const [fileList, setFileList] = useState([]); + const upRef = useRef(0); const getMinioUploadId = async () => { let resp: any = await minioUploadId("mp4"); @@ -55,7 +55,7 @@ export const UploadVideoButton = (props: PropsInterface) => { multiple: true, beforeUpload: async (file: File) => { if (file.type === "video/mp4") { - setLoading(true); + upRef.current++; // 视频封面解析 || 视频时长解析 let videoInfo = await parseVideo(file); // 添加到本地待上传 @@ -93,7 +93,7 @@ export const UploadVideoButton = (props: PropsInterface) => { item.isSuc = true; setFileList([...localFileList.current]); message.success(`${item.file.name} 上传成功`); - setLoading(false); + upRef.current--; }); }); item.run.on("retry", () => { @@ -109,7 +109,7 @@ export const UploadVideoButton = (props: PropsInterface) => { item.isErr = true; item.errMsg = msg; setFileList([...localFileList.current]); - setLoading(false); + upRef.current--; }); setTimeout(() => { item.run.start(); @@ -124,12 +124,13 @@ export const UploadVideoButton = (props: PropsInterface) => { }; const closeWin = () => { - if (loading) { + if (upRef.current > 0) { message.error(`等待上传成功后才能关闭`); return; } setShowModal(false); setFileList([]); + localFileList.current = []; props.onUpdate(); };