diff --git a/zyplayer-doc-ui/wiki-ui/src/common/api/page.js b/zyplayer-doc-ui/wiki-ui/src/common/api/page.js index 3a01eae2..ff3ca136 100644 --- a/zyplayer-doc-ui/wiki-ui/src/common/api/page.js +++ b/zyplayer-doc-ui/wiki-ui/src/common/api/page.js @@ -52,6 +52,9 @@ export default { }, updatePageComment: data => { return request({url: '/zyplayer-doc-wiki/page/comment/update', method: 'post', data: Qs.stringify(data)}); + }, + deletePageComment: data => { + return request({url: '/zyplayer-doc-wiki/page/comment/delete', method: 'post', data: Qs.stringify(data)}); }, pageZanList: data => { return request({url: '/zyplayer-doc-wiki/page/zan/list', method: 'post', data: Qs.stringify(data)}); diff --git a/zyplayer-doc-ui/wiki-ui/src/views/page/Show.vue b/zyplayer-doc-ui/wiki-ui/src/views/page/Show.vue index 6b9ae032..9560a976 100644 --- a/zyplayer-doc-ui/wiki-ui/src/views/page/Show.vue +++ b/zyplayer-doc-ui/wiki-ui/src/views/page/Show.vue @@ -67,6 +67,7 @@ {{comment.createUserName}} {{comment.createTime}} 回复 + 删除
{{comment.content}}
@@ -76,6 +77,7 @@
{{commentSub.createUserName}} {{commentSub.createTime}} + 删除
{{commentSub.content}}
@@ -146,6 +148,7 @@ wikiPage: {}, pageContent: {}, pageFileList: [], + selfUserId: 0, uploadFileList: [], uploadFormData: {pageId: 0}, zanUserDialogVisible: false, @@ -274,6 +277,7 @@ this.wikiPage = wikiPage; this.pageContent = json.data.pageContent || {}; this.pageFileList = json.data.fileList || []; + this.selfUserId = json.data.selfUserId || 0; this.uploadFormData = {pageId: this.wikiPage.id}; this.parentPath.spaceId = wikiPage.spaceId; // 修改标题 @@ -321,6 +325,21 @@ recommentUser(id, index) { this.recommentInfo = {id: id, index: index, placeholder: '回复' + (index + 1) + '楼'}; }, + canDeleteComment(row) { + return this.selfUserId == row.createUserId || this.wikiPage.createUserId == this.selfUserId; + }, + deleteComment(id) { + this.$confirm('确定要除删此评论吗?', '提示', { + confirmButtonText: '确定', + cancelButtonText: '取消', + type: 'warning' + }).then(() => { + pageApi.deletePageComment({id: id}).then(() => { + this.$message.success("删除成功!"); + this.loadCommentList(this.parentPath.pageId); + }); + }); + }, cancelCommentUser() { this.recommentInfo = {}; }, @@ -337,7 +356,7 @@ var data = json.data; data.color = this.getUserHeadBgColor(data.createUserId); this.commentTextInput = ""; - this.commentList.push(data); + this.loadCommentList(this.parentPath.pageId); }); }, uploadFileError(err) { diff --git a/zyplayer-doc-wiki/src/main/java/com/zyplayer/doc/wiki/controller/WikiPageCommentController.java b/zyplayer-doc-wiki/src/main/java/com/zyplayer/doc/wiki/controller/WikiPageCommentController.java index 4c798287..82c863fb 100644 --- a/zyplayer-doc-wiki/src/main/java/com/zyplayer/doc/wiki/controller/WikiPageCommentController.java +++ b/zyplayer-doc-wiki/src/main/java/com/zyplayer/doc/wiki/controller/WikiPageCommentController.java @@ -25,6 +25,7 @@ import javax.annotation.Resource; import java.util.Date; import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.stream.Collectors; /** @@ -58,6 +59,7 @@ public class WikiPageCommentController { return DocResponseJson.warn("您没有查看该空间的评论权!"); } UpdateWrapper wrapper = new UpdateWrapper<>(); + wrapper.eq("del_flag", 0); wrapper.eq("page_id", pageComment.getPageId()); wrapper.eq(pageComment.getParentId() != null, "parent_id", pageComment.getParentId()); List authList = wikiPageCommentService.list(wrapper); @@ -71,19 +73,39 @@ public class WikiPageCommentController { return DocResponseJson.ok(commentList); } + @PostMapping("/delete") + public ResponseJson delete(Long id) { + WikiPageComment pageCommentSel = wikiPageCommentService.getById(id); + DocUserDetails currentUser = DocUserUtil.getCurrentUser(); + if (!Objects.equals(pageCommentSel.getCreateUserId(), currentUser.getUserId())) { + WikiPage wikiPageSel = wikiPageService.getById(pageCommentSel.getPageId()); + if (!Objects.equals(currentUser.getUserId(), wikiPageSel.getCreateUserId())) { + return DocResponseJson.warn("只有评论人或页面创建人才有权限删除此评论!"); + } + } + WikiPageComment pageComment = new WikiPageComment(); + pageComment.setId(id); + pageComment.setDelFlag(1); + wikiPageCommentService.updateById(pageComment); + return DocResponseJson.ok(); + } + @PostMapping("/update") public ResponseJson update(WikiPageComment pageComment) { + DocUserDetails currentUser = DocUserUtil.getCurrentUser(); Long id = pageComment.getId(); Long pageId; if (id != null && id > 0) { WikiPageComment pageCommentSel = wikiPageCommentService.getById(id); + if (!Objects.equals(pageCommentSel.getCreateUserId(), currentUser.getUserId())) { + return DocResponseJson.warn("只能修改自己的评论!"); + } pageId = pageCommentSel.getPageId(); } else if (pageComment.getPageId() != null) { pageId = pageComment.getPageId(); } else { return DocResponseJson.warn("需指定所属页面!"); } - DocUserDetails currentUser = DocUserUtil.getCurrentUser(); WikiPage wikiPageSel = wikiPageService.getById(pageId); WikiSpace wikiSpaceSel = wikiSpaceService.getById(wikiPageSel.getSpaceId()); // 私人空间 @@ -98,6 +120,7 @@ public class WikiPageCommentController { // } // } if (id != null && id > 0) { + pageComment.setDelFlag(0); wikiPageCommentService.updateById(pageComment); } else { pageComment.setCreateTime(new Date()); diff --git a/zyplayer-doc-wiki/src/main/java/com/zyplayer/doc/wiki/controller/WikiPageController.java b/zyplayer-doc-wiki/src/main/java/com/zyplayer/doc/wiki/controller/WikiPageController.java index 9043a05d..48b7c774 100644 --- a/zyplayer-doc-wiki/src/main/java/com/zyplayer/doc/wiki/controller/WikiPageController.java +++ b/zyplayer-doc-wiki/src/main/java/com/zyplayer/doc/wiki/controller/WikiPageController.java @@ -132,6 +132,7 @@ public class WikiPageController { vo.setPageContent(pageContent); vo.setFileList(pageFiles); vo.setSelfZan((pageZan != null) ? 1 : 0); + vo.setSelfUserId(currentUser.getUserId()); // 高并发下会有覆盖问题,但不重要~ Integer viewNum = Optional.ofNullable(wikiPageSel.getViewNum()).orElse(0); WikiPage wikiPageUp = new WikiPage(); diff --git a/zyplayer-doc-wiki/src/main/java/com/zyplayer/doc/wiki/controller/vo/WikiPageContentVo.java b/zyplayer-doc-wiki/src/main/java/com/zyplayer/doc/wiki/controller/vo/WikiPageContentVo.java index 9d2b1023..afb31e28 100644 --- a/zyplayer-doc-wiki/src/main/java/com/zyplayer/doc/wiki/controller/vo/WikiPageContentVo.java +++ b/zyplayer-doc-wiki/src/main/java/com/zyplayer/doc/wiki/controller/vo/WikiPageContentVo.java @@ -11,6 +11,7 @@ public class WikiPageContentVo { private WikiPageContent pageContent; private List fileList; private Integer selfZan; + private Long selfUserId; public WikiPage getWikiPage() { return wikiPage; @@ -43,4 +44,12 @@ public class WikiPageContentVo { public void setSelfZan(Integer selfZan) { this.selfZan = selfZan; } + + public Long getSelfUserId() { + return selfUserId; + } + + public void setSelfUserId(Long selfUserId) { + this.selfUserId = selfUserId; + } } diff --git a/zyplayer-doc-wiki/src/main/java/com/zyplayer/doc/wiki/framework/consts/SpaceType.java b/zyplayer-doc-wiki/src/main/java/com/zyplayer/doc/wiki/framework/consts/SpaceType.java index 770ba582..e6f9c08e 100644 --- a/zyplayer-doc-wiki/src/main/java/com/zyplayer/doc/wiki/framework/consts/SpaceType.java +++ b/zyplayer-doc-wiki/src/main/java/com/zyplayer/doc/wiki/framework/consts/SpaceType.java @@ -7,7 +7,7 @@ public class SpaceType { public static final Integer personalSpace = 2; public static final Integer privateSpace = 3; - public static boolean isPublic(Integer type){ + public static boolean isPublic(Integer type) { return Objects.equals(type, publicSpace); } @@ -15,19 +15,19 @@ public class SpaceType { return Objects.equals(type, personalSpace); } - public static boolean isOthersPersonal(Integer type, Long loginUserId, Long spaceUserId){ + public static boolean isOthersPersonal(Integer type, Long loginUserId, Long spaceUserId) { return Objects.equals(type, personalSpace) && !Objects.equals(loginUserId, spaceUserId); } - public static boolean isPrivate(Integer type){ + public static boolean isPrivate(Integer type) { return Objects.equals(type, privateSpace); } - public static boolean isSelfPrivate(Integer type, Long loginUserId, Long spaceUserId){ + public static boolean isSelfPrivate(Integer type, Long loginUserId, Long spaceUserId) { return Objects.equals(type, privateSpace) && Objects.equals(loginUserId, spaceUserId); } - public static boolean isOthersPrivate(Integer type, Long loginUserId, Long spaceUserId){ + public static boolean isOthersPrivate(Integer type, Long loginUserId, Long spaceUserId) { return Objects.equals(type, privateSpace) && !Objects.equals(loginUserId, spaceUserId); } }