dev_hjm
hjm 6 years ago
parent d36da7c2c9
commit 913f7ed2cf

@ -21,18 +21,24 @@ export function reducer(state, action) {
case 'updateProgress':
let _index = -1;
state.videoes.some((item, index) => {
// addFileSuccess的时候没有fileHash
// if (uploadInfo.fileHash == item.fileHash) {
if (action.uploadInfo.fileHash == item.fileHash || action.uploadInfo.file.name == item.name) {
// 同文件不同名字 fileHash也是一样的
if (item.loaded != 100 && (action.uploadInfo.fileHash == item.fileHash && action.uploadInfo.file.name == item.name)) {
_index = index
return true;
}
})
return {videoes: update(state.videoes, {[_index]: {
loaded: {$set: action.progressPercent},
videoId: {$set: action.uploadInfo.videoId},
fileHash: {$set: action.uploadInfo.fileHash}
}})};
let newVideoes = state.videoes
// 删除先执行
if (_index != -1) {
newVideoes = update(state.videoes, {[_index]: {
loaded: {$set: action.progressPercent},
videoId: {$set: action.uploadInfo.videoId},
// addFileSuccess的时候没有fileHash
fileHash: {$set: action.uploadInfo.fileHash}
}})
}
return {videoes: newVideoes};
default:
throw new Error();
}

@ -4,7 +4,7 @@ import { getUrl2, isDev, CBreadcrumb, ActionBtn } from 'educoder'
import axios from 'axios'
const MAX_LENGTH = 60
const MAX_LENGTH = 30
/**
name: file.name,
@ -30,7 +30,7 @@ function VideoUpload (props) {
<div className="filename">{index+1}. {name}</div>
<div className="progress df">
<Progress percent={loaded}
status={state == "Uploading" ? "active" : ''}
status={loaded == '100' ? "" : 'active'}
/>
<ActionBtn className="cancelUpload" onClick={() => cancelUpload(index, loaded == '100' )}>{loaded == '100' ? "删除" : "取消上传"}</ActionBtn>
</div>

@ -8,7 +8,7 @@ import { Button } from 'antd'
import { getUploader } from './AliyunUploaderManager'
import { reducer, initialState } from './VideoReducer'
import { deleteVideoInCloud } from './VideoUtil'
let uploader
const files = []
function VideoUploadList (props) {
@ -16,7 +16,7 @@ function VideoUploadList (props) {
const [videoes, setVideoes] = useState([]);
const [state, dispatch] = useReducer(reducer, initialState);
const username = props.match.params.username
const { showNotification } = props;
const uploaderOptions = {
}
@ -121,22 +121,23 @@ function VideoUploadList (props) {
}
// uploader.deleteFile(index);
function cancelUpload(index, isSuccess) {
// 确定取消?
// const file = files[index]
// TODO 确定取消?
uploader.deleteFile(index)
if (isSuccess) {
uploader.deleteFile(index)
} else {
uploader.cancelFile(index)
}
// files.splice(index, 1)
deleteVideoInCloud(username, state.videoes[index].videoId)
}
// else {
// uploader.cancelFile(index)
// }
const _input = document.getElementById('fileUpload')
_input.value = ''
dispatch({type: 'removeVideo', index})
// setVideoes([...videoes.splice(index, 1)])
}
function onPublish() {
if (state.videoes.length == 0) {
this.props.showNotification('请先上传视频')
showNotification('请先上传视频')
return;
}
const publishUrl = `/users/${username}/videos/batch_publish.json`

@ -0,0 +1,13 @@
import axios from 'axios'
export function deleteVideoInCloud(login, video_id) {
const url = `/users/${login}/videos/cancel.json`
axios.post(url, {
video_id
}).then((response) => {
}).catch((error) => {
console.log(error)
})
}
Loading…
Cancel
Save