dev_hjm
hjm 6 years ago
parent ba4d2711ac
commit 0e47f3e69d

@ -1,5 +1,16 @@
import update from 'immutability-helper' import update from 'immutability-helper'
function find(state, action) {
let _index = -1
state.videoes.some((item, index) => {
// 同文件不同名字 fileHash也是一样的
if (item.loaded != 100 && (action.uploadInfo.fileHash == item.fileHash && action.uploadInfo.file.name == item.name)) {
_index = index
return true;
}
})
return _index;
}
export function reducer(state, action) { export function reducer(state, action) {
switch (action.type) { switch (action.type) {
case 'addVideo': case 'addVideo':
@ -12,21 +23,16 @@ export function reducer(state, action) {
fileHash: uploadInfo.fileHash, // "ba1bbc53fdecd9eaaae479fbd9518442" fileHash: uploadInfo.fileHash, // "ba1bbc53fdecd9eaaae479fbd9518442"
state: uploadInfo.state, // "Uploading" "Ready" "Success" state: uploadInfo.state, // "Uploading" "Ready" "Success"
videoId: uploadInfo.videoId, // "719b82c875c34ac39f94feb145d25ad2" videoId: uploadInfo.videoId, // "719b82c875c34ac39f94feb145d25ad2"
loaded: 0 loaded: 0,
title: ''
}]}; }]};
case 'removeVideo': case 'removeVideo':
return { return {
videoes: update(state.videoes, {$splice: [[action.index, 1]]}) videoes: update(state.videoes, {$splice: [[action.index, 1]]})
} }
case 'updateProgress': case 'updateProgress':
let _index = -1; let _index = find(state, action)
state.videoes.some((item, index) => {
// 同文件不同名字 fileHash也是一样的
if (item.loaded != 100 && (action.uploadInfo.fileHash == item.fileHash && action.uploadInfo.file.name == item.name)) {
_index = index
return true;
}
})
let newVideoes = state.videoes let newVideoes = state.videoes
// 删除先执行 // 删除先执行
if (_index != -1) { if (_index != -1) {
@ -39,6 +45,17 @@ export function reducer(state, action) {
}}) }})
} }
return {videoes: newVideoes}; return {videoes: newVideoes};
case 'updateTitle':
let _upadteIndex = action.index
let newVideoes2 = state.videoes
if (_upadteIndex != -1) {
newVideoes2 = update(state.videoes, {[_upadteIndex]: {
title: {$set: action.title},
}})
}
return {videoes: newVideoes2};
default: default:
throw new Error(); throw new Error();
} }

@ -18,12 +18,12 @@ loaded: 0
*/ */
function VideoUpload (props) { function VideoUpload (props) {
const { className, index, name, loaded, state, cancelUpload } = props; const { className, index, name, loaded, state, cancelUpload, onTitleChange, title } = props;
const [title, setTitle] = useState('') // const [title, setTitle] = useState('')
const username = props.match.params.username const username = props.match.params.username
function titleChange (e) { function titleChange (e) {
setTitle(e.target.value) onTitleChange(e.target.value, index)
} }
return ( return (
<div className={`videoUpload ${className}`}> <div className={`videoUpload ${className}`}>
@ -32,12 +32,19 @@ function VideoUpload (props) {
<Progress percent={loaded} <Progress percent={loaded}
status={loaded == '100' ? "" : 'active'} status={loaded == '100' ? "" : 'active'}
/> />
<ActionBtn className="cancelUpload" onClick={() => cancelUpload(index, loaded == '100' )}>{loaded == '100' ? "删除" : "取消上传"}</ActionBtn> <div className="cancelUpload">
<ActionBtn className="" onClick={() => cancelUpload(index, loaded == '100' )}>{loaded == '100' ? "删除" : "取消上传"}</ActionBtn>
</div>
</div> </div>
<Input placeholder={`标题支持最多${MAX_LENGTH}个字符`} onInput={titleChange} maxLength={MAX_LENGTH} suffix ={ <div>
<span className="titleLabel">标题</span>
<Input placeholder={`标题支持最多${MAX_LENGTH}个字符`} onInput={titleChange} maxLength={MAX_LENGTH} suffix={
<span className="color-grey-6 font-13">{String(title.length)}/{MAX_LENGTH}</span> <span className="color-grey-6 font-13">{String(title.length)}/{MAX_LENGTH}</span>
}></Input> }
className="titleInput"
></Input>
</div>
</div> </div>
) )
} }

@ -11,6 +11,8 @@ import { reducer, initialState } from './VideoReducer'
import { deleteVideoInCloud } from './VideoUtil' import { deleteVideoInCloud } from './VideoUtil'
let uploader let uploader
const files = [] const files = []
const MAX_FILE_COUNT = 3
const MAX_FILE_SIZE = 200
function VideoUploadList (props) { function VideoUploadList (props) {
const [videoes, setVideoes] = useState([]); const [videoes, setVideoes] = useState([]);
@ -28,13 +30,22 @@ function VideoUploadList (props) {
} }
if (file.size > 200 * 1024 * 1024) { if (file.size > 200 * 1024 * 1024) {
// 超过200m TODO // 超过200m TODO
alert("视频大小超过200M") showNotification(`视频大小超过${MAX_FILE_SIZE}M`)
return;
}
let gotTheSameFileName = false;
state.videoes.some((item) => {
if (item.name == file.name) {
gotTheSameFileName = true;
return true;
}
})
if (gotTheSameFileName) {
showNotification(`你不能上传同一个视频文件名称,请重新选择。`)
return; return;
} }
// TODO 判断文件类型
var Title = file.name var Title = file.name
file.type
var userData = '{"Vod":{}}' var userData = '{"Vod":{}}'
if (!uploader) { if (!uploader) {
@ -164,6 +175,9 @@ function VideoUploadList (props) {
console.log(error) console.log(error)
}) })
} }
function onTitleChange(title, index) {
dispatch({type: 'updateTitle', title, index})
}
// login // login
return ( return (
<div className="educontent videoUploadList"> <div className="educontent videoUploadList">
@ -171,17 +185,44 @@ function VideoUploadList (props) {
.videoUploadList .section { .videoUploadList .section {
background: #fff; background: #fff;
padding: 16px 20px; padding: 16px 20px;
padding-top: 0px;
}
.videoUploadList .cBreadcrumb {
margin-top: 16px;
}
.videoUploadList .title .head {
display: inline-block;
margin-right: 8px;
}
.videoUploadList .title .titleDescription {
color: #555;
}
.videoUploadList .section .description {
padding-top: 10px;
margin-top: 20px; margin-top: 20px;
margin-bottom: 30px;
} }
/* item */ /* item */
.videoUploadList .cancelUpload { .videoUploadList .cancelUpload {
flex: 0 0 92px; flex: 0 0 200px;
}
.videoUploadList .titleInput {
width: 480px;
margin-top: 16px;
}
.videoUploadList .videoUpload {
padding: 26px 0;
border-bottom: 1px dashed #DCDCDC;
}
.videoUploadList .videoUpload:last-child {
border-bottom: none;
} }
`}</style> `}</style>
<CBreadcrumb <CBreadcrumb
className="mb30"
separator=" > " separator=" > "
items={[ items={[
{ to: `/users/${username}/videoes`, name: '视频'}, { to: `/users/${username}/videoes`, name: '视频'},
@ -189,18 +230,26 @@ function VideoUploadList (props) {
]} ]}
></CBreadcrumb> ></CBreadcrumb>
<div className="title section">上传视频</div> <div className="title">
<h2 className="head">上传视频</h2>
<span className="titleDescription">单次最多支持{MAX_FILE_COUNT}个视频文件上传不支持断点续传单个视频文件最大{MAX_FILE_SIZE}M</span>
</div>
<div className="section">
<div>
{state.videoes.map((item, vIndex) => { {state.videoes.map((item, vIndex) => {
return ( return (
<VideoUpload {...props} {...item} className="section" <VideoUpload {...props} {...item} className=""
cancelUpload={cancelUpload} key={vIndex} cancelUpload={cancelUpload}
onTitleChange={onTitleChange}
key={vIndex}
index={vIndex} index={vIndex}
></VideoUpload> ></VideoUpload>
) )
})} })}
</div>
<div className="description section"> <div className="description">
<div className="">视频大小不支持断点续传单个视频文件最大200M单次最多支持3个视频文件上传 </div> <div className="">视频大小不支持断点续传单个视频文件最大200M单次最多支持3个视频文件上传 </div>
<div className="">视频规格aviflvf4vm4vmovmp4rmvbswfwebm </div> <div className="">视频规格aviflvf4vm4vmovmp4rmvbswfwebm </div>
<div className="">温馨提示请勿上传违法视频平台将为每一个视频分配一个地址您可以通过引用改地址将视频使用在开发社区等模块</div> <div className="">温馨提示请勿上传违法视频平台将为每一个视频分配一个地址您可以通过引用改地址将视频使用在开发社区等模块</div>
@ -215,6 +264,7 @@ function VideoUploadList (props) {
<ActionBtn className="publishBtn" onClick={() => onPublish()}>立即发布</ActionBtn> <ActionBtn className="publishBtn" onClick={() => onPublish()}>立即发布</ActionBtn>
</div> </div>
</div>
) )
} }

Loading…
Cancel
Save