|
|
@@ -0,0 +1,491 @@
|
|
|
+<template>
|
|
|
+ <div>
|
|
|
+ <el-row class="movie-list">
|
|
|
+ <el-card class="box-card">
|
|
|
+ <div class="text item">
|
|
|
+ <el-button style="float: left; padding: 3px 0" type="text" @click="onReturnVideo">返回视频列表</el-button>
|
|
|
+ </div>
|
|
|
+ </el-card>
|
|
|
+ </el-row>
|
|
|
+ <el-row class="movie-list">
|
|
|
+ <el-col :md="8">
|
|
|
+ <el-card class="box-card">
|
|
|
+ <div slot="header" class="clearfix">
|
|
|
+ <span>更新视频文件</span>
|
|
|
+ <el-button style="float: right; padding: 3px 0" type="text" @click="onUpdateVideoFile">更新</el-button>
|
|
|
+ </div>
|
|
|
+ <div class="text item">
|
|
|
+ <uploader
|
|
|
+ class="uploader-example"
|
|
|
+ :options="options"
|
|
|
+ :auto-start="true"
|
|
|
+ @file-added="onFileAdded"
|
|
|
+ @file-success="onFileSuccess"
|
|
|
+ @file-progress="onFileProgress"
|
|
|
+ @file-error="onFileError"
|
|
|
+ >
|
|
|
+ <uploader-unsupport />
|
|
|
+ <uploader-drop>
|
|
|
+ <p>拖动视频文件到此处或</p>
|
|
|
+ <uploader-btn :attrs="attrs">选择视频文件</uploader-btn>
|
|
|
+ </uploader-drop>
|
|
|
+ <uploader-list />
|
|
|
+ </uploader>
|
|
|
+ </div>
|
|
|
+ </el-card>
|
|
|
+ </el-col>
|
|
|
+ <el-col :md="8">
|
|
|
+ <el-card class="box-card">
|
|
|
+ <div slot="header" class="clearfix">
|
|
|
+ <span>更新视频封面</span>
|
|
|
+ <el-button style="float: right; padding: 3px 0" type="text" @click="onUpdateVideoCover">更新</el-button>
|
|
|
+ </div>
|
|
|
+ <div class="text item">
|
|
|
+ <el-upload
|
|
|
+ class="avatar-uploader"
|
|
|
+ action="//oss.reghao.cn/"
|
|
|
+ :headers="imgHeaders"
|
|
|
+ :data="imgData"
|
|
|
+ :show-file-list="false"
|
|
|
+ :before-upload="beforeAvatarUpload"
|
|
|
+ :on-success="handleAvatarSuccess"
|
|
|
+ >
|
|
|
+ <img v-if="imageUrl" :src="imageUrl" class="avatar">
|
|
|
+ <i v-else class="el-icon-plus avatar-uploader-icon" />
|
|
|
+ </el-upload>
|
|
|
+ </div>
|
|
|
+ </el-card>
|
|
|
+ </el-col>
|
|
|
+ </el-row>
|
|
|
+ <el-row class="movie-list">
|
|
|
+ <el-col :md="8">
|
|
|
+ <el-card class="box-card">
|
|
|
+ <div slot="header" class="clearfix">
|
|
|
+ <span>更新视频信息</span>
|
|
|
+ <el-button style="float: right; padding: 3px 0" type="text" @click="onUpdateVideoInfo">更新</el-button>
|
|
|
+ </div>
|
|
|
+ <div class="text item">
|
|
|
+ <el-form ref="form" :model="form" label-width="80px">
|
|
|
+ <el-form-item label="标题">
|
|
|
+ <el-input v-model="form.title" style="width: 70%; padding-right: 2px" placeholder="标题不能超过 50 个字符" />
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item label="描述">
|
|
|
+ <el-input v-model="form.description" type="textarea" style="width: 70%; padding-right: 2px" />
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item label="分区">
|
|
|
+ <el-select v-model="category" placeholder="请选择分区">
|
|
|
+ <el-option label="新闻" value="shanghai" />
|
|
|
+ <el-option label="教育" value="beijing" />
|
|
|
+ </el-select>
|
|
|
+ <el-select v-model="childCategory" placeholder="请选择子分区">
|
|
|
+ <el-option label="历史" value="shanghai" />
|
|
|
+ <el-option label="计算机" value="beijing" />
|
|
|
+ </el-select>
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item label="标签">
|
|
|
+ <el-input v-model="tagsStr" style="width: 70%; padding-right: 2px" placeholder="多个标签之间使用英文逗号分隔" />
|
|
|
+ </el-form-item>
|
|
|
+ </el-form>
|
|
|
+ </div>
|
|
|
+ </el-card>
|
|
|
+ </el-col>
|
|
|
+ <el-col :md="8">
|
|
|
+ <el-card class="box-card">
|
|
|
+ <div slot="header" class="clearfix">
|
|
|
+ <span>更新视频可见范围</span>
|
|
|
+ <el-button style="float: right; padding: 3px 0" type="text" @click="onUpdateVideoScope">更新</el-button>
|
|
|
+ </div>
|
|
|
+ <div class="text item">
|
|
|
+ <el-form ref="form" :model="form" label-width="80px">
|
|
|
+ <el-form-item label="可见范围">
|
|
|
+ <el-select v-model="form.scope" placeholder="选择可见范围">
|
|
|
+ <el-option label="所有人可见" value="1" />
|
|
|
+ <el-option label="验证码可见" value="2" />
|
|
|
+ <el-option label="VIP 可见" value="3" />
|
|
|
+ <el-option label="仅自己可见" value="4" />
|
|
|
+ </el-select>
|
|
|
+ </el-form-item>
|
|
|
+ </el-form>
|
|
|
+ </div>
|
|
|
+ </el-card>
|
|
|
+ </el-col>
|
|
|
+ </el-row>
|
|
|
+ </div>
|
|
|
+</template>
|
|
|
+
|
|
|
+<script>
|
|
|
+import { videoCategory, submitVideo, videoInfo, updateVideoInfo, updateVideoScope, updateVideoCover, updateVideoFile } from '@/api/video'
|
|
|
+
|
|
|
+export default {
|
|
|
+ name: 'EditVideo',
|
|
|
+ data() {
|
|
|
+ return {
|
|
|
+ /***********************************************************************/
|
|
|
+ options: {
|
|
|
+ target: '//oss.reghao.cn/',
|
|
|
+ chunkSize: 1024 * 1024 * 1024 * 5, // 5GiB
|
|
|
+ fileParameterName: 'file',
|
|
|
+ testChunks: false,
|
|
|
+ query: (file, chunk) => {
|
|
|
+ return {
|
|
|
+ channelId: 2
|
|
|
+ }
|
|
|
+ },
|
|
|
+ headers: {
|
|
|
+ Authorization: '1234567890'
|
|
|
+ }
|
|
|
+ },
|
|
|
+ attrs: {
|
|
|
+ accept: 'video/*'
|
|
|
+ },
|
|
|
+ imgHeaders: {
|
|
|
+ Authorization: '1234567890'
|
|
|
+ },
|
|
|
+ imgData: {
|
|
|
+ channelId: 3
|
|
|
+ },
|
|
|
+ /***********************************************************************/
|
|
|
+ coverUrl: null,
|
|
|
+ categoryMap: {
|
|
|
+ Set: function(key, value) { this[key] = value },
|
|
|
+ Get: function(key) { return this[key] },
|
|
|
+ Contains: function(key) { return this.Get(key) !== null },
|
|
|
+ Remove: function(key) { delete this[key] }
|
|
|
+ },
|
|
|
+ category: [],
|
|
|
+ childCategory: [],
|
|
|
+ coverFile: null,
|
|
|
+ imageList: [],
|
|
|
+ imageUrl: '',
|
|
|
+ // 提交给后端的数据
|
|
|
+ tagsStr: null,
|
|
|
+ form: {
|
|
|
+ videoFileId: null,
|
|
|
+ coverUrl: null,
|
|
|
+ title: null,
|
|
|
+ description: null,
|
|
|
+ categoryId: 0,
|
|
|
+ tags: [],
|
|
|
+ scope: null,
|
|
|
+ width: 0,
|
|
|
+ height: 0,
|
|
|
+ duration: 0
|
|
|
+ },
|
|
|
+ videoInfo: null
|
|
|
+ }
|
|
|
+ },
|
|
|
+ created() {
|
|
|
+ document.title = '编辑视频'
|
|
|
+
|
|
|
+ const videoId = this.$route.params.videoId
|
|
|
+ videoInfo(videoId).then(res => {
|
|
|
+ if (res.code === 0) {
|
|
|
+ const videoInfo = res.data
|
|
|
+ this.imageUrl = videoInfo.coverUrl
|
|
|
+ this.form.title = videoInfo.title
|
|
|
+ this.form.description = videoInfo.description
|
|
|
+ this.form.scope = videoInfo.scope
|
|
|
+ } else {
|
|
|
+
|
|
|
+ }
|
|
|
+ })
|
|
|
+ //this.getVideoCategory()
|
|
|
+ },
|
|
|
+ methods: {
|
|
|
+ /***********************************************************************/
|
|
|
+ onFileAdded(file) {
|
|
|
+ if (file.file.size > 1024*1024*1024*5) {
|
|
|
+ file.cancel()
|
|
|
+ this.$notify(
|
|
|
+ {
|
|
|
+ title: '提示',
|
|
|
+ message: '视频文件应小于 5GiB',
|
|
|
+ type: 'warning',
|
|
|
+ duration: 3000
|
|
|
+ }
|
|
|
+ )
|
|
|
+ return
|
|
|
+ }
|
|
|
+ this.setTitle(file.file.name)
|
|
|
+ this.processVideo(file.file)
|
|
|
+ },
|
|
|
+ onFileProgress(rootFile, file, chunk) {
|
|
|
+ },
|
|
|
+ onFileSuccess(rootFile, file, response, chunk) {
|
|
|
+ const res = JSON.parse(response)
|
|
|
+ if (res.code === 0) {
|
|
|
+ const resData = res.data
|
|
|
+ this.form.videoFileId = resData.uploadId
|
|
|
+
|
|
|
+ this.$notify(
|
|
|
+ {
|
|
|
+ title: '提示',
|
|
|
+ message: '视频已上传',
|
|
|
+ type: 'warning',
|
|
|
+ duration: 3000
|
|
|
+ }
|
|
|
+ )
|
|
|
+ }
|
|
|
+ },
|
|
|
+ onFileError(rootFile, file, response, chunk) {
|
|
|
+ this.$notify(
|
|
|
+ {
|
|
|
+ title: '提示',
|
|
|
+ message: '文件上传错误',
|
|
|
+ type: 'warning',
|
|
|
+ duration: 3000
|
|
|
+ }
|
|
|
+ )
|
|
|
+ },
|
|
|
+ /***********************************************************************/
|
|
|
+ beforeAvatarUpload(file) {
|
|
|
+ const isJPG = file.type === 'image/jpeg'
|
|
|
+ const isLt2M = file.size / 1024 / 1024 < 2
|
|
|
+ if (!isJPG) {
|
|
|
+ this.$message.error('上传头像图片只能是 JPG 格式!')
|
|
|
+ }
|
|
|
+ if (!isLt2M) {
|
|
|
+ this.$message.error('上传头像图片大小不能超过 2MB!')
|
|
|
+ }
|
|
|
+ return isJPG && isLt2M
|
|
|
+ },
|
|
|
+ handleAvatarSuccess(res, file) {
|
|
|
+ this.imageList.push(file)
|
|
|
+ this.imageUrl = URL.createObjectURL(file.raw)
|
|
|
+ if (res.code === 0) {
|
|
|
+ const resData = res.data
|
|
|
+ const uploadId = resData.uploadId
|
|
|
+ const url = resData.url
|
|
|
+ } else {
|
|
|
+
|
|
|
+ }
|
|
|
+ },
|
|
|
+ /***********************************************************************/
|
|
|
+ // 选择视频后获取视频的分辨率和时长, 并截取第一秒的内容作为封面
|
|
|
+ processVideo(file) {
|
|
|
+ return new Promise((resolve, reject) => {
|
|
|
+ const canvas = document.createElement('canvas')
|
|
|
+ const canvasCtx = canvas.getContext('2d')
|
|
|
+
|
|
|
+ const videoElem = document.createElement('video')
|
|
|
+ const dataUrl = window.URL.createObjectURL(file)
|
|
|
+ // 当前帧的数据是可用的
|
|
|
+ videoElem.onloadeddata = function() {
|
|
|
+ resolve(videoElem)
|
|
|
+ }
|
|
|
+ videoElem.onerror = function() {
|
|
|
+ reject('video 后台加载失败')
|
|
|
+ }
|
|
|
+ // 设置 auto 预加载数据, 否则会出现截图为黑色图片的情况
|
|
|
+ videoElem.setAttribute('preload', 'auto')
|
|
|
+ videoElem.src = dataUrl
|
|
|
+ // 预加载完成后才会获取到视频的宽高和时长数据
|
|
|
+ videoElem.addEventListener('canplay', this.onCanPlay(videoElem, canvas, canvasCtx))
|
|
|
+ })
|
|
|
+ },
|
|
|
+ onCanPlay(videoElem, canvas, canvasCtx) {
|
|
|
+ setTimeout(() => {
|
|
|
+ // 视频视频分辨率
|
|
|
+ const videoWidth = videoElem.videoWidth
|
|
|
+ const videoHeight = videoElem.videoHeight
|
|
|
+ this.form.width = videoWidth
|
|
|
+ this.form.height = videoHeight
|
|
|
+ this.form.duration = videoElem.duration
|
|
|
+
|
|
|
+ videoElem.pause()
|
|
|
+ // 设置画布尺寸
|
|
|
+ canvas.width = videoWidth
|
|
|
+ canvas.height = videoHeight
|
|
|
+ canvasCtx.drawImage(videoElem, 0, 0, canvas.width, canvas.height)
|
|
|
+ // 把图标base64编码后变成一段url字符串
|
|
|
+ const urlData = canvas.toDataURL('image/jpeg')
|
|
|
+ if (typeof urlData !== 'string') {
|
|
|
+ alert('urlData不是字符串')
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ var arr = urlData.split(',')
|
|
|
+ var bstr = atob(arr[1])
|
|
|
+ var n = bstr.length
|
|
|
+ var u8arr = new Uint8Array(n)
|
|
|
+ while (n--) {
|
|
|
+ u8arr[n] = bstr.charCodeAt(n)
|
|
|
+ }
|
|
|
+
|
|
|
+ const coverFile = new File([u8arr], 'cover.jpg', { type: 'image/jpeg' })
|
|
|
+ if (coverFile instanceof File) {
|
|
|
+ const formData = new FormData()
|
|
|
+ formData.append('file', coverFile)
|
|
|
+ formData.append('channelId', 3)
|
|
|
+ fetch(`//oss.reghao.cn/`, {
|
|
|
+ headers: {
|
|
|
+ Authorization: '1234567890'
|
|
|
+ },
|
|
|
+ method: 'POST',
|
|
|
+ credentials: 'include',
|
|
|
+ body: formData
|
|
|
+ }).then(response => response.json())
|
|
|
+ .then(json => {
|
|
|
+ if (json.code === 0) {
|
|
|
+ const resData = json.data
|
|
|
+ this.form.coverUrl = resData.url
|
|
|
+ this.imageUrl = resData.url
|
|
|
+ } else {
|
|
|
+ this.$notify(
|
|
|
+ {
|
|
|
+ title: '提示',
|
|
|
+ message: '视频封面上传失败,请重试!' + json.msg,
|
|
|
+ type: 'warning',
|
|
|
+ duration: 3000
|
|
|
+ }
|
|
|
+ )
|
|
|
+ }
|
|
|
+ })
|
|
|
+ .catch(e => {
|
|
|
+ return null
|
|
|
+ })
|
|
|
+ }
|
|
|
+ }, 1000) // 1000毫秒,就是截取第一秒,2000毫秒就是截取第2秒,视频1秒通常24帧,也可以换算成截取第几帧。
|
|
|
+ // 防止拖动进度条的时候重复触发
|
|
|
+ // videoElem.removeEventListener('canplay', arguments.callee)
|
|
|
+ },
|
|
|
+ /***********************************************************************/
|
|
|
+ setTitle(title) {
|
|
|
+ if (title.length > 50) {
|
|
|
+ this.form.title = title.substring(0, 50)
|
|
|
+ this.form.description = title
|
|
|
+ } else {
|
|
|
+ this.form.title = title
|
|
|
+ }
|
|
|
+ },
|
|
|
+ getVideoCategory() {
|
|
|
+ videoCategory()
|
|
|
+ .then(res => {
|
|
|
+ if (res.code === 0) {
|
|
|
+ for (let i = 0; i < res.data.length; i++) {
|
|
|
+ const name = res.data[i].name
|
|
|
+ //this.category.push(name)
|
|
|
+ this.categoryMap.Set(name, res.data[i])
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ this.$notify(
|
|
|
+ {
|
|
|
+ title: '提示',
|
|
|
+ message: res.msg,
|
|
|
+ type: 'warning',
|
|
|
+ duration: 3000
|
|
|
+ }
|
|
|
+ )
|
|
|
+ }
|
|
|
+ }).catch(error => {
|
|
|
+ this.$notify(
|
|
|
+ {
|
|
|
+ title: '提示',
|
|
|
+ message: error.message,
|
|
|
+ type: 'error',
|
|
|
+ duration: 3000
|
|
|
+ }
|
|
|
+ )
|
|
|
+ })
|
|
|
+ },
|
|
|
+ getCategory(name) {
|
|
|
+ // 重置子分区,清除前一次选择分区时留下的缓存
|
|
|
+ this.childCategory = []
|
|
|
+ this.currentCategory = this.categoryMap.Get(name)
|
|
|
+ this.form.categoryId = this.currentCategory.id
|
|
|
+
|
|
|
+ const c = this.currentCategory.children
|
|
|
+ if (c) {
|
|
|
+ for (let i = 0; i < c.length; i++) {
|
|
|
+ this.childCategory.push(c[i].name)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
+ getChildCategory(name) {
|
|
|
+ const c = this.currentCategory.children
|
|
|
+ for (let i = 0; i < c.length; i++) {
|
|
|
+ if (c[i].name === name) {
|
|
|
+ this.form.categoryId = c[i].id
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
+ onReturnVideo() {
|
|
|
+ this.$router.push('/post/video')
|
|
|
+ },
|
|
|
+ onUpdateVideoFile() {
|
|
|
+ console.log('更新视频文件')
|
|
|
+ },
|
|
|
+ onUpdateVideoCover() {
|
|
|
+ console.log('更新视频封面')
|
|
|
+ },
|
|
|
+ onUpdateVideoInfo() {
|
|
|
+ console.log('更新视频信息')
|
|
|
+ },
|
|
|
+ onUpdateVideoScope() {
|
|
|
+ console.log('更新视频作用域')
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+</script>
|
|
|
+
|
|
|
+<style>
|
|
|
+/*处于手机屏幕时*/
|
|
|
+@media screen and (max-width: 768px){
|
|
|
+ .movie-list {
|
|
|
+ padding-top: 8px;
|
|
|
+ padding-left: 0.5%;
|
|
|
+ padding-right: 0.5%;
|
|
|
+ }
|
|
|
+
|
|
|
+ .coverImg {
|
|
|
+ height: 120px !important;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+.movie-list {
|
|
|
+ padding-top: 15px;
|
|
|
+ padding-left: 6%;
|
|
|
+ padding-right: 6%;
|
|
|
+}
|
|
|
+
|
|
|
+.uploader-example {
|
|
|
+ width: 500px;
|
|
|
+ padding: 15px;
|
|
|
+ margin: 40px auto 0;
|
|
|
+ font-size: 12px;
|
|
|
+ box-shadow: 0 0 10px rgba(0, 0, 0, .4);
|
|
|
+}
|
|
|
+.uploader-example .uploader-btn {
|
|
|
+ margin-right: 4px;
|
|
|
+}
|
|
|
+.uploader-example .uploader-list {
|
|
|
+ max-height: 440px;
|
|
|
+ overflow: auto;
|
|
|
+ overflow-x: hidden;
|
|
|
+ overflow-y: auto;
|
|
|
+}
|
|
|
+
|
|
|
+.avatar-uploader .el-upload {
|
|
|
+ border: 1px dashed #d9d9d9;
|
|
|
+ border-radius: 6px;
|
|
|
+ cursor: pointer;
|
|
|
+ position: relative;
|
|
|
+ overflow: hidden;
|
|
|
+}
|
|
|
+.avatar-uploader .el-upload:hover {
|
|
|
+ border-color: #409EFF;
|
|
|
+}
|
|
|
+.avatar-uploader-icon {
|
|
|
+ font-size: 28px;
|
|
|
+ color: #8c939d;
|
|
|
+ width: 320px;
|
|
|
+ height: 240px;
|
|
|
+ line-height: 178px;
|
|
|
+ text-align: center;
|
|
|
+}
|
|
|
+.avatar {
|
|
|
+ width: 320px;
|
|
|
+ height: 240px;
|
|
|
+ display: block;
|
|
|
+}
|
|
|
+</style>
|