From c2b95c7f48d6cd38ec5985d904d8b6ad549c0f5c Mon Sep 17 00:00:00 2001 From: ruibaby Date: Wed, 24 Apr 2019 23:58:01 +0800 Subject: [PATCH] Complate post and sheet control. --- src/api/post.js | 14 ++++++++ src/api/sheet.js | 14 ++++++++ src/views/post/PostList.vue | 57 ++++++++++++++++++++++--------- src/views/sheet/SheetList.vue | 63 +++++++++++++++++++++++++++-------- 4 files changed, 120 insertions(+), 28 deletions(-) diff --git a/src/api/post.js b/src/api/post.js index 4c9fa365..49f58245 100644 --- a/src/api/post.js +++ b/src/api/post.js @@ -42,6 +42,20 @@ postApi.update = (postId, postToUpdate) => { }) } +postApi.updateStatus = (postId, status) => { + return service({ + url: `${baseUrl}/${postId}/${status}`, + method: 'put' + }) +} + +postApi.delete = postId => { + return service({ + url: `${baseUrl}/${postId}`, + method: 'delete' + }) +} + postApi.postStatus = { PUBLISHED: { color: 'green', diff --git a/src/api/sheet.js b/src/api/sheet.js index 52bd7d00..80a37eb3 100644 --- a/src/api/sheet.js +++ b/src/api/sheet.js @@ -34,6 +34,20 @@ sheetApi.update = (sheetId, sheetToUpdate) => { }) } +sheetApi.updateStatus = (sheetId, status) => { + return service({ + url: `${baseUrl}/${sheetId}/${status}`, + method: 'put' + }) +} + +sheetApi.delete = sheetId => { + return service({ + url: `${baseUrl}/${sheetId}`, + method: 'delete' + }) +} + sheetApi.sheetStatus = { PUBLISHED: { color: 'green', diff --git a/src/views/post/PostList.vue b/src/views/post/PostList.vue index 12745689..a176aa46 100644 --- a/src/views/post/PostList.vue +++ b/src/views/post/PostList.vue @@ -143,22 +143,37 @@ @click="onEditClick(post)" v-if="post.status === 'PUBLISHED' || post.status === 'DRAFT'" >编辑 - 还原 - - 回收站 - 删除 + > + 还原 + + + + + + 回收站 + + + + 删除 + { + this.$message.success('操作成功!') + this.loadPosts() + }) + }, + onDeleteClick(postId) { + postApi.delete(postId).then(response => { + this.$message.success('删除成功!') + this.loadPosts() + }) } } } diff --git a/src/views/sheet/SheetList.vue b/src/views/sheet/SheetList.vue index d73c34cf..f86a8598 100644 --- a/src/views/sheet/SheetList.vue +++ b/src/views/sheet/SheetList.vue @@ -104,20 +104,45 @@ @click="onEditClick(sheet)" v-if="sheet.status === 'PUBLISHED' || sheet.status === 'DRAFT'" >编辑 - 还原 - - 回收站 - 删除 + > + 还原 + + + + + + 回收站 + + + + 删除 + + @@ -225,6 +250,18 @@ export default { onEditClick(sheet) { this.$router.push({ name: 'SheetEdit', query: { sheetId: sheet.id } }) }, + onEditStatusClick(sheetId, status) { + sheetApi.updateStatus(sheetId, status).then(response => { + this.$message.success('操作成功!') + this.loadSheets() + }) + }, + onDeleteClick(sheetId) { + sheetApi.delete(sheetId).then(response => { + this.$message.success('删除成功!') + this.loadSheets() + }) + }, viewPage(id) { this.$message.success('查看' + id) }