|  |  | @ -19,20 +19,23 @@ const MAX_FILE_SIZE = 200 | 
			
		
	
		
		
			
				
					
					|  |  |  | let noUploads = true |  |  |  | let noUploads = true | 
			
		
	
		
		
			
				
					
					|  |  |  | function VideoUploadList (props) { |  |  |  | function VideoUploadList (props) { | 
			
		
	
		
		
			
				
					
					|  |  |  |      |  |  |  |      | 
			
		
	
		
		
			
				
					
					|  |  |  |     // const [videoes, setVideoes] = useState([]);
 |  |  |  |     // const [videos, setvideos] = useState([]);
 | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |     const [state, dispatch] = useReducer(reducer, initialState); |  |  |  |     const [state, dispatch] = useReducer(reducer, initialState); | 
			
		
	
		
		
			
				
					
					|  |  |  |     const theme = useContext(ThemeContext) |  |  |  |     const theme = useContext(ThemeContext) | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |     useEffect(() => { |  |  |  |     useEffect(() => { | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         // Chrome removed support for custom message in ver 51
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         // https://stackoverflow.com/questions/38879742/is-it-possible-to-display-a-custom-message-in-the-beforeunload-popup
 | 
			
		
	
		
		
			
				
					
					|  |  |  |         window.addEventListener("beforeunload", beforeunload); |  |  |  |         window.addEventListener("beforeunload", beforeunload); | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  |         // window.onbeforeunload = beforeunload
 | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |         return () => { |  |  |  |         return () => { | 
			
		
	
		
		
			
				
					
					|  |  |  |             uploader = null; |  |  |  |             uploader = null; | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             // window.onbeforeunload = null;
 | 
			
		
	
		
		
			
				
					
					|  |  |  |             window.removeEventListener("beforeunload", beforeunload); |  |  |  |             window.removeEventListener("beforeunload", beforeunload); | 
			
		
	
		
		
			
				
					
					|  |  |  |         } |  |  |  |         } | 
			
		
	
		
		
			
				
					
					|  |  |  |     }, []) |  |  |  |     }, []) | 
			
		
	
		
		
			
				
					
					|  |  |  |     // TODO 闭包!
 |  |  |  |     // TODO 闭包!
 | 
			
		
	
		
		
			
				
					
					|  |  |  |     noUploads = (!state.videoes || state.videoes.length == 0); |  |  |  |     noUploads = (!state.videos || state.videos.length == 0); | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |     function beforeunload(e) { |  |  |  |     function beforeunload(e) { | 
			
		
	
		
		
			
				
					
					|  |  |  |         if (noUploads) { |  |  |  |         if (noUploads) { | 
			
		
	
		
		
			
				
					
					|  |  |  |             return true; |  |  |  |             return true; | 
			
		
	
	
		
		
			
				
					|  |  | @ -62,7 +65,7 @@ function VideoUploadList (props) { | 
			
		
	
		
		
			
				
					
					|  |  |  |             return; |  |  |  |             return; | 
			
		
	
		
		
			
				
					
					|  |  |  |         } |  |  |  |         } | 
			
		
	
		
		
			
				
					
					|  |  |  |         let gotTheSameFileName = false; |  |  |  |         let gotTheSameFileName = false; | 
			
		
	
		
		
			
				
					
					|  |  |  |         state.videoes.some((item) => { |  |  |  |         state.videos.some((item) => { | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |             if (item.name == file.name) { |  |  |  |             if (item.name == file.name) { | 
			
		
	
		
		
			
				
					
					|  |  |  |                 gotTheSameFileName = true; |  |  |  |                 gotTheSameFileName = true; | 
			
		
	
		
		
			
				
					
					|  |  |  |                 return true; |  |  |  |                 return true; | 
			
		
	
	
		
		
			
				
					|  |  | @ -86,7 +89,7 @@ function VideoUploadList (props) { | 
			
		
	
		
		
			
				
					
					|  |  |  |                 addFileSuccess: (uploadInfo) => { |  |  |  |                 addFileSuccess: (uploadInfo) => { | 
			
		
	
		
		
			
				
					
					|  |  |  |                     const file = uploadInfo.file |  |  |  |                     const file = uploadInfo.file | 
			
		
	
		
		
			
				
					
					|  |  |  |                     console.log('addFileSuccess', uploadInfo) |  |  |  |                     console.log('addFileSuccess', uploadInfo) | 
			
		
	
		
		
			
				
					
					|  |  |  |                     // const newVideoes = [...videoes, {
 |  |  |  |                     // const newvideos = [...videos, {
 | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |                     //     name: file.name,
 |  |  |  |                     //     name: file.name,
 | 
			
		
	
		
		
			
				
					
					|  |  |  |                     //     size: file.size,
 |  |  |  |                     //     size: file.size,
 | 
			
		
	
		
		
			
				
					
					|  |  |  |                     //     type: file.type,
 |  |  |  |                     //     type: file.type,
 | 
			
		
	
	
		
		
			
				
					|  |  | @ -96,7 +99,7 @@ function VideoUploadList (props) { | 
			
		
	
		
		
			
				
					
					|  |  |  |                     //     videoId: uploadInfo.videoId, //   "719b82c875c34ac39f94feb145d25ad2"
 |  |  |  |                     //     videoId: uploadInfo.videoId, //   "719b82c875c34ac39f94feb145d25ad2"
 | 
			
		
	
		
		
			
				
					
					|  |  |  |                     //     loaded: 0
 |  |  |  |                     //     loaded: 0
 | 
			
		
	
		
		
			
				
					
					|  |  |  |                     // }]
 |  |  |  |                     // }]
 | 
			
		
	
		
		
			
				
					
					|  |  |  |                     // setVideoes(newVideoes)
 |  |  |  |                     // setvideos(newvideos)
 | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |                     // files.push(file)
 |  |  |  |                     // files.push(file)
 | 
			
		
	
		
		
			
				
					
					|  |  |  |                     clearInput() |  |  |  |                     clearInput() | 
			
		
	
	
		
		
			
				
					|  |  | @ -107,7 +110,7 @@ function VideoUploadList (props) { | 
			
		
	
		
		
			
				
					
					|  |  |  |                     var progressPercent = Math.ceil(progress * 100) |  |  |  |                     var progressPercent = Math.ceil(progress * 100) | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |                     // let _index = -1;
 |  |  |  |                     // let _index = -1;
 | 
			
		
	
		
		
			
				
					
					|  |  |  |                     // videoes.some((item, index) => {
 |  |  |  |                     // videos.some((item, index) => {
 | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |                     //     // addFileSuccess的时候没有fileHash
 |  |  |  |                     //     // addFileSuccess的时候没有fileHash
 | 
			
		
	
		
		
			
				
					
					|  |  |  |                     //     // if (uploadInfo.fileHash == item.fileHash) {
 |  |  |  |                     //     // if (uploadInfo.fileHash == item.fileHash) {
 | 
			
		
	
		
		
			
				
					
					|  |  |  |                     //     if (uploadInfo.file.name == item.name) {
 |  |  |  |                     //     if (uploadInfo.file.name == item.name) {
 | 
			
		
	
	
		
		
			
				
					|  |  | @ -119,7 +122,7 @@ function VideoUploadList (props) { | 
			
		
	
		
		
			
				
					
					|  |  |  |                     // TODO 这里不用reducer,会出现state被重置的问题
 |  |  |  |                     // TODO 这里不用reducer,会出现state被重置的问题
 | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |                     // if (_index == -1) {
 |  |  |  |                     // if (_index == -1) {
 | 
			
		
	
		
		
			
				
					
					|  |  |  |                     //     const newVideoes = [...videoes, {
 |  |  |  |                     //     const newvideos = [...videos, {
 | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |                     //         name: file.name,
 |  |  |  |                     //         name: file.name,
 | 
			
		
	
		
		
			
				
					
					|  |  |  |                     //         size: file.size,
 |  |  |  |                     //         size: file.size,
 | 
			
		
	
		
		
			
				
					
					|  |  |  |                     //         type: file.type,
 |  |  |  |                     //         type: file.type,
 | 
			
		
	
	
		
		
			
				
					|  |  | @ -129,12 +132,12 @@ function VideoUploadList (props) { | 
			
		
	
		
		
			
				
					
					|  |  |  |                     //         videoId: uploadInfo.videoId, //   "719b82c875c34ac39f94feb145d25ad2"
 |  |  |  |                     //         videoId: uploadInfo.videoId, //   "719b82c875c34ac39f94feb145d25ad2"
 | 
			
		
	
		
		
			
				
					
					|  |  |  |                     //         loaded: progressPercent
 |  |  |  |                     //         loaded: progressPercent
 | 
			
		
	
		
		
			
				
					
					|  |  |  |                     //     }]
 |  |  |  |                     //     }]
 | 
			
		
	
		
		
			
				
					
					|  |  |  |                     //     setVideoes(newVideoes)
 |  |  |  |                     //     setvideos(newvideos)
 | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |                     //     return;
 |  |  |  |                     //     return;
 | 
			
		
	
		
		
			
				
					
					|  |  |  |                     // }
 |  |  |  |                     // }
 | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |                     // //           exercise_questions : update(prevState.exercise_questions, {[index]: { isNew: {$set: false}}})
 |  |  |  |                     // //           exercise_questions : update(prevState.exercise_questions, {[index]: { isNew: {$set: false}}})
 | 
			
		
	
		
		
			
				
					
					|  |  |  |                     // setVideoes(update(videoes, {[_index]: { loaded: {$set: progressPercent}}}))
 |  |  |  |                     // setvideos(update(videos, {[_index]: { loaded: {$set: progressPercent}}}))
 | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |                     dispatch({type: 'updateProgress', uploadInfo, progressPercent}) |  |  |  |                     dispatch({type: 'updateProgress', uploadInfo, progressPercent}) | 
			
		
	
		
		
			
				
					
					|  |  |  |                 }, |  |  |  |                 }, | 
			
		
	
	
		
		
			
				
					|  |  | @ -179,14 +182,14 @@ function VideoUploadList (props) { | 
			
		
	
		
		
			
				
					
					|  |  |  |         uploader.deleteFile(index) |  |  |  |         uploader.deleteFile(index) | 
			
		
	
		
		
			
				
					
					|  |  |  |         if (isSuccess) { |  |  |  |         if (isSuccess) { | 
			
		
	
		
		
			
				
					
					|  |  |  |             // uploader.deleteFile(index)
 |  |  |  |             // uploader.deleteFile(index)
 | 
			
		
	
		
		
			
				
					
					|  |  |  |             // deleteVideoInCloud(username, state.videoes[index].videoId)
 |  |  |  |             // deleteVideoInCloud(username, state.videos[index].videoId)
 | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |         } else { |  |  |  |         } else { | 
			
		
	
		
		
			
				
					
					|  |  |  |             // uploader.cancelFile(index)
 |  |  |  |             // uploader.cancelFile(index)
 | 
			
		
	
		
		
			
				
					
					|  |  |  |         } |  |  |  |         } | 
			
		
	
		
		
			
				
					
					|  |  |  |              |  |  |  |              | 
			
		
	
		
		
			
				
					
					|  |  |  |         clearInput() |  |  |  |         clearInput() | 
			
		
	
		
		
			
				
					
					|  |  |  |         dispatch({type: 'removeVideo', index})  |  |  |  |         dispatch({type: 'removeVideo', index})  | 
			
		
	
		
		
			
				
					
					|  |  |  |         // setVideoes([...videoes.splice(index, 1)])
 |  |  |  |         // setvideos([...videos.splice(index, 1)])
 | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |     } |  |  |  |     } | 
			
		
	
		
		
			
				
					
					|  |  |  |     //  uploader.deleteFile(index);
 |  |  |  |     //  uploader.deleteFile(index);
 | 
			
		
	
		
		
			
				
					
					|  |  |  |     function cancelUpload(index, isSuccess) { |  |  |  |     function cancelUpload(index, isSuccess) { | 
			
		
	
	
		
		
			
				
					|  |  | @ -201,13 +204,13 @@ function VideoUploadList (props) { | 
			
		
	
		
		
			
				
					
					|  |  |  |          |  |  |  |          | 
			
		
	
		
		
			
				
					
					|  |  |  |     } |  |  |  |     } | 
			
		
	
		
		
			
				
					
					|  |  |  |     function onPublish() { |  |  |  |     function onPublish() { | 
			
		
	
		
		
			
				
					
					|  |  |  |         if (state.videoes.length == 0) { |  |  |  |         if (state.videos.length == 0) { | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |             showNotification('请先上传视频') |  |  |  |             showNotification('请先上传视频') | 
			
		
	
		
		
			
				
					
					|  |  |  |             return; |  |  |  |             return; | 
			
		
	
		
		
			
				
					
					|  |  |  |         } |  |  |  |         } | 
			
		
	
		
		
			
				
					
					|  |  |  |         const publishUrl = `/users/${username}/videos/batch_publish.json` |  |  |  |         const publishUrl = `/users/${username}/videos/batch_publish.json` | 
			
		
	
		
		
			
				
					
					|  |  |  |         axios.post(publishUrl, { |  |  |  |         axios.post(publishUrl, { | 
			
		
	
		
		
			
				
					
					|  |  |  |             videos: state.videoes.map(item => { |  |  |  |             videos: state.videos.map(item => { | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |                 return { |  |  |  |                 return { | 
			
		
	
		
		
			
				
					
					|  |  |  |                     video_id: item.videoId, |  |  |  |                     video_id: item.videoId, | 
			
		
	
		
		
			
				
					
					|  |  |  |                     // todo
 |  |  |  |                     // todo
 | 
			
		
	
	
		
		
			
				
					|  |  | @ -217,7 +220,7 @@ function VideoUploadList (props) { | 
			
		
	
		
		
			
				
					
					|  |  |  |         }).then((response) => { |  |  |  |         }).then((response) => { | 
			
		
	
		
		
			
				
					
					|  |  |  |            // to success page
 |  |  |  |            // to success page
 | 
			
		
	
		
		
			
				
					
					|  |  |  |            if (response.data.status == 0) { |  |  |  |            if (response.data.status == 0) { | 
			
		
	
		
		
			
				
					
					|  |  |  |                history.push(`/users/${username}/videoes/success`) |  |  |  |                history.push(`/users/${username}/videos/success`) | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |            } |  |  |  |            } | 
			
		
	
		
		
			
				
					
					|  |  |  |         }).catch((error) => { |  |  |  |         }).catch((error) => { | 
			
		
	
		
		
			
				
					
					|  |  |  |             console.log(error) |  |  |  |             console.log(error) | 
			
		
	
	
		
		
			
				
					|  |  | @ -334,7 +337,7 @@ function VideoUploadList (props) { | 
			
		
	
		
		
			
				
					
					|  |  |  |                 className="mb26" |  |  |  |                 className="mb26" | 
			
		
	
		
		
			
				
					
					|  |  |  |                 separator=" > " |  |  |  |                 separator=" > " | 
			
		
	
		
		
			
				
					
					|  |  |  |                 items={[ |  |  |  |                 items={[ | 
			
		
	
		
		
			
				
					
					|  |  |  |                     { to: `/users/${username}/videoes`, name:  '视频'}, |  |  |  |                     { to: `/users/${username}/videos`, name:  '视频'}, | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |                     { name: '上传'} |  |  |  |                     { name: '上传'} | 
			
		
	
		
		
			
				
					
					|  |  |  |                 ]} |  |  |  |                 ]} | 
			
		
	
		
		
			
				
					
					|  |  |  |             ></CBreadcrumb> |  |  |  |             ></CBreadcrumb> | 
			
		
	
	
		
		
			
				
					|  |  | @ -363,7 +366,7 @@ function VideoUploadList (props) { | 
			
		
	
		
		
			
				
					
					|  |  |  |                 </div>} |  |  |  |                 </div>} | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |                 <div> |  |  |  |                 <div> | 
			
		
	
		
		
			
				
					
					|  |  |  |                 {state.videoes.map((item, vIndex) => { |  |  |  |                 {state.videos.map((item, vIndex) => { | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |                     return ( |  |  |  |                     return ( | 
			
		
	
		
		
			
				
					
					|  |  |  |                         <VideoUpload {...props} {...item} className="" |  |  |  |                         <VideoUpload {...props} {...item} className="" | 
			
		
	
		
		
			
				
					
					|  |  |  |                             cancelUpload={cancelUpload} |  |  |  |                             cancelUpload={cancelUpload} | 
			
		
	
	
		
		
			
				
					|  |  | @ -374,13 +377,13 @@ function VideoUploadList (props) { | 
			
		
	
		
		
			
				
					
					|  |  |  |                     ) |  |  |  |                     ) | 
			
		
	
		
		
			
				
					
					|  |  |  |                 })} |  |  |  |                 })} | 
			
		
	
		
		
			
				
					
					|  |  |  |                 </div> |  |  |  |                 </div> | 
			
		
	
		
		
			
				
					
					|  |  |  |                 {state.videoes && state.videoes.length === MAX_FILE_COUNT &&  |  |  |  |                 {state.videos && state.videos.length === MAX_FILE_COUNT &&  | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |                 <div className="uploadTip"> |  |  |  |                 <div className="uploadTip"> | 
			
		
	
		
		
			
				
					
					|  |  |  |                     <i className="iconfont icon-tishi" style={{color: '#FF6F6F', verticalAlign: 'text-bottom'}}></i> |  |  |  |                     <i className="iconfont icon-tishi" style={{color: '#FF6F6F', verticalAlign: 'text-bottom'}}></i> | 
			
		
	
		
		
			
				
					
					|  |  |  |                     <span>单次最多支持3个视频文件上传</span>  |  |  |  |                     <span>单次最多支持3个视频文件上传</span>  | 
			
		
	
		
		
			
				
					
					|  |  |  |                 </div>} |  |  |  |                 </div>} | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |                 {(!noUploads && state.videoes.length < MAX_FILE_COUNT) && <ActionBtn className="publishBtn" onClick={() => document.getElementById('fileUpload').click()} |  |  |  |                 {(!noUploads && state.videos.length < MAX_FILE_COUNT) && <ActionBtn className="publishBtn" onClick={() => document.getElementById('fileUpload').click()} | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |                 >继续添加</ActionBtn>} |  |  |  |                 >继续添加</ActionBtn>} | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |                 <div className={`description ${noUploads ? 'noUploads' : ''}`}> |  |  |  |                 <div className={`description ${noUploads ? 'noUploads' : ''}`}> | 
			
		
	
	
		
		
			
				
					|  |  | @ -391,7 +394,7 @@ function VideoUploadList (props) { | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |                 {!noUploads && <React.Fragment> |  |  |  |                 {!noUploads && <React.Fragment> | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |                 {/* {(state.videoes.length < MAX_FILE_COUNT) && <Button type="primary" icon="plus-square" |  |  |  |                 {/* {(state.videos.length < MAX_FILE_COUNT) && <Button type="primary" icon="plus-square" | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |                     onClick={() => { document.getElementById('fileUpload').click()}} |  |  |  |                     onClick={() => { document.getElementById('fileUpload').click()}} | 
			
		
	
		
		
			
				
					
					|  |  |  |                     className="fr addVideoBtn" |  |  |  |                     className="fr addVideoBtn" | 
			
		
	
		
		
			
				
					
					|  |  |  |                 > |  |  |  |                 > | 
			
		
	
	
		
		
			
				
					|  |  | 
 |