<template>
<div class="upload-video">
<div v-if="videoList.length > 0 || isEdit" class="image-list">
<el-upload
v-if="isEdit"
:show-file-list="false"
:data="{FoldPath:'上传目录',SecretKey:'安全验证'}"
:on-progress="uploadVideoProcess"
:on-change="handleVideoSuccess"
:before-upload="beforeUploadVideo"
:auto-upload="false"
:multiple="true"
action
class="image-item"
>
<div v-if="!videoFlag" class="upload-image">
<i class="el-icon-plus" />
</div>
<el-progress v-if="videoFlag" :percentage="videoUploadPercent" type="circle" style="margin-top:7px;"/>
</el-upload>
<div v-for="(item, index) in videoList" :key="item.uid" class="image-item" @click="getPlayVideo(item)">
<video class="video">
<source :src="item.url || item">
</video>
<div class="play-btn-icon"><i class="iconfont-ziranziyuan iconyunhang" /></div>
<div v-if="isEdit" class="del-btn-icon" @click.stop="deleteVideo(index)"><i class="iconfont-ziranziyuan iconshanchu1" /></div>
</div>
</div>
<div v-else>无</div>
<div v-if="isShowPlay" class="play-video">
<div class="close-video" @click="getPlayVideo({})"><i class="el-icon-close"/></div>
<video class="video-draw" controls autoplay>
<source :src="playVideo.url || playVideo">
</video>
</div>
</div>
</template>
<script>
export default {
name: 'UploadVideo',
props: {
isEdit: {
type: Boolean,
default: true
},
spdz: {
type: Array,
default: () => []
}
},
data() {
return {
videoFlag: false,
videoUploadPercent: '',
isShowUploadVideo: false,
playVideo: {},
isShowPlay: false,
videoList: []
}
},
created() {
this.videoList = [...this.spdz]
},
methods: {
handleVideoSuccess(file) {
this.isShowUploadVideo = true
this.videoFlag = false
this.videoUploadPercent = 0
const videoObj = { ...file }
videoObj.url = window.webkitURL.createObjectURL(file.raw)
this.videoList.push(videoObj)
this.$emit('changeSPDZ', this.videoList)
},
beforeUploadVideo(file) {
if (['video/mp4', 'video/ogg', 'video/flv', 'video/avi', 'video/wmv', 'video/rmvb', 'video/mov'].indexOf(file.type) === -1) {
this.$mymess.warning('请上传正确的视频格式')
return false
}
this.isShowUploadVideo = false
},
uploadVideoProcess(event, file, fileList) {
this.videoFlag = true
this.videoUploadPercent = file.percentage.toFixed(0) * 1
},
getPlayVideo(video) {
this.isShowPlay = !this.isShowPlay
this.playVideo = video
},
deleteVideo(index) {
this.videoList.splice(index, 1)
this.$emit('changeSPDZ', this.videoList)
}
}
}
</script>
<style lang="scss" scoped>
.upload-video {
width: 100%;
.image-list {
display: flex;
width: 100%;
flex-wrap: wrap;
.image-item {
display: inline-block;
margin-bottom: 12px;
height: 126px;
width: calc((100% - 48px)/4);
margin-right: 16px;
text-align: center;
line-height: 124px;
font-size: 32px;
color: #C0C4CC;
background-color: #F2F6FC;
border-radius: 4px;
border: 1px solid #DCDFE6;
position: relative;
/deep/.el-upload {
width: 100%;
}
&:nth-child(4n) {
margin-right: 0;
}
.video {
width: 100%;
height: 100%;
}
&:hover {
.del-btn-icon {
display: block;
}
}
.play-btn-icon {
width: 24px;
height: 24px;
line-height: 24px;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
color: #FFFFFF;
.iconfont-ziranziyuan {
font-size: 24px;
}
}
.del-btn-icon {
display: none;
cursor: pointer;
position: absolute;
width: 100%;
height: 28px;
bottom: 0;
left: 0;
background-color: rgba(0, 0, 0, 0.6);
font-size: 16px;
line-height: 28px;
color: #FFFFFF;
}
}
}
.play-video {
position: fixed;
left: 0;
right: 0;
top: 0;
bottom: 0;
background-color: rgba(0, 0, 0, 0.5);
z-index: 10000;
.video-draw {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
.close-video {
width: 40px;
height: 40px;
background-color: #606266;
border-radius: 50%;
position: absolute;
font-size: 24px;
line-height: 40px;
text-align: center;
opacity: 0.8;
top: 38px;
cursor: pointer;
color: #FFFFFF;
right: 30px;
}
}
}
</style>
上传视频组件
最新推荐文章于 2025-05-01 08:38:22 发布