2022-02-25 17:27:11 +08:00
|
|
|
|
<template>
|
|
|
|
|
|
<ai-detail class="add-article">
|
|
|
|
|
|
<template slot="title">
|
2022-02-28 16:25:36 +08:00
|
|
|
|
<ai-title :title="isEdit?'编辑新闻':'发布新闻'" :isShowBack="true" :isShowBottomBorder="true"
|
2022-02-25 17:27:11 +08:00
|
|
|
|
@onBackClick="$emit('goBack')"></ai-title>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
<template slot="content">
|
2022-02-28 16:25:36 +08:00
|
|
|
|
<ai-card title="发布新闻">
|
2022-02-25 17:27:11 +08:00
|
|
|
|
<template #content>
|
|
|
|
|
|
<el-form ref="ruleForm" :model="articInfo" :rules="rules" label-width="120px" label-position="right">
|
|
|
|
|
|
<el-form-item prop="title" label="标题:">
|
|
|
|
|
|
<el-input v-model="articInfo.title" size="small" placeholder="请输入…" maxlength="30"
|
|
|
|
|
|
show-word-limit></el-input>
|
|
|
|
|
|
</el-form-item>
|
2022-02-28 16:25:36 +08:00
|
|
|
|
<el-form-item prop="description" label="摘要:">
|
|
|
|
|
|
<el-input type="textarea" v-model="articInfo.description" size="small" placeholder="请输入…" maxlength="255"
|
|
|
|
|
|
show-word-limit></el-input>
|
|
|
|
|
|
</el-form-item>
|
|
|
|
|
|
<el-form-item prop="category" label="分类:">
|
2022-02-25 17:27:11 +08:00
|
|
|
|
<ai-select
|
2022-02-28 16:25:36 +08:00
|
|
|
|
v-model="articInfo.category"
|
|
|
|
|
|
placeholder="选择新闻分类"
|
|
|
|
|
|
:selectList="dict.getDict('appNewsCategory')">
|
2022-02-25 17:27:11 +08:00
|
|
|
|
</ai-select>
|
|
|
|
|
|
</el-form-item>
|
|
|
|
|
|
<el-form-item prop="content" label="正文:">
|
|
|
|
|
|
<ai-editor v-model="articInfo.content" :instance="instance"/>
|
|
|
|
|
|
</el-form-item>
|
2022-02-28 16:25:36 +08:00
|
|
|
|
<el-form-item prop="thumbUrl" label="封面:">
|
|
|
|
|
|
<ai-uploader :instance="instance" v-model="articInfo.thumbUrl" :limit="1" :isShowTip="true"
|
|
|
|
|
|
@change="$refs['ruleForm'].clearValidate('thumbUrl')" :cropOps="cropOps" is-crop>
|
2022-02-25 17:27:11 +08:00
|
|
|
|
<template slot="tips">最多上传1张图片,单个文件最大10MB,支持jpg、jpeg、png<br/>格式图片比例:1.6:1</template>
|
|
|
|
|
|
</ai-uploader>
|
|
|
|
|
|
</el-form-item>
|
|
|
|
|
|
</el-form>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
</ai-card>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
<template slot="footer">
|
|
|
|
|
|
<el-button class="footer_btn" @click="$emit('goBack')">取消</el-button>
|
|
|
|
|
|
<el-button class="footer_btn" @click="handleSubmit('0')">保存</el-button>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
</ai-detail>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
|
|
<script>
|
|
|
|
|
|
export default {
|
|
|
|
|
|
name: "addArticle",
|
|
|
|
|
|
props: {
|
|
|
|
|
|
instance: Function,
|
|
|
|
|
|
dict: Object,
|
|
|
|
|
|
permissions: Function,
|
|
|
|
|
|
detail: Object,
|
|
|
|
|
|
},
|
|
|
|
|
|
data() {
|
|
|
|
|
|
return {
|
|
|
|
|
|
articInfo: {
|
2022-02-28 16:25:36 +08:00
|
|
|
|
id: "",
|
2022-02-25 17:27:11 +08:00
|
|
|
|
title: "",
|
|
|
|
|
|
content: "",
|
2022-02-28 16:25:36 +08:00
|
|
|
|
description: "",
|
|
|
|
|
|
category: '',
|
|
|
|
|
|
thumbUrl: '',
|
2022-02-25 17:27:11 +08:00
|
|
|
|
},
|
|
|
|
|
|
rules: {
|
|
|
|
|
|
title: {required: true, message: '请输入标题', trigger: 'blur'},
|
2022-02-28 16:25:36 +08:00
|
|
|
|
description: {required: true, message: '请输入摘要', trigger: 'blur'},
|
|
|
|
|
|
category: {required: true, message: '请选择分类', trigger: 'change'},
|
2022-02-25 17:27:11 +08:00
|
|
|
|
content: {required: true, message: '请填写内容', trigger: 'blur'},
|
2022-02-28 16:25:36 +08:00
|
|
|
|
thumbUrl: {required: true, message: '请上传封面', trigger: 'blur'},
|
2022-02-25 17:27:11 +08:00
|
|
|
|
},
|
|
|
|
|
|
cropOps: {
|
|
|
|
|
|
fixedNumber: [1.8, 1],
|
|
|
|
|
|
fixed: true
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
computed: {
|
|
|
|
|
|
isEdit() {
|
|
|
|
|
|
return !!this.$route.query.id;
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
methods: {
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 发布、保存新闻
|
|
|
|
|
|
* @param status
|
|
|
|
|
|
*/
|
|
|
|
|
|
handleSubmit(status) {
|
|
|
|
|
|
this.$refs["ruleForm"].validate(valid => {
|
|
|
|
|
|
if (valid) {
|
|
|
|
|
|
this.addOrUpdate(status);
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 新增、修改
|
|
|
|
|
|
* */
|
|
|
|
|
|
addOrUpdate(status) {
|
2022-02-28 16:25:36 +08:00
|
|
|
|
if (Array.isArray(this.articInfo.thumbUrl)) {
|
|
|
|
|
|
this.articInfo.thumbUrl = this.articInfo.thumbUrl[0].url
|
|
|
|
|
|
}
|
2022-02-25 17:27:11 +08:00
|
|
|
|
const msg = +status ? '发布成功' : this.isEdit ? '编辑成功' : '保存成功';
|
2022-02-28 16:25:36 +08:00
|
|
|
|
this.instance.post(`/app/appnews/addOrUpdate`, {
|
2022-02-25 17:27:11 +08:00
|
|
|
|
...this.articInfo,
|
2022-02-28 16:25:36 +08:00
|
|
|
|
thumbUrl: this.articInfo.thumbUrl,
|
|
|
|
|
|
category: this.articInfo.category,
|
2022-02-25 17:27:11 +08:00
|
|
|
|
type: 0,
|
2022-02-28 16:25:36 +08:00
|
|
|
|
id: this.articInfo.id,
|
|
|
|
|
|
status: this.articInfo.status
|
2022-02-25 17:27:11 +08:00
|
|
|
|
}).then(res => {
|
|
|
|
|
|
if (res.code == 0) {
|
|
|
|
|
|
this.$message.success(msg);
|
|
|
|
|
|
this.$emit("goBack");
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 根据id查询详情
|
|
|
|
|
|
*/
|
|
|
|
|
|
getDetail() {
|
|
|
|
|
|
let {id} = this.$route.query
|
2022-02-28 16:25:36 +08:00
|
|
|
|
id && this.instance.post(`/app/appnews/getById`, null, {
|
2022-02-25 17:27:11 +08:00
|
|
|
|
params: {id}
|
|
|
|
|
|
}).then(res => {
|
|
|
|
|
|
if (res?.data) {
|
|
|
|
|
|
this.articInfo = res.data
|
2022-02-28 16:25:36 +08:00
|
|
|
|
this.articInfo.id = res.data.id
|
2022-02-25 17:27:11 +08:00
|
|
|
|
this.articInfo.title = res.data.title;
|
|
|
|
|
|
this.articInfo.content = res.data.content;
|
2022-02-28 16:25:36 +08:00
|
|
|
|
this.articInfo.category = res.data.category
|
|
|
|
|
|
this.articInfo.thumbUrl = [{url: res.data.thumbUrl}]
|
2022-02-25 17:27:11 +08:00
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
created() {
|
|
|
|
|
|
if (this.isEdit) {
|
|
|
|
|
|
this.getDetail();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
|
|
|
.add-article {
|
|
|
|
|
|
height: 100%;
|
|
|
|
|
|
overflow: auto;
|
|
|
|
|
|
background: #F3F6F9;
|
|
|
|
|
|
|
|
|
|
|
|
.footer_btn {
|
|
|
|
|
|
width: 106px;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
</style>
|