From 4b42eede1947b525637a74000f76c867df128eb0 Mon Sep 17 00:00:00 2001 From: ruibaby Date: Wed, 11 Dec 2019 23:15:39 +0800 Subject: [PATCH] feat: support remove in batch api for post. --- src/api/post.js | 12 +++++++ src/views/post/PostList.vue | 67 ++++++++++++++++++------------------- 2 files changed, 45 insertions(+), 34 deletions(-) diff --git a/src/api/post.js b/src/api/post.js index 9199b206..82ababaa 100644 --- a/src/api/post.js +++ b/src/api/post.js @@ -65,6 +65,14 @@ postApi.delete = postId => { }) } +postApi.deleteInBatch = ids => { + return service({ + url: `${baseUrl}`, + data: ids, + method: 'delete' + }) +} + postApi.preview = postId => { return service({ url: `${baseUrl}/preview/${postId}`, @@ -74,21 +82,25 @@ postApi.preview = postId => { postApi.postStatus = { PUBLISHED: { + value: 'PUBLISHED', color: 'green', status: 'success', text: '已发布' }, DRAFT: { + value: 'DRAFT', color: 'yellow', status: 'warning', text: '草稿' }, RECYCLE: { + value: 'RECYCLE', color: 'red', status: 'error', text: '回收站' }, INTIMATE: { + value: 'INTIMATE', color: 'blue', status: 'success', text: '私密' diff --git a/src/views/post/PostList.vue b/src/views/post/PostList.vue index ead44fb4..a8e4df14 100644 --- a/src/views/post/PostList.vue +++ b/src/views/post/PostList.vue @@ -12,7 +12,10 @@ :sm="24" > - + 发布 @@ -96,14 +99,25 @@ > 移到回收站 + + 草稿 + + + { - this.$log.debug(`postId: ${element}, status: PUBLISHED`) - this.selectedRowKeys = [] - this.loadPosts() - }) - } - }, - handleRecycleMore() { + handleEditStatusMore(status) { if (this.selectedRowKeys.length <= 0) { this.$message.success('请至少选择一项!') return } for (let index = 0; index < this.selectedRowKeys.length; index++) { const element = this.selectedRowKeys[index] - postApi.updateStatus(element, 'RECYCLE').then(response => { - this.$log.debug(`postId: ${element}, status: RECYCLE`) + postApi.updateStatus(element, status).then(response => { + this.$log.debug(`postId: ${element}, status: ${status}`) this.selectedRowKeys = [] this.loadPosts() }) @@ -739,14 +741,11 @@ export default { this.$message.success('请至少选择一项!') return } - for (let index = 0; index < this.selectedRowKeys.length; index++) { - const element = this.selectedRowKeys[index] - postApi.delete(element).then(response => { - this.$log.debug(`delete: ${element}`) - this.selectedRowKeys = [] - this.loadPosts() - }) - } + postApi.deleteInBatch(this.selectedRowKeys).then(response => { + this.$log.debug(`delete: ${this.selectedRowKeys}`) + this.selectedRowKeys = [] + this.loadPosts() + }) }, handleShowPostSettings(post) { postApi.get(post.id).then(response => {