2023-02-07 13:36:02 +08:00
|
|
|
|
<template>
|
2023-02-07 15:46:45 +08:00
|
|
|
|
<ai-detail class="content-add" v-loading="isLoading">
|
2023-02-07 13:36:02 +08:00
|
|
|
|
<template slot="title">
|
2023-02-07 15:46:45 +08:00
|
|
|
|
<ai-title :title="params.id ? '编辑' + '课程' : '添加' + '课程'" isShowBack isShowBottomBorder @onBackClick="cancel(false)"></ai-title>
|
2023-02-07 13:36:02 +08:00
|
|
|
|
</template>
|
|
|
|
|
|
<template slot="content">
|
|
|
|
|
|
<ai-card title="基本信息">
|
|
|
|
|
|
<template #content>
|
2023-02-07 15:46:45 +08:00
|
|
|
|
<el-form class="ai-form" :model="form" label-width="120px" ref="form">
|
2023-02-14 11:48:49 +08:00
|
|
|
|
<el-form-item label="课程名称" style="width: 100%;" prop="title" :rules="[{required: true, message: '请输入标题', trigger: 'blur'}]">
|
2023-02-07 15:46:45 +08:00
|
|
|
|
<el-input size="small" v-model="form.title" clearable placeholder="请输入..." :maxlength="50" :show-word-limit="true"></el-input>
|
2023-02-07 13:36:02 +08:00
|
|
|
|
</el-form-item>
|
2023-02-14 11:48:49 +08:00
|
|
|
|
<el-form-item prop="courseType" label="课程类型" :rules="[{required: true, message: '请选择课程类型', trigger: 'change'}]">
|
|
|
|
|
|
<ai-select
|
|
|
|
|
|
v-model="form.courseType"
|
|
|
|
|
|
clearable
|
|
|
|
|
|
placeholder="请选择课程类型"
|
|
|
|
|
|
:selectList="dict.getDict('qjCourseType')">
|
|
|
|
|
|
</ai-select>
|
2023-02-07 13:36:02 +08:00
|
|
|
|
</el-form-item>
|
2023-02-07 15:46:45 +08:00
|
|
|
|
<el-form-item prop="showIndex" label="排序" :rules="[{required: true, message: '请选择文章类型', trigger: 'change'}]">
|
|
|
|
|
|
<el-input-number size="small" v-model="form.showIndex" :min="0"></el-input-number>
|
2023-02-07 13:36:02 +08:00
|
|
|
|
</el-form-item>
|
2023-02-14 11:48:49 +08:00
|
|
|
|
<el-form-item v-if="form.courseType === '0'" label="正文" prop="content" style="width: 100%;" :rules="[{required: true, message: '请输入内容', trigger: 'change'}]">
|
2023-02-07 15:46:45 +08:00
|
|
|
|
<ai-editor v-model="form.content" :instance="instance"/>
|
2023-02-07 13:36:02 +08:00
|
|
|
|
</el-form-item>
|
2023-02-14 11:48:49 +08:00
|
|
|
|
<el-form-item v-if="form.courseType === '0' && !isHideCoverimg" label="封面图片" prop="pictureUrl" :rules="[{required: true, message: '请上传封面图片', trigger: 'change'}]" style="width: 100%;">
|
2023-02-07 13:36:02 +08:00
|
|
|
|
<ai-uploader
|
|
|
|
|
|
:instance="instance"
|
2023-02-14 11:48:49 +08:00
|
|
|
|
isShowTip
|
|
|
|
|
|
v-model="form.pictureUrl"
|
|
|
|
|
|
:limit="1"
|
|
|
|
|
|
:cropOps="cropOps"
|
|
|
|
|
|
is-crop>
|
2023-02-07 15:46:45 +08:00
|
|
|
|
<template slot="tips">
|
2023-02-14 11:48:49 +08:00
|
|
|
|
<p>最多上传1张图片,单个文件最大10MB,支持jpg、jpeg、png格式</p>
|
|
|
|
|
|
<p>图片比例:1.6:1</p>
|
2023-02-07 15:46:45 +08:00
|
|
|
|
</template>
|
2023-02-07 13:36:02 +08:00
|
|
|
|
</ai-uploader>
|
|
|
|
|
|
</el-form-item>
|
2023-02-14 11:48:49 +08:00
|
|
|
|
<el-form-item v-if="form.courseType === '1'" label="视频" prop="videoUrl" style="width: 100%;" :rules="[{required: true, message: '请上传视频', trigger: 'change'}]">
|
2023-02-07 15:46:45 +08:00
|
|
|
|
<el-upload :show-file-list="false" ref="upload1" action :http-request="submitUpload" :accept="accept" :limit="1">
|
2023-02-14 11:48:49 +08:00
|
|
|
|
<div class="video" v-if="!form.videoUrl.length">
|
2023-02-07 15:46:45 +08:00
|
|
|
|
<div class="icon">
|
|
|
|
|
|
<ai-icon type="svg" icon="iconVideo"/>
|
|
|
|
|
|
<span>上传视频</span>
|
2023-02-07 13:36:02 +08:00
|
|
|
|
</div>
|
2023-02-07 15:46:45 +08:00
|
|
|
|
<span class="tips">支持mp4格式,单个文件最大100MB</span>
|
2023-02-07 13:36:02 +08:00
|
|
|
|
</div>
|
2023-02-07 15:46:45 +08:00
|
|
|
|
</el-upload>
|
|
|
|
|
|
<video class="video-com" style="width:100%; height:100%; object-fit: fill;" muted
|
2023-02-14 11:48:49 +08:00
|
|
|
|
:src="form.videoUrl[0].url" controls="controls" v-if="form.videoUrl.length"></video>
|
2023-02-07 15:46:45 +08:00
|
|
|
|
<el-upload :show-file-list="false" ref="upload2" action :http-request="submitUpload" :accept="accept"
|
2023-02-14 11:48:49 +08:00
|
|
|
|
:limit="1" v-if="form.videoUrl.length">
|
2023-02-07 15:46:45 +08:00
|
|
|
|
<el-button style="margin-top: 10px;">重新选择</el-button>
|
|
|
|
|
|
</el-upload>
|
|
|
|
|
|
</el-form-item>
|
2023-02-14 11:48:49 +08:00
|
|
|
|
<el-form-item label="视频封面" prop="pictureUrl" style="width: 100%;" v-if="form.courseType === '1'" :rules="[{required: true, message: '请上传视频封面', trigger: 'change'}]">
|
2023-02-07 15:46:45 +08:00
|
|
|
|
<ai-uploader
|
|
|
|
|
|
:instance="instance"
|
|
|
|
|
|
isShowTip
|
|
|
|
|
|
v-model="form.pictureUrl"
|
|
|
|
|
|
:limit="1"
|
|
|
|
|
|
:cropOps="cropOps"
|
|
|
|
|
|
is-crop>
|
|
|
|
|
|
<template slot="tips">
|
|
|
|
|
|
<p>最多上传1张图片,单个文件最大10MB,支持jpg、jpeg、png格式</p>
|
|
|
|
|
|
<p>图片比例:1.6:1</p>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
</ai-uploader>
|
2023-02-07 13:36:02 +08:00
|
|
|
|
</el-form-item>
|
|
|
|
|
|
</el-form>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
</ai-card>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
<template #footer>
|
|
|
|
|
|
<el-button @click="cancel">取消</el-button>
|
2023-02-07 15:46:45 +08:00
|
|
|
|
<el-button type="primary" :loading="isLoading" @click="confirm">提交</el-button>
|
2023-02-07 13:36:02 +08:00
|
|
|
|
</template>
|
|
|
|
|
|
</ai-detail>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
|
|
<script>
|
2023-02-07 15:46:45 +08:00
|
|
|
|
import mp4box from 'mp4box'
|
2023-02-07 13:36:02 +08:00
|
|
|
|
export default {
|
|
|
|
|
|
name: 'Add',
|
|
|
|
|
|
|
|
|
|
|
|
props: {
|
|
|
|
|
|
instance: Function,
|
|
|
|
|
|
dict: Object,
|
2023-02-14 11:48:49 +08:00
|
|
|
|
params: Object
|
2023-02-07 13:36:02 +08:00
|
|
|
|
},
|
|
|
|
|
|
data () {
|
|
|
|
|
|
return {
|
|
|
|
|
|
info: {},
|
2023-02-07 15:46:45 +08:00
|
|
|
|
accept: '.mp4',
|
2023-02-07 13:36:02 +08:00
|
|
|
|
form: {
|
|
|
|
|
|
title: '',
|
2023-02-07 15:46:45 +08:00
|
|
|
|
content: '',
|
|
|
|
|
|
showIndex: '',
|
2023-02-14 11:48:49 +08:00
|
|
|
|
videoUrl: [],
|
2023-02-07 15:46:45 +08:00
|
|
|
|
pictureUrl: [],
|
2023-02-14 11:48:49 +08:00
|
|
|
|
courseType: '0',
|
|
|
|
|
|
duration: ''
|
2023-02-07 13:36:02 +08:00
|
|
|
|
},
|
2023-02-07 15:46:45 +08:00
|
|
|
|
isLoading: false,
|
|
|
|
|
|
cropOps: {
|
|
|
|
|
|
width: "336px",
|
|
|
|
|
|
height: "210px"
|
|
|
|
|
|
},
|
|
|
|
|
|
id: '',
|
|
|
|
|
|
contentTypeList: [
|
|
|
|
|
|
{
|
|
|
|
|
|
name: '图文',
|
|
|
|
|
|
value: '0'
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
name: '视频',
|
|
|
|
|
|
value: '1'
|
|
|
|
|
|
}
|
|
|
|
|
|
],
|
|
|
|
|
|
isHideCoverimg: false,
|
|
|
|
|
|
cateList: [],
|
|
|
|
|
|
needExamine: '0'
|
2023-02-07 13:36:02 +08:00
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
created () {
|
2023-02-14 11:48:49 +08:00
|
|
|
|
this.dict.load('qjCourseType').then(() => {
|
|
|
|
|
|
if (this.params && this.params.id) {
|
|
|
|
|
|
this.getInfo(this.params.id)
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
2023-02-07 13:36:02 +08:00
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
methods: {
|
|
|
|
|
|
getInfo (id) {
|
2023-02-14 11:48:49 +08:00
|
|
|
|
this.instance.post(`/app/appcourseinfo/queryDetailById?id=${id}`).then(res => {
|
2023-02-07 13:36:02 +08:00
|
|
|
|
if (res.code === 0) {
|
|
|
|
|
|
this.form = res.data
|
2023-02-07 15:46:45 +08:00
|
|
|
|
this.form.pictureUrl = res.data.pictureUrl ? [{
|
|
|
|
|
|
url: res.data.pictureUrl
|
|
|
|
|
|
}] : []
|
2023-02-14 11:48:49 +08:00
|
|
|
|
this.form.videoUrl = res.data.videoUrl ? [{
|
|
|
|
|
|
url: res.data.videoUrl
|
|
|
|
|
|
}] : []
|
2023-02-07 13:36:02 +08:00
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
},
|
|
|
|
|
|
|
2023-02-07 15:46:45 +08:00
|
|
|
|
onChange () {
|
2023-02-14 11:48:49 +08:00
|
|
|
|
this.form.videoUrl = []
|
2023-02-07 13:36:02 +08:00
|
|
|
|
},
|
|
|
|
|
|
|
2023-02-07 15:46:45 +08:00
|
|
|
|
submitUpload(file) {
|
|
|
|
|
|
this.$refs['upload1']?.clearFiles();
|
|
|
|
|
|
this.$refs['upload2']?.clearFiles();
|
|
|
|
|
|
this.$refs['ruleForm']?.clearValidate('videoFile');
|
|
|
|
|
|
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]
|
2023-05-24 09:08:28 +08:00
|
|
|
|
// if (codec.indexOf('avc') === -1) {
|
|
|
|
|
|
// return this.$message.error("视频编码格式不支持")
|
|
|
|
|
|
// }
|
2023-02-07 15:46:45 +08:00
|
|
|
|
|
|
|
|
|
|
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.isLoading = true
|
2023-02-14 11:48:49 +08:00
|
|
|
|
this.instance.post(`/admin/file/addVideo1`, formData).then(res => {
|
2023-02-07 15:46:45 +08:00
|
|
|
|
if (res && res.data) {
|
2023-02-14 11:48:49 +08:00
|
|
|
|
let videoList = res.data[0].split(";")
|
|
|
|
|
|
this.form.duration = res.data[2]
|
2023-02-07 15:46:45 +08:00
|
|
|
|
|
2023-02-14 11:48:49 +08:00
|
|
|
|
this.form.videoUrl = [{
|
2023-02-07 15:46:45 +08:00
|
|
|
|
id: videoList[1],
|
|
|
|
|
|
url: videoList[0]
|
|
|
|
|
|
}]
|
2023-02-14 11:48:49 +08:00
|
|
|
|
this.form.pictureUrl = [{
|
|
|
|
|
|
id: res.data[1].split(";")[1],
|
|
|
|
|
|
url: res.data[1].split(";")[0]
|
|
|
|
|
|
}]
|
2023-02-07 15:46:45 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
this.isLoading = false
|
|
|
|
|
|
}).catch(() => {
|
|
|
|
|
|
this.isLoading = false
|
|
|
|
|
|
})
|
|
|
|
|
|
} else {
|
|
|
|
|
|
return this.$message.error("视频格式错误")
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2023-02-07 13:36:02 +08:00
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
confirm () {
|
|
|
|
|
|
this.$refs.form.validate((valid) => {
|
|
|
|
|
|
if (valid) {
|
2023-02-07 15:46:45 +08:00
|
|
|
|
this.isLoading = true
|
2023-02-14 11:48:49 +08:00
|
|
|
|
this.instance.post(`/app/appcourseinfo/addOrUpdate`, {
|
2023-02-07 13:36:02 +08:00
|
|
|
|
...this.form,
|
2023-02-14 11:48:49 +08:00
|
|
|
|
videoUrl: this.form.courseType === '1' ? this.form.videoUrl[0].url : '',
|
2023-02-07 15:46:45 +08:00
|
|
|
|
pictureUrl: this.form.pictureUrl.length ? this.form.pictureUrl[0].url : ''
|
2023-02-07 13:36:02 +08:00
|
|
|
|
}).then(res => {
|
|
|
|
|
|
if (res.code == 0) {
|
2023-02-14 11:48:49 +08:00
|
|
|
|
this.$message.success('提交成功')
|
2023-02-07 13:36:02 +08:00
|
|
|
|
setTimeout(() => {
|
|
|
|
|
|
this.cancel(true)
|
|
|
|
|
|
}, 600)
|
2023-02-07 15:46:45 +08:00
|
|
|
|
} else {
|
|
|
|
|
|
this.isLoading = false
|
2023-02-07 13:36:02 +08:00
|
|
|
|
}
|
2023-02-07 15:46:45 +08:00
|
|
|
|
}).catch(() => {
|
|
|
|
|
|
this.isLoading = false
|
2023-02-07 13:36:02 +08:00
|
|
|
|
})
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
cancel (isRefresh) {
|
|
|
|
|
|
this.$emit('change', {
|
|
|
|
|
|
type: 'List',
|
|
|
|
|
|
isRefresh: !!isRefresh
|
|
|
|
|
|
})
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
|
|
<style scoped lang="scss">
|
2023-02-07 15:46:45 +08:00
|
|
|
|
.content-add {
|
|
|
|
|
|
.video {
|
|
|
|
|
|
width: 640px;
|
|
|
|
|
|
height: 360px;
|
|
|
|
|
|
border-radius: 4px;
|
|
|
|
|
|
border: 1px dashed #D0D4DC;
|
|
|
|
|
|
display: flex;
|
|
|
|
|
|
flex-direction: column;
|
|
|
|
|
|
align-items: center;
|
|
|
|
|
|
justify-content: center;
|
2023-02-07 13:36:02 +08:00
|
|
|
|
|
2023-02-07 15:46:45 +08:00
|
|
|
|
.icon {
|
|
|
|
|
|
display: flex;
|
|
|
|
|
|
flex-direction: column;
|
|
|
|
|
|
align-items: center;
|
|
|
|
|
|
justify-content: center;
|
2023-02-07 13:36:02 +08:00
|
|
|
|
|
2023-02-07 15:46:45 +08:00
|
|
|
|
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;
|
|
|
|
|
|
}
|
2023-02-07 13:36:02 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2023-02-07 15:46:45 +08:00
|
|
|
|
.video-com {
|
|
|
|
|
|
width: 640px;
|
|
|
|
|
|
height: 360px;
|
|
|
|
|
|
background: rgba(0, 0, 0, 0.5);
|
|
|
|
|
|
border-radius: 2px;
|
|
|
|
|
|
border: 1px solid #D0D4DC;
|
|
|
|
|
|
margin-top: -40px;
|
2023-02-07 13:36:02 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
</style>
|