mirror of https://github.com/halo-dev/halo
Complete post edit feature
parent
9c18f52889
commit
1a25c41d1d
|
@ -19,6 +19,13 @@ postApi.query = params => {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
postApi.get = postId => {
|
||||||
|
return service({
|
||||||
|
url: `${baseUrl}/${postId}`,
|
||||||
|
method: 'get'
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
postApi.create = postToCreate => {
|
postApi.create = postToCreate => {
|
||||||
return service({
|
return service({
|
||||||
url: baseUrl,
|
url: baseUrl,
|
||||||
|
|
|
@ -214,6 +214,18 @@ export default {
|
||||||
this.loadTags()
|
this.loadTags()
|
||||||
this.loadCategories()
|
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: {
|
methods: {
|
||||||
loadTags() {
|
loadTags() {
|
||||||
tagApi.listAll(true).then(response => {
|
tagApi.listAll(true).then(response => {
|
||||||
|
@ -242,7 +254,7 @@ export default {
|
||||||
postApi.create(this.postToStage).then(response => {
|
postApi.create(this.postToStage).then(response => {
|
||||||
this.$log.debug('Created post', response.data.data)
|
this.$log.debug('Created post', response.data.data)
|
||||||
this.$message.success('文章创建成功')
|
this.$message.success('文章创建成功')
|
||||||
this.postToStage.id = response.data.data.id
|
this.postToStage = response.data.data
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
@ -149,16 +149,16 @@
|
||||||
|
|
||||||
<span
|
<span
|
||||||
slot="action"
|
slot="action"
|
||||||
slot-scope="text, record"
|
slot-scope="text, post"
|
||||||
>
|
>
|
||||||
<a
|
<a
|
||||||
href="javascript:;"
|
href="javascript:;"
|
||||||
@click="editPost(record.id)"
|
@click="onEditClick(post)"
|
||||||
>编辑</a>
|
>编辑</a>
|
||||||
<a-divider type="vertical" />
|
<a-divider type="vertical" />
|
||||||
<a
|
<a
|
||||||
href="javascript:;"
|
href="javascript:;"
|
||||||
@click="deletePost(record.id)"
|
@click="deletePost(post.id)"
|
||||||
>删除</a>
|
>删除</a>
|
||||||
</span>
|
</span>
|
||||||
</a-table>
|
</a-table>
|
||||||
|
@ -294,8 +294,8 @@ export default {
|
||||||
this.categories = response.data.data
|
this.categories = response.data.data
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
editPost(id) {
|
onEditClick(post) {
|
||||||
this.$message.success('编辑')
|
this.$router.push({ name: 'PostEdit', query: { postId: post.id } })
|
||||||
},
|
},
|
||||||
deletePost(id) {
|
deletePost(id) {
|
||||||
this.$message.success('删除')
|
this.$message.success('删除')
|
||||||
|
|
Loading…
Reference in New Issue