删除当前出错的,并执行下一个任务

dev_hjm^2
hjm 6 years ago
parent 1c62cf337e
commit a21ca8c695

@ -4,7 +4,7 @@ import axios from 'axios'
let _url_origin = getUrl2() let _url_origin = getUrl2()
let _path = _isDev ? 'public' : 'build' let _path = _isDev ? 'public' : 'build'
let _testHost = 'http://192.168.2.63:3001/api' ; // '' ; let _testHost = '' ; // 'http://192.168.2.63:3001/api' ; // '' ;
let login = 'innov' let login = 'innov'
let uploader; let uploader;
@ -44,7 +44,6 @@ function doCreateUploader (options) {
userId: $('#userId').val() || 1202060945918292, // 1303984639806000, userId: $('#userId').val() || 1202060945918292, // 1303984639806000,
// 添加文件成功 // 添加文件成功
addFileSuccess: function (uploadInfo) { addFileSuccess: function (uploadInfo) {
options.addFileSuccess && options.addFileSuccess(uploadInfo)
console.log("addFileSuccess: " + uploadInfo.file.name) console.log("addFileSuccess: " + uploadInfo.file.name)
@ -74,7 +73,13 @@ function doCreateUploader (options) {
var uploadAddress = data.UploadAddress var uploadAddress = data.UploadAddress
var videoId = data.VideoId var videoId = data.VideoId
uploader.setUploadAuthAndAddress(uploadInfo, uploadAuth, uploadAddress, videoId) uploader.setUploadAuthAndAddress(uploadInfo, uploadAuth, uploadAddress, videoId)
options.addFileSuccess && options.addFileSuccess(uploadInfo)
}).catch((error) => { }).catch((error) => {
// 删除当前出错的,并执行下一个任务
uploader.deleteFile(uploader._curIndex)
uploader.nextUpload()
console.log(error) console.log(error)
}) })
@ -88,12 +93,20 @@ function doCreateUploader (options) {
axios.put(refreshUrl, { axios.put(refreshUrl, {
video_id: uploadInfo.videoId, video_id: uploadInfo.videoId,
}).then((response) => { }).then((response) => {
if (response.data.status == -1) {
options.onUploadError && options.onUploadError(uploadInfo)
return;
}
const data = response.data.data const data = response.data.data
var uploadAuth = data.UploadAuth var uploadAuth = data.UploadAuth
var uploadAddress = data.UploadAddress var uploadAddress = data.UploadAddress
var videoId = data.VideoId var videoId = data.VideoId
uploader.setUploadAuthAndAddress(uploadInfo, uploadAuth, uploadAddress, videoId) uploader.setUploadAuthAndAddress(uploadInfo, uploadAuth, uploadAddress, videoId)
options.addFileSuccess && options.addFileSuccess(uploadInfo)
}).catch((error) => { }).catch((error) => {
uploader.deleteFile(uploader._curIndex)
uploader.nextUpload()
console.log(error) console.log(error)
}) })
} }

@ -4,9 +4,42 @@ import {Link} from 'react-router-dom';
import { getUrl2, isDev } from 'educoder' import { getUrl2, isDev } from 'educoder'
import axios from 'axios' import axios from 'axios'
const PAGE_SIZE = 12
function InfoVideo (props) { function InfoVideo (props) {
const username = props.match.params.username const username = props.match.params.username
function fetchVideoes() {
const fetchUrl = `/users/${username}/videos.json`
axios.get(fetchUrl, {
params: {
per_page: PAGE_SIZE
}
})
.then((response) => {
}).catch(() => {
})
}
function fetchReviewVideoes() {
const fetchUrl = `/users/${username}/videos/review.json`
axios.get(fetchUrl, {
params: {
per_page: 200
}
})
.then((response) => {
}).catch(() => {
})
}
useEffect(() => {
fetchVideoes()
fetchReviewVideoes()
}, [])
return ( return (
<div>123 <div>123

@ -14,6 +14,10 @@ export function reducer(state, action) {
videoId: uploadInfo.videoId, // "719b82c875c34ac39f94feb145d25ad2" videoId: uploadInfo.videoId, // "719b82c875c34ac39f94feb145d25ad2"
loaded: 0 loaded: 0
}]}; }]};
case 'removeVideo':
return {
videoes: update(state.videoes, {$splice: [[action.index, 1]]})
}
case 'updateProgress': case 'updateProgress':
let _index = -1; let _index = -1;
state.videoes.some((item, index) => { state.videoes.some((item, index) => {
@ -26,6 +30,7 @@ export function reducer(state, action) {
}) })
return {videoes: update(state.videoes, {[_index]: { return {videoes: update(state.videoes, {[_index]: {
loaded: {$set: action.progressPercent}, loaded: {$set: action.progressPercent},
videoId: {$set: action.uploadInfo.videoId},
fileHash: {$set: action.uploadInfo.fileHash} fileHash: {$set: action.uploadInfo.fileHash}
}})}; }})};
default: default:

@ -22,7 +22,7 @@ function VideoUpload (props) {
const [title, setTitle] = useState('') const [title, setTitle] = useState('')
const username = props.match.params.username const username = props.match.params.username
function titleChange () { function titleChange (e) {
setTitle(e.target.value) setTitle(e.target.value)
} }
return ( return (
@ -32,7 +32,7 @@ function VideoUpload (props) {
<Progress percent={loaded} <Progress percent={loaded}
status={state == "Uploading" ? "active" : ''} status={state == "Uploading" ? "active" : ''}
/> />
<ActionBtn className="cancelUpload" onClick={() => cancelUpload(index)}>取消上传</ActionBtn> <ActionBtn className="cancelUpload" onClick={() => cancelUpload(index, loaded == '100' )}>{loaded == '100' ? "删除" : "取消上传"}</ActionBtn>
</div> </div>
<Input placeholder={`标题支持最多${MAX_LENGTH}个字符`} onInput={titleChange} maxLength={MAX_LENGTH} suffix ={ <Input placeholder={`标题支持最多${MAX_LENGTH}个字符`} onInput={titleChange} maxLength={MAX_LENGTH} suffix ={

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

Loading…
Cancel
Save