<template>
<div class="upload-video">
<div id="videoBox" ref="videoBox"></div>
<div>
<el-upload
v-loading="uploadLoading"
class="upload-demo"
:action="''"
:multiple="false"
accept="video/mp4,video/quicktime,video/avi"
:auto-upload="false"
:file-list="fileList"
:limit="1"
:on-change="handleVideoChange"
:on-remove="handleRemove"
:on-exceed="handleExceed"
:on-error="handleError"
>
<el-button plain>上傳視頻</el-button>
<div slot="tip" class="el-upload__tip">
選擇本地視頻上傳,不支持多條視頻同步上傳
</div>
</el-upload>
</div>
<div v-if="progressSeen">
<el-progress
v-if="!uploadStatus"
:percentage="progress"
status="warning"
style="width:350px"
></el-progress>
<el-progress
v-else-if="uploadStatus && progress !== 100"
:percentage="progress"
style="width:350px"
></el-progress>
<el-progress v-else :percentage="progress" status="success" style="width:350px"></el-progress>
</div>
<!-- <el-button plain @click="test">測試</el-button> -->
</div>
</template>
<script>
export default {
name: 'UploadVideo',
props: {
content: {
type: String,
default: ''
},
uploadImgMaxSize: {
type: Number,
default: 10 * 1024 * 1024
},
uploadImgServer: {
type: String,
default: ''
},
uploadFileName: {
type: String,
default: 'file'
},
uploadImgAccept: {
type: Array,
default: () => ['jpg', 'jpeg', 'png', 'gif']
}
},
data () {
return {
uploadSign: {
host: ''
},
uploadLoading: false,
fileList: [],
progress: 0,
progressSeen: false,
uploadStatus: true
}
},
computed: {},
watch: {},
mounted () {},
methods: {
async handleVideoChange (file) {
const validFile = file.raw
//只能插入一個(gè)視頻
console.log(validFile)
if (this.fileList.length > 0) {
this.$message.error('只能插入一個(gè)視頻')
return false
}
const isLt1G = validFile && validFile.size / 1024 / 1024 / 1024 < 1
if (!isLt1G) {
this.$message.error('視頻大小不能超過1G')
return false
}
this.uploadStatus = true
this.progressSeen = true
this.progress = 10
await this.getSignature(validFile && validFile.name)
const client = {
key: this.uploadSign.filePath,
policy: this.uploadSign.policy,
OSSAccessKeyId: this.uploadSign.accessId,
signature: this.uploadSign.signature,
expire: this.uploadSign.expire,
dir: this.uploadSign.dir,
callBack: this.uploadSign.callBack,
success_action_status: '200'
}
this.uploadOssVideo(client, validFile)
},
async getSignature (fileName) {
let res = await fetchApi.article.getUploadSign({ fileName })
this.uploadSign = res.data
console.log(this.uploadSign)
},
async uploadOssVideo (client, file) {
let _this = this
var oMyForm = new FormData()
for (var field_name in client) {
oMyForm.append(field_name, client[field_name])
}
oMyForm.append('file', file)
var oReq = new XMLHttpRequest()
//上傳進(jìn)度監(jiān)聽
oReq.upload.onprogress = function (e) {
if (e.type == 'progress') {
_this.uploadLoading = true
var percent = Math.round((e.loaded / e.total) * 100, 2)
_this.progress = percent
}
}
//上傳結(jié)果
oReq.onreadystatechange = function (e) {
_this.uploadLoading = false
if (oReq.readyState == 4) {
if (oReq.status == 200) {
//這里如果成功返回的是 success_action_status設(shè)置的值
_this.$message.success('上傳成功')
try {
const path = e.target.response && JSON.parse(e.target.response).fileFullPath
console.log(path)
_this.$emit('uploadVide', path)
} catch (error) {}
} else {
_this.$message.error('上傳失敗')
this.uploadStatus = false
}
}
}
oReq.open('POST', this.uploadSign.host)
oReq.send(oMyForm)
},
test () {
this.handleError()
},
handleRemove (file, fileList) {
this.progressSeen = false
this.progress = 0
},
handleExceed () {
this.$message.warning(`只能插入一個(gè)視頻`)
},
handleError () {
this.$message.error('上傳失敗')
this.uploadStatus = false
// this.fileList = []
this.$emit('uploadVide', '')
}
}
}
</script>
<style lang="scss">
.upload-video {
.el-upload-list__item-name {
padding-left: 0px !important;
}
}
</style>
VUE 基于 element 上傳視頻,顯示進(jìn)度條
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
- 文/潘曉璐 我一進(jìn)店門咧栗,熙熙樓的掌柜王于貴愁眉苦臉地迎上來逆甜,“玉大人,你說我怎么就攤上這事致板〗簧罚” “怎么了?”我有些...
- 文/不壞的土叔 我叫張陵斟或,是天一觀的道長素征。 經(jīng)常有香客問我,道長萝挤,這世上最難降的妖魔是什么御毅? 我笑而不...
- 正文 為了忘掉前任,我火速辦了婚禮怜珍,結(jié)果婚禮上端蛆,老公的妹妹穿的比我還像新娘。我一直安慰自己酥泛,他們只是感情好今豆,可當(dāng)我...
- 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著揭璃,像睡著了一般晚凿。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上瘦馍,一...
- 文/蒼蘭香墨 我猛地睜開眼袍祖,長吁一口氣:“原來是場噩夢啊……” “哼底瓣!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起蕉陋,我...
- 序言:老撾萬榮一對情侶失蹤捐凭,失蹤者是張志新(化名)和其女友劉穎,沒想到半個(gè)月后凳鬓,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體茁肠,經(jīng)...
- 正文 獨(dú)居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
- 正文 我和宋清朗相戀三年缩举,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了垦梆。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片匹颤。...
- 正文 年R本政府宣布赦肃,位于F島的核電站,受9級特大地震影響绞旅,放射性物質(zhì)發(fā)生泄漏摆尝。R本人自食惡果不足惜,卻給世界環(huán)境...
- 文/蒙蒙 一因悲、第九天 我趴在偏房一處隱蔽的房頂上張望堕汞。 院中可真熱鬧,春花似錦晃琳、人聲如沸讯检。這莊子的主人今日做“春日...
- 文/蒼蘭香墨 我抬頭看了看天上的太陽人灼。三九已至,卻和暖如春顾翼,著一層夾襖步出監(jiān)牢的瞬間投放,已是汗流浹背。 一陣腳步聲響...
- 正文 我出身青樓拜姿,卻偏偏與公主長得像烙样,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個(gè)殘疾皇子蕊肥,可洞房花燭夜當(dāng)晚...
推薦閱讀更多精彩內(nèi)容
- 最近項(xiàng)目中涉及很多文件上傳的地方壁却,然后文件上傳又有很多限制批狱。比如文件大小限制,文件個(gè)數(shù)限制儒洛,文件類型限制精耐,文件上傳...
- LayUI上傳附件進(jìn)度條 目前文件上傳基本沒有進(jìn)度提示,可參考如下設(shè)置加入進(jìn)度提示: 替換upload.js 增加...
- SuperWeb 超級瀏覽器 基于騰訊X5內(nèi)核 目前已有功能: 1、文件瀏覽(支持pdf/ppt/doc/exce...
- 1. Demo介紹 使用前后端分離開發(fā)的模式實(shí)現(xiàn)文件上傳,前端使用Vue框架凿跳,后端使用node的express框架...