Files
dvcp_v2_webapp/packages/publicity/AppContentInfo/components/Add.vue

341 lines
12 KiB
Vue
Raw Normal View History

2021-12-18 17:16:42 +08:00
<template>
2022-03-28 13:54:21 +08:00
<ai-detail class="content-add" v-loading="isLoading">
2021-12-18 17:16:42 +08:00
<template slot="title">
2021-12-24 20:01:48 +08:00
<ai-title :title="params.id ? '编辑' + moduleName : '添加' + moduleName" isShowBack isShowBottomBorder @onBackClick="cancel(false)">
2021-12-18 17:16:42 +08:00
</ai-title>
</template>
<template slot="content">
<ai-card title="基本信息">
<template #content>
<el-form class="ai-form" :model="form" label-width="120px" ref="form">
<el-form-item label="标题" style="width: 100%;" prop="title" :rules="[{required: true, message: '请输入标题', trigger: 'blur'}]">
2021-12-22 13:45:41 +08:00
<el-input size="small" v-model="form.title" clearable placeholder="请输入..." :maxlength="50" :show-word-limit="true"></el-input>
2021-12-18 17:16:42 +08:00
</el-form-item>
<el-form-item prop="areaId" style="width: 100%;" label="发布地区" :rules="[{required: true, message: '请选择地区', trigger: 'change'}]">
<ai-area-select clearable @fullname="v => form.areaName = v" always-show :instance="instance" v-model="form.areaId" :disabled-level="disabledLevel"></ai-area-select>
</el-form-item>
<el-form-item prop="contentType" label="文章类型" :rules="[{required: true, message: '请选择文章类型', trigger: 'change'}]">
2021-12-23 18:05:46 +08:00
<el-select style="width: 100%;" @change="onChange" v-model="form.contentType" size="small" placeholder="请选择文章类型">
2021-12-18 17:16:42 +08:00
<el-option
v-for="item in contentTypeList"
:key="item.value"
:label="item.name"
:value="item.value">
</el-option>
</el-select>
</el-form-item>
2021-12-23 11:38:57 +08:00
<el-form-item prop="categoryId" label="分类" v-if="cateList.length" :rules="[{required: true, message: '请选择分类', trigger: 'change'}]">
2021-12-18 17:16:42 +08:00
<el-select style="width: 100%;" v-model="form.categoryId" size="small" placeholder="请选择分类">
<el-option
v-for="item in cateList"
:key="item.id"
:label="item.categoryName"
:value="item.id">
</el-option>
</el-select>
</el-form-item>
<el-form-item v-if="form.contentType === '0'" label="正文" prop="content" style="width: 100%;" :rules="[{required: true, message: '请输入内容', trigger: 'change'}]">
<ai-editor v-model="form.content" :instance="instance"/>
</el-form-item>
2022-01-20 15:25:16 +08:00
<el-form-item v-if="form.contentType === '0' && !isHideCoverimg" label="封面图片" prop="files" style="width: 100%;">
2021-12-18 17:16:42 +08:00
<ai-uploader
:instance="instance"
v-model="form.files"
2021-12-23 18:05:46 +08:00
key="file"
2021-12-18 17:16:42 +08:00
:limit="9">
2021-12-22 11:21:25 +08:00
<template slot="tips">
<p>最多上传9张图片,单个文件最大10MB支持jpgjpegpng格式</p>
</template>
2021-12-18 17:16:42 +08:00
</ai-uploader>
</el-form-item>
2021-12-22 15:37:01 +08:00
<el-form-item v-if="form.contentType === '1'" label="视频" prop="files" style="width: 100%;" :rules="[{required: true, message: '请上传视频', trigger: 'change'}]">
2021-12-23 18:05:46 +08:00
<el-upload :show-file-list="false" ref="upload1" action :http-request="submitUpload" :accept="accept" :limit="1">
<div class="video" v-if="!form.files.length">
<div class="icon">
<ai-icon type="svg" icon="iconVideo"/>
<span>上传视频</span>
</div>
<span class="tips">支持mp4格式单个文件最大100MB</span>
</div>
</el-upload>
<video class="video-com" style="width:100%; height:100%; object-fit: fill;" muted
:src="form.files[0].url" controls="controls" v-if="form.files.length"></video>
<el-upload :show-file-list="false" ref="upload2" action :http-request="submitUpload" :accept="accept"
:limit="1" v-if="form.files.length">
<el-button style="margin-top: 10px;">重新选择</el-button>
</el-upload>
2021-12-18 17:16:42 +08:00
</el-form-item>
2021-12-24 18:24:56 +08:00
<el-form-item label="视频封面" prop="pictureUrl" style="width: 100%;" v-if="form.contentType === '1'" :rules="[{required: true, message: '请上传视频封面', trigger: 'change'}]">
2021-12-24 18:20:18 +08:00
<ai-uploader
:instance="instance"
isShowTip
v-model="form.pictureUrl"
:limit="1"
:cropOps="cropOps"
is-crop>
<template slot="tips">
<p>最多上传1张图片,单个文件最大10MB支持jpgjpegpng格式</p>
<p>图片比例1.61</p>
</template>
</ai-uploader>
</el-form-item>
2021-12-18 17:16:42 +08:00
</el-form>
</template>
</ai-card>
</template>
<template #footer>
<el-button @click="cancel">取消</el-button>
2022-02-28 17:53:41 +08:00
<el-button type="primary" :loading="isLoading" @click="confirm">提交</el-button>
2021-12-18 17:16:42 +08:00
</template>
</ai-detail>
</template>
<script>
2021-12-23 18:05:46 +08:00
import mp4box from 'mp4box'
2021-12-18 17:16:42 +08:00
import { mapState } from 'vuex'
export default {
name: 'Add',
props: {
instance: Function,
dict: Object,
2021-12-24 20:01:48 +08:00
params: Object,
2022-03-18 13:47:30 +08:00
areaId: String,
2021-12-24 20:01:48 +08:00
moduleName: String
2021-12-18 17:16:42 +08:00
},
data () {
return {
info: {},
2021-12-23 18:05:46 +08:00
accept: '.mp4',
2021-12-18 17:16:42 +08:00
form: {
title: '',
content: '',
areaId: '',
files: [],
categoryId: '',
2021-12-24 18:24:56 +08:00
pictureUrl: [],
2021-12-18 17:16:42 +08:00
contentType: '0',
areaName: '',
thumbUrl: []
},
2022-02-28 17:53:41 +08:00
isLoading: false,
2021-12-24 18:24:56 +08:00
cropOps: {
width: "336px",
height: "210px"
},
2021-12-18 17:16:42 +08:00
id: '',
contentTypeList: [
{
name: '文章',
value: '0'
},
{
name: '视频',
value: '1'
}
],
2022-01-20 15:25:16 +08:00
isHideCoverimg: false,
2022-03-18 14:30:56 +08:00
cateList: [],
needExamine: '0'
2021-12-18 17:16:42 +08:00
}
},
computed: {
...mapState(['user'])
},
created () {
2022-01-20 15:25:16 +08:00
this.getModuleInfo()
2021-12-18 17:16:42 +08:00
this.getCateList()
2022-03-18 13:47:30 +08:00
this.form.areaId = this.areaId
2021-12-18 17:16:42 +08:00
this.disabledLevel = this.user.info.areaList.length
if (this.params && this.params.id) {
this.id = this.params.id
this.getInfo(this.params.id)
}
},
methods: {
getInfo (id) {
this.instance.post(`/app/appcontentinfo/queryDetailById?id=${id}`).then(res => {
if (res.code === 0) {
this.form = res.data
2021-12-24 18:20:18 +08:00
this.form.pictureUrl = res.data.pictureUrl ? [{
url: res.data.pictureUrl
}] : []
2021-12-18 17:16:42 +08:00
}
})
},
2022-01-20 15:25:16 +08:00
getModuleInfo () {
this.instance.post(`/app/appcontentmoduleinfo/queryDetailById?id=${this.$route.query.moduleId}`).then(res => {
if (res.code === 0) {
this.isHideCoverimg = res.data.styleType === '0'
2022-03-18 14:30:56 +08:00
this.needExamine = res.data.needExamine
2022-01-20 15:25:16 +08:00
}
})
},
2021-12-23 18:05:46 +08:00
onChange () {
this.form.files = []
},
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-23 12:41:52 +00:00
if (!/(avc|hevc)/.test(codec)) {
2021-12-23 18:05:46 +08:00
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);
2022-03-28 13:54:21 +08:00
this.isLoading = true
2021-12-23 18:05:46 +08:00
this.instance.post(`/admin/file/add-unlimited`, formData).then(res => {
if (res && res.data) {
let videoList = res.data[0].split(";");
this.form.files = [{
id: videoList[1],
url: videoList[0]
}]
}
2022-03-28 13:54:21 +08:00
this.isLoading = false
}).catch(() => {
this.isLoading = false
2021-12-23 18:05:46 +08:00
})
} else {
return this.$message.error("视频格式错误")
}
}
},
2021-12-18 17:16:42 +08:00
getCateList () {
this.instance.post(`/app/appcontentmodulecategory/list`, null, {
params: {
...this.cateSearch,
2021-12-22 11:14:42 +08:00
moduleId: this.$route.query.moduleId,
2021-12-18 17:16:42 +08:00
size: 100
}
}).then(res => {
if (res.code == 0) {
this.cateList = res.data.records
}
})
},
confirm () {
this.$refs.form.validate((valid) => {
if (valid) {
2021-12-23 11:38:57 +08:00
let categoryName = ''
if (this.cateList.length && this.form.categoryId) {
categoryName = this.cateList.filter(v => v.id === this.form.categoryId)[0].categoryName
}
2022-02-28 17:53:41 +08:00
this.isLoading = true
2021-12-18 17:16:42 +08:00
this.instance.post(`/app/appcontentinfo/addOrUpdate`, {
...this.form,
2021-12-22 11:14:42 +08:00
moduleId: this.$route.query.moduleId,
2021-12-18 17:16:42 +08:00
createUserName: this.user.info.name,
createUserId: this.user.info.id,
2021-12-24 18:20:18 +08:00
categoryName: categoryName,
pictureUrl: this.form.pictureUrl.length ? this.form.pictureUrl[0].url : ''
2021-12-18 17:16:42 +08:00
}).then(res => {
if (res.code == 0) {
2022-03-18 14:30:56 +08:00
if (this.needExamine === '1') {
this.$message.success('提交成功,等待管理员审核')
} else {
this.$message.success('提交成功')
}
2021-12-18 17:16:42 +08:00
setTimeout(() => {
this.cancel(true)
}, 600)
2022-02-28 17:53:41 +08:00
} else {
this.isLoading = false
2021-12-18 17:16:42 +08:00
}
2022-02-28 17:53:41 +08:00
}).catch(() => {
this.isLoading = false
2021-12-18 17:16:42 +08:00
})
}
})
},
cancel (isRefresh) {
this.$emit('change', {
2022-03-18 13:47:30 +08:00
type: 'List',
2021-12-18 17:16:42 +08:00
isRefresh: !!isRefresh
})
}
}
}
</script>
<style scoped lang="scss">
2021-12-23 18:05:46 +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;
.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;
}
}
.video-com {
width: 640px;
height: 360px;
background: rgba(0, 0, 0, 0.5);
border-radius: 2px;
border: 1px solid #D0D4DC;
margin-top: -40px;
}
}
2021-12-18 17:16:42 +08:00
</style>