|
|
|
@ -1,6 +1,6 @@
|
|
|
|
|
import React, { useState, useEffect, useReducer, memo } from 'react';
|
|
|
|
|
|
|
|
|
|
import { getUrl2, isDev, CBreadcrumb } from 'educoder'
|
|
|
|
|
import { getUrl2, isDev, CBreadcrumb, ActionBtn } from 'educoder'
|
|
|
|
|
import axios from 'axios'
|
|
|
|
|
|
|
|
|
|
import VideoUpload from './VideoUpload'
|
|
|
|
@ -15,6 +15,7 @@ function VideoUploadList (props) {
|
|
|
|
|
|
|
|
|
|
const [videoes, setVideoes] = useState([]);
|
|
|
|
|
const [state, dispatch] = useReducer(reducer, initialState);
|
|
|
|
|
const username = props.match.params.username
|
|
|
|
|
|
|
|
|
|
const uploaderOptions = {
|
|
|
|
|
|
|
|
|
@ -49,7 +50,7 @@ function VideoUploadList (props) {
|
|
|
|
|
// }]
|
|
|
|
|
// setVideoes(newVideoes)
|
|
|
|
|
|
|
|
|
|
files.push(file)
|
|
|
|
|
// files.push(file)
|
|
|
|
|
|
|
|
|
|
dispatch({type: 'addVideo', uploadInfo})
|
|
|
|
|
},
|
|
|
|
@ -98,6 +99,9 @@ function VideoUploadList (props) {
|
|
|
|
|
onUploadSucceed: (uploadInfo) => {
|
|
|
|
|
console.log('onUploadSucceed', uploadInfo)
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
onUploadError: (uploadInfo) => {
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
// 可能需要等lib加载完毕才能执行
|
|
|
|
|
gotUploader: (_uploader) => {
|
|
|
|
@ -116,15 +120,44 @@ function VideoUploadList (props) {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// uploader.deleteFile(index);
|
|
|
|
|
function cancelUpload(index) {
|
|
|
|
|
function cancelUpload(index, isSuccess) {
|
|
|
|
|
// 确定取消?
|
|
|
|
|
setVideoes([...videoes.splice(index, 1)])
|
|
|
|
|
const file = files[index]
|
|
|
|
|
uploader.cancelFile(file)
|
|
|
|
|
files.splice(index, 1)
|
|
|
|
|
|
|
|
|
|
// const file = files[index]
|
|
|
|
|
if (isSuccess) {
|
|
|
|
|
uploader.deleteFile(index)
|
|
|
|
|
} else {
|
|
|
|
|
uploader.cancelFile(index)
|
|
|
|
|
}
|
|
|
|
|
// files.splice(index, 1)
|
|
|
|
|
|
|
|
|
|
dispatch({type: 'removeVideo', index})
|
|
|
|
|
// setVideoes([...videoes.splice(index, 1)])
|
|
|
|
|
}
|
|
|
|
|
function onPublish() {
|
|
|
|
|
if (state.videoes.length == 0) {
|
|
|
|
|
this.props.showNotification('请先上传视频')
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
const publishUrl = `/users/${username}/videos/batch_publish.json`
|
|
|
|
|
axios.post(publishUrl, {
|
|
|
|
|
videos: state.videoes.map(item => {
|
|
|
|
|
return {
|
|
|
|
|
video_id: item.videoId,
|
|
|
|
|
// todo
|
|
|
|
|
title: item.name
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}).then((response) => {
|
|
|
|
|
// to success page
|
|
|
|
|
if (response.data.status == 0) {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}).catch((error) => {
|
|
|
|
|
console.log(error)
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
// login
|
|
|
|
|
const username = props.match.params.username
|
|
|
|
|
return (
|
|
|
|
|
<div className="educontent videoUploadList">
|
|
|
|
|
<style>{`
|
|
|
|
@ -144,7 +177,7 @@ function VideoUploadList (props) {
|
|
|
|
|
<CBreadcrumb
|
|
|
|
|
separator=" > "
|
|
|
|
|
items={[
|
|
|
|
|
{ to: `users/${username}/videoes`, name: '视频'},
|
|
|
|
|
{ to: `/users/${username}/videoes`, name: '视频'},
|
|
|
|
|
{ name: '上传'}
|
|
|
|
|
]}
|
|
|
|
|
></CBreadcrumb>
|
|
|
|
@ -154,7 +187,7 @@ function VideoUploadList (props) {
|
|
|
|
|
{state.videoes.map((item, vIndex) => {
|
|
|
|
|
return (
|
|
|
|
|
<VideoUpload {...props} {...item} className="section"
|
|
|
|
|
cancelUpload={cancelUpload}
|
|
|
|
|
cancelUpload={cancelUpload} key={vIndex}
|
|
|
|
|
index={vIndex}
|
|
|
|
|
></VideoUpload>
|
|
|
|
|
)
|
|
|
|
@ -171,6 +204,7 @@ function VideoUploadList (props) {
|
|
|
|
|
</Button>
|
|
|
|
|
<input type="file" id="fileUpload" style={{display: 'none'}} onChange={onUploadChange}></input>
|
|
|
|
|
|
|
|
|
|
<ActionBtn className="publishBtn" onClick={() => onPublish()}>立即发布</ActionBtn>
|
|
|
|
|
</div>
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|