素材管理 视频上传

This commit is contained in:
shidongli 2024-03-06 15:49:52 +08:00
parent 45f03dfb5e
commit 6979259e33
2 changed files with 312 additions and 9 deletions

View File

@ -189,13 +189,12 @@
prop="materialsFilePath"
v-if="form.materialsType == 'VIDEO'"
>
<stationAcatar
style="width: 208px"
@imgUrl="imgUrl2"
:tovideo="form.materialsFilePath"
:type="'materialsVideoUrl'"
v-if="open"
/>
<trainingAvatar
@imgUrl="imgUrl2"
:tovideo="form.materialsFilePath"
:type="'materialsVideoUrl'"
/>
</el-form-item>
<el-form-item
@ -309,10 +308,11 @@
<script>
import { listMaterials, getMaterials, delMaterials, addMaterials, updateMaterials,crowdInfo } from "@/api/manage/materials";
import stationAcatar from "../../system/stationAvatar/index.vue";
import trainingAvatar from "../../system/trainingAvatar/index.vue";
export default {
name: "Materials",
components: { stationAcatar },
components: { stationAcatar ,trainingAvatar},
dicts: ['crowd_type', 'materials_type', 'video_cover_type'],
data() {
return {
@ -431,10 +431,14 @@ export default {
},
//
radioChange(e) {
if(e=='VIDEO'){
this.form.materialsFilePath=null
this.form.videoCoverFilePath=null
}else if(e=='IMAGE_TEXT'){
this.form.materialsFilePath=null
this.form.videoCoverFilePath=null
console.log(e)
}
},
//
@ -445,7 +449,9 @@ export default {
imgUrl2(imgUrl) {
this.form.materialsFilePath = process.env.VUE_APP_BASE_API + imgUrl;
this.form.materialsFilePath = imgUrl;
},
//
imgUrl3(imgUrl) {
console.log(this.form.videoCoverFilePath)

View File

@ -0,0 +1,297 @@
<template>
<div>
<div class="user-info-head" :class="video.VideoPath ? 'wihi' : ''" @click="editCropper()">
<video style="width: 208px; height: 208px" v-bind:src="video.VideoPath" v-if="video.VideoPath"
class="avatar video-avatar" controls="controls">您的浏览器不支持视频播放</video>
<i class="el-icon-plus avatar-uploader-icon" style="
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
"></i>
</div>
<el-dialog :title="title" :visible.sync="openimg" width="950px" append-to-body @opened="modalOpened"
@close="closeDialog">
<el-row>
<el-col :xs="24" :md="24" :style="{ height: '350px' }">
<div class="avatar-upload-preview">
<video v-if="openimg" style="width: 100%; height: 100%" v-bind:src="videoForm.showVideoPath"
class="avatar video-avatar" controls="controls">您的浏览器不支持视频播放</video>
</div>
</el-col>
</el-row>
<br />
<el-progress v-if="progressFlag" :percentage="loadProgress" style="height:30px;padding-bottom:20px"></el-progress>
<el-row style="padding-bottom:0px">
<el-col :lg="3" :md="2">
<el-upload :show-file-list="false" class="upload-demo" ref="upload" :action="uploadurl"
:on-preview="handlePreview" :auto-upload="false" :on-change="loadJsonFromFile" :data="filedata"
:headers="headers" :on-progress="uploadVideoProcess" :on-success="handleAvatarSuccess">
<el-button slot="trigger" size="small" type="primary" style="float:left">选取文件</el-button>
</el-upload>
</el-col>
<el-col :lg="{ span: 2, offset: 18 }" :md="2">
<el-button v-if="uploadbtn" type="primary" size="small" @click="submitUpload"> </el-button>
<el-button v-else :loading="!uploadbtn" type="primary" size="small">提交中...</el-button>
</el-col>
</el-row>
</el-dialog>
</div>
</template>
<script>
import { VueCropper } from "vue-cropper";
import { uploadFilefm } from "@/api/system/stationAvatar.js";
import { getToken } from "@/utils/auth";
export default {
components: { VueCropper },
props: ["img", "type", "item", "tovideo"],
data() {
return {
fileList: [],
loadProgress: 0, //
progressFlag: false, //
uploadbtn: true, //
imageUrl: "",
//
openimg: false,
// cropper
visible: false,
//
title: "上传图片/视频",
filedata: {
type: ""
},
headers: {
Authorization: "Bearer " + getToken() // token
},
options: {
img: null, //
autoCrop: true, //
autoCropWidth: 300, //
autoCropHeight: 300, //
fixedBox: true //
},
previews: {},
items: {},
//
videoForm: {
showVideoPath: null //
},
video: {
VideoPath: null //
},
uploadurl: undefined
};
},
created() {
this.uploadurl =
process.env.VUE_APP_BASE_API + "/manage/file/uploadFile";
this.uploadbtn = true;
this.filedata.type = this.type;
this.items = this.item;
if (this.tovideo == null) {
this.video.VideoPath = null;
} else if (this.tovideo == "") {
this.video.VideoPath = null;
} else {
this.videoForm.showVideoPath =
process.env.VUE_APP_BASE_API + this.tovideo;
this.video.VideoPath = process.env.VUE_APP_BASE_API + this.tovideo;
}
this.title = "上传视频";
},
watch: {
tovideo: {
handler(newimg, oldimg) {
this.uploadbtn = true;
if (newimg == null) {
this.video.VideoPath = null;
this.videoForm.showVideoPath = null
} else if (newimg == "") {
this.video.VideoPath = null;
this.videoForm.showVideoPath = null
} else {
this.videoForm.showVideoPath = process.env.VUE_APP_BASE_API + newimg;
this.video.VideoPath = process.env.VUE_APP_BASE_API + newimg;
}
}
},
item: {
handler(newimg, oldimg) {
this.uploadbtn = true;
this.items = this.item;
}
},
type: {
handler(newimg, oldimg) {
this.filedata.type = this.type;
}
}
},
methods: {
uploadVideoProcess(event, file, fileList) {
this.progressFlag = true; //
this.loadProgress = parseInt(event.percent); //
if (this.loadProgress >= 100) {
this.loadProgress = 100;
setTimeout(() => {
this.progressFlag = false;
}, 1000); //
}
},
loadJsonFromFile(file, fileList) {
const reader = new FileReader();
this.previews.data = file.raw;
this.videoForm.showVideoPath = URL.createObjectURL(file.raw);
reader.readAsDataURL(file.raw);
reader.onload = () => {
// this.options.img = reader.result;
};
},
submitUpload() {
this.uploadbtn = false;
this.$refs.upload.submit();
},
handlePreview(file) { },
//
editCropper() {
this.openimg = true;
},
//
modalOpened() {
this.visible = true;
},
//
requestUpload() { },
//
rotateLeft() {
this.$refs.cropper.rotateLeft();
},
//
rotateRight() {
this.$refs.cropper.rotateRight();
},
//
changeScale(num) {
num = num || 1;
this.$refs.cropper.changeScale(num);
},
//
beforeUpload(file) {
const reader = new FileReader();
this.previews.data = file;
this.videoForm.showVideoPath = URL.createObjectURL(file);
reader.readAsDataURL(file);
reader.onload = () => {
// this.options.img = reader.result;
};
},
handleAvatarSuccess(res, file) {
if (res.code == 200) {
this.video.VideoPath = process.env.VUE_APP_BASE_API + res.imgUrl;
this.$emit("imgUrl", res.imgUrl);
this.$modal.msgSuccess("上传视频成功");
this.openimg = false;
} else {
this.$message.error(res.msg);
}
this.uploadbtn = true;
},
//
uploadImg() {
this.uploadbtn = true;
let formData = new FormData();
if (this.previews.data) {
formData.append("file", this.previews.data);
formData.append("type", this.filedata.type);
this.$modal.msgSuccess("上传视频中,请耐心等待");
this.uploadbtn = false;
uploadFilefm(formData).then(response => {
if (response.code == 200) {
this.video.VideoPath =
process.env.VUE_APP_BASE_API + response.imgUrl;
this.items.itemDirectoryUrl = response.imgUrl;
this.$emit("item", JSON.stringify(this.items));
this.openimg = false;
} else {
setTimeout(e => {
this.openimg = false;
}, 1000);
}
this.uploadbtn = true;
});
} else {
this.openimg = false;
}
// this.videoForm.showVideoPath = null;
this.previews.data = null;
},
//
realTime(data) {
this.previews = data;
},
//
closeDialog() {
this.visible = false;
}
}
};
</script>
<style scoped lang="scss">
.title {
position: absolute;
bottom: 5%;
left: 50%;
transform: translate(-50%, 0%);
}
.avatar-upload-preview {
position: absolute;
top: 0%;
left: 50%;
transform: translate(-50%, 0%);
width: 300px;
height: 300px;
border-radius: 0%;
box-shadow: 0 0 4px #ccc;
overflow: hidden;
}
.user-info-head {
position: relative;
display: inline-block;
background: #fafafa;
width: 100px;
height: 100px;
}
.user-info-head:hover:after {
content: "";
position: absolute;
left: 0;
right: 0;
top: 0;
bottom: 0;
color: #eee;
background: rgba(0, 0, 0, 0.5);
font-size: 24px;
font-style: normal;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
cursor: pointer;
line-height: 110px;
border-radius: 50%;
}
.wihi {
background-color: #fff;
width: 100px;
height: 100px;
}
.wihi:hover:after {
transform: translate(50%, 50%);
}
</style>