在 nginx 当中配置上传地址与最大上传容量
client_max_body_size 1024m;
location ~ /service_vod {
proxy_pass http://localhost:8003;
}
在 api 当中创建 vod.js
前端请求文件
import request from '@/utils/request'
const API_NAME = '/service_vod/vod'
export default {
deleteVodById(id) {
return request({
url: `${API_NAME}/delete_vod/${id}`,
method: 'post'
});
}
}
修改后端首先是接口路径名称如下,然后紧接着就是修改 ContentVideoInfoVO
添加一个新的字段
在 chapte.vue 当中定义相关属性
// 小节视频标题
videoOriginalName: ''
// 上传文件列表
fileList: [],
BASE_API: process.env.VUE_APP_BASE_API
导入 vod 请求文件
import void from "@/api/video/vod/vod";
添加上传组件
<el-form-item label="上传视频">
<!-- 上传视频 -->
<el-upload
:on-success="handleVodUploadSuccess"
:on-remove="handleVodRemove"
:before-remove="beforeVodRemove"
:on-exceed="handleUploadExceed"
:file-list="fileList"
:action="BASE_API+'/service_vod/vod/upload'"
:limit="1"
class="upload-demo">
<el-button size="small" type="primary">上传视频</el-button>
<el-tooltip placement="right-end">
<div slot="content">最大支持1G,<br>
支持3GP、ASF、AVI、DAT、DV、FLV、F4V、<br>
GIF、M2T、M4V、MJ2、MJPEG、MKV、MOV、MP4、<br>
MPE、MPG、MPEG、MTS、OGG、QT、RM、RMVB、<br>
SWF、TS、VOB、WMV、WEBM 等视频格式上传
</div>
<i class="el-icon-question"/>
</el-tooltip>
</el-upload>
</el-form-item>
定义组件方法
//自动上传成功回调
handleVodUploadSuccess(response, file, fileList) {
// 获取当前上传视频的ID
this.contentVideo.videoSourceId = response.data.videoId;
// 获取当前上传视频标题
this.contentVideo.videoOriginalName = file.name;
// 设置文件名回显
this.fileList = [{'name': this.contentVideo.videoOriginalName}];
},
// 已经超过了指定数量时,调用此方法
handleUploadExceed(files, fileList) {
this.$message.warning('请先删除已上传的视频!');
},
//删除之前提示信息
beforeVodRemove(file, fileList) {
return this.$confirm(`确定删除 ${file.name}?`);
},
//删除小节视频
handleVodRemove(file, fileList) {
vod.deleteVodById(this.contentVideo.videoSourceId).then(response => {
// 清空当前小节视频id
this.contentVideo.videoSourceId = '';
// 清空当前小节视频标题
this.contentVideo.videoOriginalName = '';
this.fileList = [];
this.$message({
type: 'success',
message: response.message
});
});
},
更改之前的小节编辑回显代码如下
editorContentVideo(id) {
this.dialogVideoFormVisible = true;
contentVideo.getVideoInfoById(id).then(res => {
this.contentVideo = res.data.item;
// 如果有视频, 显示视频标题
if (this.contentVideo.videoOriginalName !== '') {
this.fileList = [{'name': this.contentVideo.videoOriginalName}];
}
});
},
可能还有一个小问题后面在解决