|
|
|
@ -1,6 +1,15 @@ |
|
|
|
|
<template> |
|
|
|
|
<div> |
|
|
|
|
<el-card shadow="hover" class="mgb20"> |
|
|
|
|
<div class="flex-between"> |
|
|
|
|
<div class="per_title" v-preventReClick @click="back"> |
|
|
|
|
<i class="el-icon-arrow-left"></i> |
|
|
|
|
<span class="per_back">返回</span> |
|
|
|
|
<span class="per_school" v-text="form.id ? '编辑文章' : '新建文章'"></span> |
|
|
|
|
</div> |
|
|
|
|
</div> |
|
|
|
|
</el-card> |
|
|
|
|
<div class="page"> |
|
|
|
|
<p class="page-name mb">文章详情</p> |
|
|
|
|
<el-form :model="form" :rules="rules" class="input-form model" label-width="140px"> |
|
|
|
|
<el-form-item prop="title" label="标题"> |
|
|
|
|
<el-input |
|
|
|
@ -139,6 +148,7 @@ |
|
|
|
|
<el-button @click="submit(0)">保存草稿</el-button> |
|
|
|
|
<el-button @click="back">取消</el-button> |
|
|
|
|
</div> |
|
|
|
|
</div> |
|
|
|
|
<!-- 剪裁组件弹窗 --> |
|
|
|
|
<el-dialog title="图片裁剪" append-to-body :visible.sync="cropperModel" width="1100px" :close-on-click-modal="false"> |
|
|
|
|
<Cropper |
|
|
|
@ -258,9 +268,9 @@ export default { |
|
|
|
|
releaseTime: [ |
|
|
|
|
{ required: true, message: '请选择发布日期', trigger: 'change' } |
|
|
|
|
], |
|
|
|
|
// bannerImg: [ |
|
|
|
|
// { required: true, message: '请上传封面图', trigger: 'change' } |
|
|
|
|
// ], |
|
|
|
|
bannerImg: [ |
|
|
|
|
{ required: true, message: '请上传封面图', trigger: 'change' } |
|
|
|
|
], |
|
|
|
|
mainBody: [ |
|
|
|
|
{ required: true, message: '请输入正文', trigger: 'blur' } |
|
|
|
|
], |
|
|
|
@ -299,12 +309,13 @@ export default { |
|
|
|
|
next() |
|
|
|
|
} else if (!this.pass) { |
|
|
|
|
// 更改了信息才需要提示 |
|
|
|
|
if (this.updateTime > 1) { |
|
|
|
|
if (this.updateTime) { |
|
|
|
|
this.$confirm(`所填写内容暂未保存,是否保存?`, '提示', { |
|
|
|
|
type: 'warning' |
|
|
|
|
}).then(() => { |
|
|
|
|
this.submit(this.form.isRelease, next) |
|
|
|
|
}).catch(() => { |
|
|
|
|
console.log(55) |
|
|
|
|
next() |
|
|
|
|
}) |
|
|
|
|
} else { |
|
|
|
@ -317,21 +328,30 @@ export default { |
|
|
|
|
mounted() { |
|
|
|
|
this.getArticle() |
|
|
|
|
this.getLabel() |
|
|
|
|
this.getClassification() |
|
|
|
|
}, |
|
|
|
|
methods: { |
|
|
|
|
// 文章列表 |
|
|
|
|
// 文章详情 |
|
|
|
|
getArticle() { |
|
|
|
|
const { id } = this.form |
|
|
|
|
id && this.$post(`${this.api.findByIdParnerArticle}?id=${id}`).then(({ data }) => { |
|
|
|
|
data.lableId = data.lableId ? data.lableId.split(',').map(e => +e) : [] |
|
|
|
|
data.fileList.forEach(e => e.name = e.fileName) |
|
|
|
|
this.form = data |
|
|
|
|
this.getClassification(1) |
|
|
|
|
}).catch(err => {}) |
|
|
|
|
}, |
|
|
|
|
// 获取所属分类 |
|
|
|
|
getClassification() { |
|
|
|
|
getClassification(detail) { |
|
|
|
|
this.$post(`${this.api.queryClassificationByType}?typeId=${this.typeId}`).then(({ data }) => { |
|
|
|
|
this.classifications = data |
|
|
|
|
// 如果所选分类被删除,则清空分类id |
|
|
|
|
if (detail) { |
|
|
|
|
const id = this.form.classificationId |
|
|
|
|
if (!data.find(e => e.id == id)) this.form.classificationId = '' |
|
|
|
|
setTimeout(() => { |
|
|
|
|
this.updateTime = 0 |
|
|
|
|
}, 500) |
|
|
|
|
} |
|
|
|
|
}).catch(err => {}) |
|
|
|
|
}, |
|
|
|
|
// 显示所属分类弹框 |
|
|
|
@ -396,9 +416,10 @@ export default { |
|
|
|
|
} else { |
|
|
|
|
this.classVisible = false |
|
|
|
|
} |
|
|
|
|
// 所选的分类被删了后,要清空所选的分类id |
|
|
|
|
if (!list.find(e => e.id == this.form.classificationId)) this.form.classificationId = '' |
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 获取标签 |
|
|
|
|
getLabel() { |
|
|
|
|
this.$post(this.api.queryAllArticleSubjectTags).then(({ data }) => { |
|
|
|
@ -443,8 +464,6 @@ export default { |
|
|
|
|
this.$post(this.api[row.id ? 'updateParnerLabel' : 'saveParnerLabel'], { |
|
|
|
|
labelName: row.labelName, |
|
|
|
|
id: row.id, |
|
|
|
|
// editorId: this.userId, |
|
|
|
|
// founderId: this.userId |
|
|
|
|
}).then(res => { |
|
|
|
|
showMsg && Util.successMsg((row.id ? '修改' : '新增') + '成功') |
|
|
|
|
this.getLabel() |
|
|
|
@ -573,7 +592,7 @@ export default { |
|
|
|
|
}, |
|
|
|
|
// 附件删除 |
|
|
|
|
handleRemove(e, fileList) { |
|
|
|
|
e.id ? this.$post(`${this.api.delContentFile}?id=${e.id}`).then(res => { |
|
|
|
|
e.id ? this.$post(`${this.api.batchDeletionParnerFile}?ids=${e.id}`).then(res => { |
|
|
|
|
this.form.fileList = fileList |
|
|
|
|
}).catch(res => {}) : (this.form.fileList = fileList) |
|
|
|
|
}, |
|
|
|
@ -620,9 +639,8 @@ export default { |
|
|
|
|
// 返回 |
|
|
|
|
back() { |
|
|
|
|
this.pass = true |
|
|
|
|
const { updateTime } = this |
|
|
|
|
// 更改了信息才需要提示 |
|
|
|
|
if (updateTime > 1) { |
|
|
|
|
if (this.updateTime) { |
|
|
|
|
this.$confirm(`所填写内容暂未保存,是否保存?`, '提示', { |
|
|
|
|
type: 'warning' |
|
|
|
|
}).then(() => { |
|
|
|
@ -634,17 +652,6 @@ export default { |
|
|
|
|
this.$router.back() |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
// 更新附件的状态为发布 |
|
|
|
|
updateFile(files, form, quoteId) { |
|
|
|
|
files.map(e => { |
|
|
|
|
this.$post(this.api.updateFile, { |
|
|
|
|
id: e, |
|
|
|
|
isRelease: form.isRelease, |
|
|
|
|
quote: form.title, |
|
|
|
|
quoteId |
|
|
|
|
}).then(res => {}).catch(err => {}) |
|
|
|
|
}) |
|
|
|
|
}, |
|
|
|
|
// 提交 |
|
|
|
|
submit(isRelease, next) { |
|
|
|
|
if (this.submiting) return false |
|
|
|
@ -653,18 +660,12 @@ export default { |
|
|
|
|
if (this.nameRepeat) return Util.errorMsg('该标题已重复!') |
|
|
|
|
// 如果是发布 |
|
|
|
|
if (isRelease) { |
|
|
|
|
// if (!form.releaseTime) return Util.errorMsg('请选择发布日期') |
|
|
|
|
// if (!form.bannerImg ) return Util.errorMsg('请上传封面') |
|
|
|
|
// if (!form.mainBody) return Util.errorMsg('请输入正文') |
|
|
|
|
if (!form.releaseTime) return Util.errorMsg('请选择发布日期') |
|
|
|
|
if (!form.classificationId) return Util.errorMsg('请选择所属分类') |
|
|
|
|
if (!form.bannerImg ) return Util.errorMsg('请上传封面') |
|
|
|
|
if (!form.mainBody) return Util.errorMsg('请输入正文') |
|
|
|
|
} |
|
|
|
|
// if (this.uploading) return Util.errorMsg('文件正在上传,请上传完成后再发布') |
|
|
|
|
const { fileList, bannerImg } = form |
|
|
|
|
const fileId = [] |
|
|
|
|
// 获取几个附件的id,url后面的数字串即是附件id |
|
|
|
|
if (bannerImg) fileId.push(bannerImg.substr(bannerImg.lastIndexOf('/') + 1)) |
|
|
|
|
fileList && fileList.map(e => { |
|
|
|
|
fileId.push(e[e.url ? 'url' : 'filePath'].substr(e[e.url ? 'url' : 'filePath'].lastIndexOf('/') + 1)) |
|
|
|
|
}) |
|
|
|
|
form.lableId = form.lableId.join(',') |
|
|
|
|
|
|
|
|
|
form.releaseTime = Util.formatDate('yyyy-MM-dd', new Date(form.releaseTime)) // 发布日期转化为年月日格式 |
|
|
|
@ -674,7 +675,6 @@ export default { |
|
|
|
|
if (form.id) { |
|
|
|
|
delete form.children |
|
|
|
|
this.$post(this.api.updateParnerArticle, form).then(res => { |
|
|
|
|
// this.updateFile(fileId, form, form.id) |
|
|
|
|
Util.successMsg('修改成功') |
|
|
|
|
next ? next() : this.$router.back() |
|
|
|
|
}).catch(err => { |
|
|
|
@ -682,18 +682,6 @@ export default { |
|
|
|
|
}) |
|
|
|
|
} else { |
|
|
|
|
this.$post(this.api.saveParnerArticle, form).then(({ data }) => { |
|
|
|
|
this.updateFile(fileId, form, data) |
|
|
|
|
// 新增文章完后需要把上传的附件添加到文章附件表 |
|
|
|
|
// form.fileList.map(e => { |
|
|
|
|
// this.$post(this.api.saveContentFile, { |
|
|
|
|
// contentId: data, |
|
|
|
|
// editorId: this.userId, |
|
|
|
|
// founderId: this.userId, |
|
|
|
|
// id: '', |
|
|
|
|
// fileName: e.name, |
|
|
|
|
// filePath: e.url |
|
|
|
|
// }).then(res => {}).catch(err => {}) |
|
|
|
|
// }) |
|
|
|
|
Util.successMsg('创建成功') |
|
|
|
|
next ? next() : this.$router.back() |
|
|
|
|
}).catch(err => { |
|
|
|
@ -829,7 +817,7 @@ $upload-lg-height: 102px; |
|
|
|
|
} |
|
|
|
|
.input-form { |
|
|
|
|
&.model { |
|
|
|
|
height: calc(100vh - 250px); |
|
|
|
|
height: calc(100vh - 340px); |
|
|
|
|
padding-right: 20px; |
|
|
|
|
overflow: auto; |
|
|
|
|
.el-form-item__label { |
|
|
|
|