diff --git a/src/views/page/PageEdit.vue b/src/views/page/PageEdit.vue index 3b0300868..92cac89e9 100644 --- a/src/views/page/PageEdit.vue +++ b/src/views/page/PageEdit.vue @@ -5,6 +5,7 @@
- +
@@ -33,20 +34,23 @@

基本设置

- - + + - + - - - - - + + + 开启 + 关闭 + - + {{ tpl }} @@ -66,8 +70,8 @@
- 保存草稿 - 发布 + 保存草稿 + {{ publishText }}
@@ -79,7 +83,8 @@ import { mavonEditor } from 'mavon-editor' import { mixin, mixinDevice } from '@/utils/mixin.js' import 'mavon-editor/dist/css/index.css' -import tagApi from '@/api/theme' +import postApi from '@/api/post' +import themeApi from '@/api/theme' export default { name: 'Editor', components: { @@ -94,11 +99,19 @@ export default { sm: { span: 24 }, xs: { span: 24 } }, - value: 'Hello World', visible: false, drawerWidth: '460', postUrl: 'hello-world', - customTpls: [] + customTpls: [], + postToStage: {} + } + }, + computed: { + publishText() { + if (this.postToStage.id) { + return '更新并发布' + } + return '创建并发布' } }, mounted() { @@ -111,15 +124,54 @@ export default { created() { this.loadCustomTpls() }, + beforeRouteEnter(to, from, next) { + // Get post id from query + const postId = to.query.postId + + next(vm => { + if (postId) { + postApi.get(postId).then(response => { + const post = response.data.data + vm.postToStage = post + vm.selectedTagIds = post.tagIds + vm.selectedCategoryIds = post.categoryIds + }) + } + }) + }, methods: { loadCustomTpls() { - tagApi.customTpls().then(response => { + themeApi.customTpls().then(response => { this.customTpls = response.data.data }) }, showDrawer() { this.visible = true }, + handlePublishClick() { + this.postToStage.status = 'PUBLISHED' + this.createOrUpdatePost() + }, + handleDraftClick() { + this.postToStage.status = 'DRAFT' + this.createOrUpdatePost() + }, + createOrUpdatePost() { + if (this.postToStage.id) { + // Update the post + postApi.update(this.postToStage.id, this.postToStage).then(response => { + this.$log.debug('Updated post', response.data.data) + this.$message.success('页面更新成功') + }) + } else { + // Create the post + postApi.create(this.postToStage).then(response => { + this.$log.debug('Created post', response.data.data) + this.$message.success('页面创建成功') + this.postToStage = response.data.data + }) + } + }, onClose() { this.visible = false } diff --git a/src/views/post/PostEdit.vue b/src/views/post/PostEdit.vue index 61a11eecf..14b2d260a 100644 --- a/src/views/post/PostEdit.vue +++ b/src/views/post/PostEdit.vue @@ -1,13 +1,7 @@