Complete post edit feature

pull/3445/head
johnniang 2019-04-12 13:07:06 +08:00
parent 9c18f52889
commit 1a25c41d1d
3 changed files with 25 additions and 6 deletions

View File

@ -19,6 +19,13 @@ postApi.query = params => {
})
}
postApi.get = postId => {
return service({
url: `${baseUrl}/${postId}`,
method: 'get'
})
}
postApi.create = postToCreate => {
return service({
url: baseUrl,

View File

@ -214,6 +214,18 @@ export default {
this.loadTags()
this.loadCategories()
},
beforeRouteEnter(to, from, next) {
// Get post id from query
const postId = to.query.postId
next(vm => {
if (postId) {
postApi.get(postId).then(response => {
vm.postToStage = response.data.data
})
}
})
},
methods: {
loadTags() {
tagApi.listAll(true).then(response => {
@ -242,7 +254,7 @@ export default {
postApi.create(this.postToStage).then(response => {
this.$log.debug('Created post', response.data.data)
this.$message.success('文章创建成功')
this.postToStage.id = response.data.data.id
this.postToStage = response.data.data
})
}
},

View File

@ -149,16 +149,16 @@
<span
slot="action"
slot-scope="text, record"
slot-scope="text, post"
>
<a
href="javascript:;"
@click="editPost(record.id)"
@click="onEditClick(post)"
>编辑</a>
<a-divider type="vertical" />
<a
href="javascript:;"
@click="deletePost(record.id)"
@click="deletePost(post.id)"
>删除</a>
</span>
</a-table>
@ -294,8 +294,8 @@ export default {
this.categories = response.data.data
})
},
editPost(id) {
this.$message.success('编辑')
onEditClick(post) {
this.$router.push({ name: 'PostEdit', query: { postId: post.id } })
},
deletePost(id) {
this.$message.success('删除')