|
|
@ -1,211 +1,238 @@ |
|
|
|
<template> |
|
|
|
<template> |
|
|
|
<div> |
|
|
|
<div> |
|
|
|
<el-card shadow="hover" class="m-b-20"> |
|
|
|
<el-card shadow="hover" |
|
|
|
<div class="flex-between"> |
|
|
|
class="m-b-20"> |
|
|
|
<el-page-header @back="goBack" :content="'新增文章'"></el-page-header> |
|
|
|
<div class="flex-between"> |
|
|
|
|
|
|
|
<el-page-header @back="goBack" |
|
|
|
|
|
|
|
:content="'新增文章'"></el-page-header> |
|
|
|
|
|
|
|
</div> |
|
|
|
|
|
|
|
</el-card> |
|
|
|
|
|
|
|
<el-card shadow="hover" |
|
|
|
|
|
|
|
class="m-b-20"> |
|
|
|
|
|
|
|
<el-form :model="form" |
|
|
|
|
|
|
|
:rules="rules" |
|
|
|
|
|
|
|
ref="form" |
|
|
|
|
|
|
|
label-width="90px" |
|
|
|
|
|
|
|
label-suffix=":" |
|
|
|
|
|
|
|
size="small"> |
|
|
|
|
|
|
|
<el-form-item prop="coverUrl" |
|
|
|
|
|
|
|
label="封面图"> |
|
|
|
|
|
|
|
<el-upload class="avatar-uploader" |
|
|
|
|
|
|
|
accept=".jpg,.png,.jpeg" |
|
|
|
|
|
|
|
:on-remove="handleRemove" |
|
|
|
|
|
|
|
:on-error="uploadError" |
|
|
|
|
|
|
|
:before-remove="beforeRemove" |
|
|
|
|
|
|
|
:limit="1" |
|
|
|
|
|
|
|
:on-exceed="handleExceed" |
|
|
|
|
|
|
|
action="" |
|
|
|
|
|
|
|
:http-request="handleRequest"> |
|
|
|
|
|
|
|
<img v-if="form.coverUrl" |
|
|
|
|
|
|
|
:src="form.coverUrl" |
|
|
|
|
|
|
|
class="avatar"> |
|
|
|
|
|
|
|
<div class="uploader-default" |
|
|
|
|
|
|
|
v-else> |
|
|
|
|
|
|
|
<i class="el-icon-plus"></i> |
|
|
|
|
|
|
|
<p>上传封面</p> |
|
|
|
</div> |
|
|
|
</div> |
|
|
|
</el-card> |
|
|
|
</el-upload> |
|
|
|
<el-card shadow="hover" class="m-b-20"> |
|
|
|
</el-form-item> |
|
|
|
<el-form :model="form" :rules="rules" ref="form" label-width="90px" label-suffix=":" size="small"> |
|
|
|
<el-form-item prop="author" |
|
|
|
<el-form-item prop="coverUrl" label="封面图"> |
|
|
|
label="作者"> |
|
|
|
<el-upload |
|
|
|
<div class="d-inline-block"> |
|
|
|
class="avatar-uploader" |
|
|
|
<el-input placeholder="请输入作者" |
|
|
|
accept=".jpg,.png,.jpeg" |
|
|
|
v-model="form.author" |
|
|
|
:on-remove="handleRemove" |
|
|
|
clearable></el-input> |
|
|
|
:on-error="uploadError" |
|
|
|
</div> |
|
|
|
:on-success="uploadSuccess" |
|
|
|
</el-form-item> |
|
|
|
:before-remove="beforeRemove" |
|
|
|
<el-form-item prop="date" |
|
|
|
:limit="1" |
|
|
|
label="日期"> |
|
|
|
:on-exceed="handleExceed" |
|
|
|
<div class="d-inline-block"> |
|
|
|
:action="this.api.fileupload" |
|
|
|
<el-date-picker v-model="form.date" |
|
|
|
:headers="headers" |
|
|
|
type="date" |
|
|
|
name="file" |
|
|
|
value-format="yyyy-MM-dd HH:mm:ss" |
|
|
|
> |
|
|
|
placeholder="选择日期"></el-date-picker> |
|
|
|
<img v-if="form.coverUrl" :src="form.coverUrl" class="avatar"> |
|
|
|
</div> |
|
|
|
<div class="uploader-default" v-else> |
|
|
|
</el-form-item> |
|
|
|
<i class="el-icon-plus"></i> |
|
|
|
<el-form-item prop="title" |
|
|
|
<p>上传封面</p> |
|
|
|
label="文章标题"> |
|
|
|
</div> |
|
|
|
<el-input placeholder="请输入文章标题" |
|
|
|
</el-upload> |
|
|
|
v-model="form.title" |
|
|
|
</el-form-item> |
|
|
|
clearable></el-input> |
|
|
|
<el-form-item prop="author" label="作者"> |
|
|
|
</el-form-item> |
|
|
|
<div class="d-inline-block"> |
|
|
|
<el-form-item prop="content" |
|
|
|
<el-input placeholder="请输入作者" v-model="form.author" clearable></el-input> |
|
|
|
label="文章内容"> |
|
|
|
</div> |
|
|
|
<quill :border="true" |
|
|
|
</el-form-item> |
|
|
|
v-model="form.content" |
|
|
|
<el-form-item prop="date" label="日期"> |
|
|
|
:uploading.sync="uploading" |
|
|
|
<div class="d-inline-block"> |
|
|
|
:height="400" /> |
|
|
|
<el-date-picker v-model="form.date" type="date" value-format="yyyy-MM-dd HH:mm:ss" placeholder="选择日期"></el-date-picker> |
|
|
|
</el-form-item> |
|
|
|
</div> |
|
|
|
<el-form-item> |
|
|
|
</el-form-item> |
|
|
|
<el-button type="primary" |
|
|
|
<el-form-item prop="title" label="文章标题"> |
|
|
|
@click="saveData">确定</el-button> |
|
|
|
<el-input placeholder="请输入文章标题" v-model="form.title" clearable></el-input> |
|
|
|
</el-form-item> |
|
|
|
</el-form-item> |
|
|
|
</el-form> |
|
|
|
<el-form-item prop="content" label="文章内容"> |
|
|
|
</el-card> |
|
|
|
<quill :border="true" v-model="form.content" :uploading.sync="uploading" :height="400" /> |
|
|
|
</div> |
|
|
|
</el-form-item> |
|
|
|
|
|
|
|
<el-form-item> |
|
|
|
|
|
|
|
<el-button type="primary" @click="saveData">确定</el-button> |
|
|
|
|
|
|
|
</el-form-item> |
|
|
|
|
|
|
|
</el-form> |
|
|
|
|
|
|
|
</el-card> |
|
|
|
|
|
|
|
</div> |
|
|
|
|
|
|
|
</template> |
|
|
|
</template> |
|
|
|
|
|
|
|
|
|
|
|
<script> |
|
|
|
<script> |
|
|
|
|
|
|
|
import Oss from '@/components/upload/upload.js' |
|
|
|
import quill from "@/components/quill"; |
|
|
|
import quill from "@/components/quill"; |
|
|
|
import util from "@/libs/util"; |
|
|
|
import util from "@/libs/util"; |
|
|
|
export default { |
|
|
|
export default { |
|
|
|
name: "addarticle", |
|
|
|
name: "addarticle", |
|
|
|
data() { |
|
|
|
data () { |
|
|
|
return { |
|
|
|
return { |
|
|
|
headers: { |
|
|
|
headers: { |
|
|
|
token: sessionStorage.getItem('token') |
|
|
|
token: sessionStorage.getItem('token') |
|
|
|
}, |
|
|
|
}, |
|
|
|
form: { |
|
|
|
form: { |
|
|
|
columnId: +this.$route.query.columnId, |
|
|
|
columnId: +this.$route.query.columnId, |
|
|
|
sort: +this.$route.query.sort, |
|
|
|
sort: +this.$route.query.sort, |
|
|
|
id: '', |
|
|
|
id: '', |
|
|
|
coverUrl: '', |
|
|
|
coverUrl: '', |
|
|
|
author: '', |
|
|
|
author: '', |
|
|
|
date: '', |
|
|
|
date: '', |
|
|
|
title: '', |
|
|
|
title: '', |
|
|
|
content: '', |
|
|
|
content: '', |
|
|
|
createUser: this.$store.state.userName |
|
|
|
createUser: this.$store.state.userName |
|
|
|
}, |
|
|
|
}, |
|
|
|
rules: { |
|
|
|
rules: { |
|
|
|
coverUrl: [ |
|
|
|
coverUrl: [ |
|
|
|
{ required: true, message: '请上传封面', trigger: 'change' } |
|
|
|
{ required: true, message: '请上传封面', trigger: 'change' } |
|
|
|
], |
|
|
|
], |
|
|
|
author: [ |
|
|
|
author: [ |
|
|
|
{ required: true, message: '请输入作者', trigger: 'blur' } |
|
|
|
{ required: true, message: '请输入作者', trigger: 'blur' } |
|
|
|
], |
|
|
|
], |
|
|
|
date: [ |
|
|
|
date: [ |
|
|
|
{ required: true, message: '请选择日期', trigger: 'change' } |
|
|
|
{ required: true, message: '请选择日期', trigger: 'change' } |
|
|
|
], |
|
|
|
], |
|
|
|
title: [ |
|
|
|
title: [ |
|
|
|
{ required: true, message: '请输入文章标题', trigger: 'blur' } |
|
|
|
{ required: true, message: '请输入文章标题', trigger: 'blur' } |
|
|
|
], |
|
|
|
], |
|
|
|
content: [ |
|
|
|
content: [ |
|
|
|
{ required: true, message: '请输入文章内容', trigger: 'blur' } |
|
|
|
{ required: true, message: '请输入文章内容', trigger: 'blur' } |
|
|
|
], |
|
|
|
], |
|
|
|
}, |
|
|
|
}, |
|
|
|
uploadList: [], |
|
|
|
uploadList: [], |
|
|
|
uploadDataList: [], |
|
|
|
uploadDataList: [], |
|
|
|
submiting: false, |
|
|
|
submiting: false, |
|
|
|
uploading: false |
|
|
|
uploading: false |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
components: { |
|
|
|
|
|
|
|
quill |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
mounted () { |
|
|
|
|
|
|
|
this.id = this.$route.query.id; |
|
|
|
|
|
|
|
this.id && this.getData(); |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
methods: { |
|
|
|
|
|
|
|
// 返回 |
|
|
|
|
|
|
|
goBack () { |
|
|
|
|
|
|
|
this.$router.back(); |
|
|
|
}, |
|
|
|
}, |
|
|
|
components: { |
|
|
|
getData () { |
|
|
|
quill |
|
|
|
this.$get(`${this.api.getArticle}?articleId=${this.id}`).then(({ article }) => { |
|
|
|
|
|
|
|
this.form = article |
|
|
|
|
|
|
|
}).catch(err => { }) |
|
|
|
}, |
|
|
|
}, |
|
|
|
mounted() { |
|
|
|
saveData () { |
|
|
|
this.id = this.$route.query.id; |
|
|
|
this.$refs.form.validate((valid) => { |
|
|
|
this.id && this.getData(); |
|
|
|
if (valid) { |
|
|
|
}, |
|
|
|
if (this.submiting) return false |
|
|
|
methods: { |
|
|
|
const { form } = this |
|
|
|
// 返回 |
|
|
|
if (this.uploading) return util.warningMsg("图片正在上传中,请稍等"); |
|
|
|
goBack() { |
|
|
|
this.submiting = true |
|
|
|
this.$router.back(); |
|
|
|
if (form.id) { |
|
|
|
}, |
|
|
|
this.$put(this.api.editArticle, form).then(res => { |
|
|
|
getData() { |
|
|
|
this.submiting = false; |
|
|
|
this.$get(`${this.api.getArticle}?articleId=${this.id}`).then(({ article }) => { |
|
|
|
util.successMsg("修改成功"); |
|
|
|
this.form = article |
|
|
|
this.back(); |
|
|
|
}).catch(err => {}) |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
saveData() { |
|
|
|
|
|
|
|
this.$refs.form.validate((valid) => { |
|
|
|
|
|
|
|
if (valid) { |
|
|
|
|
|
|
|
if (this.submiting) return false |
|
|
|
|
|
|
|
const { form } = this |
|
|
|
|
|
|
|
if (this.uploading) return util.warningMsg("图片正在上传中,请稍等"); |
|
|
|
|
|
|
|
this.submiting = true |
|
|
|
|
|
|
|
if (form.id) { |
|
|
|
|
|
|
|
this.$put(this.api.editArticle, form).then(res => { |
|
|
|
|
|
|
|
this.submiting = false; |
|
|
|
|
|
|
|
util.successMsg("修改成功"); |
|
|
|
|
|
|
|
this.back(); |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
.catch(err => { |
|
|
|
|
|
|
|
this.submiting = false; |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
this.$post(this.api.addArticle, form).then(res => { |
|
|
|
|
|
|
|
this.submiting = false; |
|
|
|
|
|
|
|
util.successMsg("创建成功"); |
|
|
|
|
|
|
|
this.back(); |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
.catch(err => { |
|
|
|
|
|
|
|
this.submiting = false; |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
handleCurrentChange(val) { |
|
|
|
|
|
|
|
this.currPage = val; |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
handleExceed(files, fileList) { |
|
|
|
|
|
|
|
util.warningMsg(`当前限制选择 1 个文件,如需更换,请删除上一个文件再重新选择!`); |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
uploadSuccess(res, file, fileList) { |
|
|
|
|
|
|
|
if (this.form.coverUrl) { |
|
|
|
|
|
|
|
let fileName = this.coverUrl.replace("https://liuwanr.oss-cn-shenzhen.aliyuncs.com/", ""); |
|
|
|
|
|
|
|
this.$del(`${this.api.fileDeletion}?keys=${fileName}`).then(res => { |
|
|
|
|
|
|
|
}).catch(res => { |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
this.form.coverUrl = res.data.filesResult.fileUrl; |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
uploadError(err, file, fileList) { |
|
|
|
|
|
|
|
this.$message({ |
|
|
|
|
|
|
|
message: "上传出错,请重试!", |
|
|
|
|
|
|
|
type: "error", |
|
|
|
|
|
|
|
center: true |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
beforeRemove(file, fileList) { |
|
|
|
|
|
|
|
return this.$confirm(`确定移除 ${file.name}?`); |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
handleRemove(file, fileList) { |
|
|
|
|
|
|
|
let fileName = this.form.coverUrl.replace("https://liuwanr.oss-cn-shenzhen.aliyuncs.com/", ""); |
|
|
|
|
|
|
|
this.$del(`${this.api.fileDeletion}?keys=${fileName}`).then(res => { |
|
|
|
|
|
|
|
this.form.coverUrl = ""; |
|
|
|
|
|
|
|
}).catch(res => { |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
uploadSure() { |
|
|
|
|
|
|
|
this.BatchUpload = false; |
|
|
|
|
|
|
|
this.pageNo = 1; |
|
|
|
|
|
|
|
this.keyword = ""; |
|
|
|
|
|
|
|
this.getData(); |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
back() { |
|
|
|
|
|
|
|
this.$router.back(); |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
goback() { |
|
|
|
|
|
|
|
this.$confirm("确定返回?未更新的信息将不会保存。", "提示", { |
|
|
|
|
|
|
|
type: "warning" |
|
|
|
|
|
|
|
}) |
|
|
|
}) |
|
|
|
.then(() => { |
|
|
|
.catch(err => { |
|
|
|
this.back(); |
|
|
|
this.submiting = false; |
|
|
|
}) |
|
|
|
}); |
|
|
|
.catch(() => { |
|
|
|
} else { |
|
|
|
}); |
|
|
|
this.$post(this.api.addArticle, form).then(res => { |
|
|
|
}, |
|
|
|
this.submiting = false; |
|
|
|
addSponsor() { |
|
|
|
util.successMsg("创建成功"); |
|
|
|
this.sponsorList.push(""); |
|
|
|
this.back(); |
|
|
|
}, |
|
|
|
}) |
|
|
|
delSponsor(index) { |
|
|
|
.catch(err => { |
|
|
|
this.sponsorList.splice(index, 1); |
|
|
|
this.submiting = false; |
|
|
|
}, |
|
|
|
}); |
|
|
|
addOrganizer() { |
|
|
|
} |
|
|
|
this.organzinerList.push(""); |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
delOrganizer(index) { |
|
|
|
|
|
|
|
this.organzinerList.splice(index, 1); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
handleCurrentChange (val) { |
|
|
|
|
|
|
|
this.currPage = val; |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
handleExceed (files, fileList) { |
|
|
|
|
|
|
|
util.warningMsg(`当前限制选择 1 个文件,如需更换,请删除上一个文件再重新选择!`); |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
// 封面自定义上传 |
|
|
|
|
|
|
|
async handleRequest ({ file }) { |
|
|
|
|
|
|
|
Oss.upload(file).then(res => { |
|
|
|
|
|
|
|
this.form.coverUrl = res.url |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
uploadSuccess (res, file, fileList) { |
|
|
|
|
|
|
|
if (this.form.coverUrl) { |
|
|
|
|
|
|
|
let fileName = this.coverUrl.replace("https://liuwanr.oss-cn-shenzhen.aliyuncs.com/", ""); |
|
|
|
|
|
|
|
this.$del(`${this.api.fileDeletion}?keys=${fileName}`).then(res => { |
|
|
|
|
|
|
|
}).catch(res => { |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
this.form.coverUrl = res.data.filesResult.fileUrl; |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
uploadError (err, file, fileList) { |
|
|
|
|
|
|
|
this.$message({ |
|
|
|
|
|
|
|
message: "上传出错,请重试!", |
|
|
|
|
|
|
|
type: "error", |
|
|
|
|
|
|
|
center: true |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
beforeRemove (file, fileList) { |
|
|
|
|
|
|
|
return this.$confirm(`确定移除 ${file.name}?`); |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
handleRemove (file, fileList) { |
|
|
|
|
|
|
|
Oss.del(this.form.coverUrl) |
|
|
|
|
|
|
|
this.form.coverUrl = '' |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
uploadSure () { |
|
|
|
|
|
|
|
this.BatchUpload = false; |
|
|
|
|
|
|
|
this.pageNo = 1; |
|
|
|
|
|
|
|
this.keyword = ""; |
|
|
|
|
|
|
|
this.getData(); |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
back () { |
|
|
|
|
|
|
|
this.$router.back(); |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
goback () { |
|
|
|
|
|
|
|
this.$confirm("确定返回?未更新的信息将不会保存。", "提示", { |
|
|
|
|
|
|
|
type: "warning" |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
.then(() => { |
|
|
|
|
|
|
|
this.back(); |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
.catch(() => { |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
addSponsor () { |
|
|
|
|
|
|
|
this.sponsorList.push(""); |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
delSponsor (index) { |
|
|
|
|
|
|
|
this.sponsorList.splice(index, 1); |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
addOrganizer () { |
|
|
|
|
|
|
|
this.organzinerList.push(""); |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
delOrganizer (index) { |
|
|
|
|
|
|
|
this.organzinerList.splice(index, 1); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
}; |
|
|
|
}; |
|
|
|
</script> |
|
|
|
</script> |
|
|
|
|
|
|
|
|
|
|
@ -221,7 +248,7 @@ $avatar-width: 104px; |
|
|
|
overflow: hidden; |
|
|
|
overflow: hidden; |
|
|
|
|
|
|
|
|
|
|
|
&:hover { |
|
|
|
&:hover { |
|
|
|
border-color: #409EFF; |
|
|
|
border-color: #409eff; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
.uploader-default { |
|
|
|
.uploader-default { |
|
|
@ -272,7 +299,8 @@ $avatar-width: 104px; |
|
|
|
/deep/ .d-inline-block { |
|
|
|
/deep/ .d-inline-block { |
|
|
|
width: 216px; |
|
|
|
width: 216px; |
|
|
|
|
|
|
|
|
|
|
|
.el-select, .el-input { |
|
|
|
.el-select, |
|
|
|
|
|
|
|
.el-input { |
|
|
|
width: 100%; |
|
|
|
width: 100%; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|