2022-03-22 16:46:00 +08:00
|
|
|
|
<template>
|
|
|
|
|
|
<section class="vpAdd">
|
|
|
|
|
|
<ai-detail>
|
|
|
|
|
|
<ai-title slot="title" :title="addTitle" isShowBottomBorder isShowBack @onBackClick="back"/>
|
|
|
|
|
|
<template #content>
|
|
|
|
|
|
<el-form size="small" label-width="120px" :model="form" ref="VideoForm" :rules="rules">
|
|
|
|
|
|
<ai-card title="基本信息">
|
|
|
|
|
|
<template #content>
|
|
|
|
|
|
<el-form-item label="标题" prop="title">
|
|
|
|
|
|
<el-input v-model="form.title" placeholder="请输入" clearable show-word-limit maxlength="30"/>
|
|
|
|
|
|
</el-form-item>
|
2022-04-11 14:03:42 +08:00
|
|
|
|
<el-form-item label="排序" prop="showIndex">
|
|
|
|
|
|
<el-input v-model.number="form.showIndex" placeholder="请输入" clearable/>
|
|
|
|
|
|
</el-form-item>
|
2022-03-22 16:46:00 +08:00
|
|
|
|
<el-form-item label="视频" prop="videoUrl">
|
|
|
|
|
|
<video v-if="hasVideo" class="video-com" muted :src="form.videoUrl" controls="controls"/>
|
|
|
|
|
|
<el-upload :show-file-list="false" ref="upload1" action :http-request="submitUpload"
|
|
|
|
|
|
:accept="accept" :limit="1">
|
|
|
|
|
|
<div class="video" v-if="!hasVideo">
|
|
|
|
|
|
<div class="icon">
|
|
|
|
|
|
<ai-icon type="svg" icon="iconVideo"/>
|
|
|
|
|
|
<span>上传视频</span>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<span class="tips">支持mp4格式,单个文件最大100MB</span>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<el-button v-else style="margin-top: 10px;">重新选择</el-button>
|
|
|
|
|
|
</el-upload>
|
|
|
|
|
|
</el-form-item>
|
|
|
|
|
|
<el-form-item label="视频封面" prop="thumbUrl">
|
|
|
|
|
|
<ai-uploader :instance="instance" :value="thumb" @change="handleUploader" key="file" :limit="1">
|
|
|
|
|
|
<template slot="tips">
|
|
|
|
|
|
<p>最多上传1张图片,单个文件最大10MB,支持jpg、jpeg、png格式</p>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
</ai-uploader>
|
|
|
|
|
|
</el-form-item>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
</ai-card>
|
|
|
|
|
|
</el-form>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
<template #footer>
|
|
|
|
|
|
<el-button @click="back">取消</el-button>
|
|
|
|
|
|
<el-button type="primary" @click="submit">保存</el-button>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
</ai-detail>
|
|
|
|
|
|
</section>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
|
|
<script>
|
|
|
|
|
|
import mp4box from "mp4box";
|
|
|
|
|
|
|
|
|
|
|
|
export default {
|
|
|
|
|
|
name: "vpAdd",
|
|
|
|
|
|
props: {
|
|
|
|
|
|
instance: Function,
|
|
|
|
|
|
dict: Object,
|
|
|
|
|
|
permissions: Function
|
|
|
|
|
|
},
|
|
|
|
|
|
computed: {
|
|
|
|
|
|
addTitle() {
|
|
|
|
|
|
return !!this.$route.query.id ? "编辑视频" : "添加视频"
|
|
|
|
|
|
},
|
|
|
|
|
|
rules() {
|
|
|
|
|
|
return {
|
|
|
|
|
|
title: [{required: true, message: "请输入标题"}],
|
|
|
|
|
|
thumbUrl: [{required: true, message: "请上传视频封面"}],
|
2022-03-23 10:18:00 +08:00
|
|
|
|
videoUrl: [{required: true, message: "请上传视频"}],
|
2022-04-11 14:03:42 +08:00
|
|
|
|
showIndex: [{required: true, message: "请输入排序"}],
|
2022-03-22 16:46:00 +08:00
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
hasVideo() {
|
|
|
|
|
|
return !!this.form.videoUrl
|
|
|
|
|
|
},
|
2022-03-23 10:18:00 +08:00
|
|
|
|
thumb() {
|
|
|
|
|
|
return this.form.thumbUrl ? [{url: this.form.thumbUrl}] : []
|
2022-03-22 16:46:00 +08:00
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
data() {
|
|
|
|
|
|
return {
|
|
|
|
|
|
dialog: false,
|
2022-03-30 17:17:01 +08:00
|
|
|
|
form: {videoUrl: "", thumbUrl: "", title: ""},
|
2022-03-22 16:46:00 +08:00
|
|
|
|
accept: ".mp4"
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
methods: {
|
|
|
|
|
|
getDetail() {
|
|
|
|
|
|
let {id} = this.$route.query
|
2022-08-26 14:24:34 +08:00
|
|
|
|
id && this.instance.post("/app/appvideonews/getById", null, {
|
2022-03-22 16:46:00 +08:00
|
|
|
|
params: {id}
|
|
|
|
|
|
}).then(res => {
|
|
|
|
|
|
if (res?.data) {
|
|
|
|
|
|
this.form = res.data
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
},
|
|
|
|
|
|
submit() {
|
|
|
|
|
|
this.$refs.VideoForm.validate(v => {
|
|
|
|
|
|
if (v) {
|
|
|
|
|
|
let {form} = this
|
2022-08-26 14:24:34 +08:00
|
|
|
|
this.instance.post("/app/appvideonews/addOrUpdate", form).then(res => {
|
2022-03-22 16:46:00 +08:00
|
|
|
|
if (res?.code == 0) {
|
|
|
|
|
|
this.$message.success("提交成功!")
|
|
|
|
|
|
this.back()
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
},
|
|
|
|
|
|
back() {
|
|
|
|
|
|
this.$router.push({})
|
|
|
|
|
|
},
|
|
|
|
|
|
submitUpload(file) {
|
|
|
|
|
|
this.$refs.upload1?.clearFiles();
|
|
|
|
|
|
const fileType = file.file.name.split(".")[1];
|
|
|
|
|
|
const size = file.file.size / 1024 / 1024 > 100;
|
|
|
|
|
|
let mp4boxfile = mp4box.createFile();
|
|
|
|
|
|
const reader = new FileReader();
|
|
|
|
|
|
reader.readAsArrayBuffer(file.file);
|
|
|
|
|
|
reader.onload = (e) => {
|
|
|
|
|
|
const arrayBuffer = e.target.result;
|
|
|
|
|
|
arrayBuffer.fileStart = 0;
|
|
|
|
|
|
mp4boxfile.appendBuffer(arrayBuffer);
|
|
|
|
|
|
};
|
|
|
|
|
|
mp4boxfile.onReady = (info) => {
|
|
|
|
|
|
let codec = info.mime.match(/codecs="(\S*),/)[1]
|
|
|
|
|
|
if (codec.indexOf('avc') === -1) {
|
|
|
|
|
|
return this.$message.error("视频编码格式不支持")
|
|
|
|
|
|
}
|
|
|
|
|
|
if (size) {
|
|
|
|
|
|
return this.$message.error("视频大小不能超过100M");
|
|
|
|
|
|
}
|
|
|
|
|
|
if (fileType && this.accept.indexOf(fileType.toLocaleLowerCase()) > -1) {
|
|
|
|
|
|
let formData = new FormData()
|
|
|
|
|
|
formData.append('file', file.file);
|
|
|
|
|
|
this.instance.post(`/admin/file/add-unlimited`, formData).then(res => {
|
|
|
|
|
|
if (res && res.data) {
|
|
|
|
|
|
let videoList = res.data[0].split(";");
|
|
|
|
|
|
this.form.videoUrl = videoList[0]
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
} else {
|
|
|
|
|
|
return this.$message.error("视频格式错误")
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
handleUploader(list) {
|
|
|
|
|
|
this.form.thumbUrl = list?.[0]?.url
|
2022-03-23 10:18:00 +08:00
|
|
|
|
this.$forceUpdate()
|
2022-03-22 16:46:00 +08:00
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
created() {
|
|
|
|
|
|
this.getDetail()
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
|
|
|
.vpAdd {
|
|
|
|
|
|
height: 100%;
|
|
|
|
|
|
|
|
|
|
|
|
video {
|
|
|
|
|
|
width: 100%;
|
|
|
|
|
|
height: 100%;
|
|
|
|
|
|
object-fit: fill;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-12-01 09:35:20 +08:00
|
|
|
|
:deep( input[type="number"] ){
|
2022-03-22 16:46:00 +08:00
|
|
|
|
line-height: 1px !important;
|
|
|
|
|
|
|
|
|
|
|
|
&::-webkit-outer-spin-button, &::-webkit-inner-spin-button {
|
|
|
|
|
|
-webkit-appearance: none !important;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.video {
|
|
|
|
|
|
width: 640px;
|
|
|
|
|
|
height: 360px;
|
|
|
|
|
|
border-radius: 4px;
|
|
|
|
|
|
border: 1px dashed #D0D4DC;
|
|
|
|
|
|
display: flex;
|
|
|
|
|
|
flex-direction: column;
|
|
|
|
|
|
align-items: center;
|
|
|
|
|
|
justify-content: center;
|
|
|
|
|
|
|
|
|
|
|
|
.icon {
|
|
|
|
|
|
display: flex;
|
|
|
|
|
|
flex-direction: column;
|
|
|
|
|
|
align-items: center;
|
|
|
|
|
|
justify-content: center;
|
|
|
|
|
|
|
|
|
|
|
|
span:nth-child(2) {
|
|
|
|
|
|
display: inline-block;
|
|
|
|
|
|
font-size: 16px;
|
|
|
|
|
|
color: #333333;
|
|
|
|
|
|
line-height: 30px;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.iconfont {
|
|
|
|
|
|
display: inline-block;
|
|
|
|
|
|
font-size: 40px;
|
|
|
|
|
|
color: #2266FF;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.tips {
|
|
|
|
|
|
display: inline-block;
|
|
|
|
|
|
font-size: 12px;
|
|
|
|
|
|
color: #999999;
|
|
|
|
|
|
line-height: 26px;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
</style>
|