wiki评论点赞

This commit is contained in:
暮光:城中城
2019-03-06 22:17:57 +08:00
parent 7d8fa1ff82
commit 3c29cac2d7
15 changed files with 184 additions and 84 deletions

View File

@@ -2,12 +2,14 @@ package com.zyplayer.doc.wiki.controller;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.util.RandomUtil;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.zyplayer.doc.core.json.DocResponseJson;
import com.zyplayer.doc.core.json.ResponseJson;
import com.zyplayer.doc.data.config.security.DocUserDetails;
import com.zyplayer.doc.data.config.security.DocUserUtil;
import com.zyplayer.doc.data.repository.manage.entity.WikiPageFile;
import com.zyplayer.doc.data.service.manage.WikiPageFileService;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
@@ -43,7 +45,6 @@ public class WikiCommonController {
@PostMapping("/upload")
public ResponseJson<Object> upload(WikiPageFile wikiPageFile, @RequestParam("files") MultipartFile file) {
//通过CommonsMultipartFile的方法直接写文件注意这个时候
String fileName = file.getOriginalFilename();
String fileSuffix = "";
if (fileName != null && fileName.lastIndexOf(".") >= 0) {
@@ -55,7 +56,8 @@ public class WikiCommonController {
if (!newFile.exists() && !newFile.mkdir()) {
return DocResponseJson.warn("创建文件夹失败");
}
path += RandomUtil.simpleUUID() + fileSuffix;
String simpleUUID = RandomUtil.simpleUUID();
path += simpleUUID + fileSuffix;
newFile = new File(path);
try {
file.transferTo(newFile);
@@ -63,6 +65,7 @@ public class WikiCommonController {
e.printStackTrace();
return DocResponseJson.warn("保存文件失败");
}
wikiPageFile.setUuid(simpleUUID);
wikiPageFile.setFileUrl(path);
wikiPageFile.setFileName(fileName);
wikiPageFile.setCreateTime(new Date());
@@ -70,16 +73,18 @@ public class WikiCommonController {
wikiPageFile.setCreateUserName(currentUser.getUsername());
wikiPageFile.setDelFlag(0);
wikiPageFileService.save(wikiPageFile);
wikiPageFile.setFileUrl("zyplayer-doc-wiki/common/file?fileId=" + wikiPageFile.getId());
wikiPageFile.setFileUrl("zyplayer-doc-wiki/common/file?uuid=" + wikiPageFile.getUuid());
return DocResponseJson.ok(wikiPageFile);
}
@GetMapping("/file")
public ResponseJson<Object> file(Long fileId, HttpServletResponse response) {
if (fileId == null || fileId <= 0) {
public ResponseJson<Object> file(String uuid, HttpServletResponse response) {
if (StringUtils.isBlank(uuid)) {
return DocResponseJson.warn("请指定文件ID");
}
WikiPageFile pageFile = wikiPageFileService.getById(fileId);
UpdateWrapper<WikiPageFile> wrapperFile = new UpdateWrapper<>();
wrapperFile.eq("uuid", uuid);
WikiPageFile pageFile = wikiPageFileService.getOne(wrapperFile);
if (pageFile == null) {
return DocResponseJson.warn("未找到指定文件");
}

View File

@@ -49,9 +49,10 @@ public class WikiPageCommentController {
DocUserDetails currentUser = DocUserUtil.getCurrentUser();
pageComment.setCreateTime(new Date());
pageComment.setCreateUserId(currentUser.getUserId());
pageComment.setCreateUserName(currentUser.getUsername());
wikiPageCommentService.save(pageComment);
}
return DocResponseJson.ok();
return DocResponseJson.ok(pageComment);
}
}

View File

@@ -71,7 +71,7 @@ public class WikiPageController {
wrapperFile.eq("del_flag", 0);
List<WikiPageFile> pageFiles = wikiPageFileService.list(wrapperFile);
for (WikiPageFile pageFile : pageFiles) {
pageFile.setFileUrl("zyplayer-doc-wiki/common/file?fileId=" + pageFile.getId());
pageFile.setFileUrl("zyplayer-doc-wiki/common/file?uuid=" + pageFile.getUuid());
}
UpdateWrapper<WikiPageZan> wrapperZan = new UpdateWrapper<>();
wrapperZan.eq("page_id", wikiPage.getId());

View File

@@ -1,12 +1,19 @@
package com.zyplayer.doc.wiki.controller;
import com.zyplayer.doc.core.json.DocResponseJson;
import com.zyplayer.doc.core.json.ResponseJson;
import com.zyplayer.doc.data.config.security.DocUserDetails;
import com.zyplayer.doc.data.config.security.DocUserUtil;
import com.zyplayer.doc.data.repository.manage.entity.WikiPageFile;
import com.zyplayer.doc.data.service.manage.WikiPageFileService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import java.util.Date;
/**
* 文档控制器
@@ -30,23 +37,27 @@ public class WikiPageFileController {
// wrapper.eq("page_id", wikiPageFile.getPageId());
// List<WikiPageFile> fileList = wikiPageFileService.list(wrapper);
// for (WikiPageFile pageFile : fileList) {
// pageFile.setFileUrl("zyplayer-doc-wiki/common/file?fileId=" + pageFile.getId());
// pageFile.setFileUrl("zyplayer-doc-wiki/common/file?uuid=" + pageFile.getUuid());
// }
// return DocResponseJson.ok(fileList);
// }
//
// @PostMapping("/update")
// public ResponseJson<Object> update(WikiPageFile wikiPageFile) {
// Long id = wikiPageFile.getId();
// if (id != null && id > 0) {
// wikiPageFileService.updateById(wikiPageFile);
// } else {
// DocUserDetails currentUser = DocUserUtil.getCurrentUser();
// wikiPageFile.setCreateTime(new Date());
// wikiPageFile.setCreateUserId(currentUser.getUserId());
// wikiPageFileService.save(wikiPageFile);
// }
// return DocResponseJson.ok();
// }
@PostMapping("/update")
public ResponseJson<Object> update(WikiPageFile wikiPageFile) {
DocUserDetails currentUser = DocUserUtil.getCurrentUser();
Long id = wikiPageFile.getId();
if (id != null && id > 0) {
wikiPageFile.setUpdateUserId(currentUser.getUserId());
wikiPageFile.setUpdateUserName(currentUser.getUsername());
wikiPageFile.setUpdateTime(new Date());
wikiPageFileService.updateById(wikiPageFile);
} else {
wikiPageFile.setCreateTime(new Date());
wikiPageFile.setCreateUserId(currentUser.getUserId());
wikiPageFile.setCreateUserName(currentUser.getUsername());
wikiPageFileService.save(wikiPageFile);
}
return DocResponseJson.ok();
}
}

View File

@@ -1,5 +1,6 @@
package com.zyplayer.doc.wiki.controller;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.zyplayer.doc.core.json.DocResponseJson;
import com.zyplayer.doc.core.json.ResponseJson;
import com.zyplayer.doc.data.repository.manage.entity.WikiPageZan;
@@ -11,6 +12,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import java.util.List;
/**
* 文档控制器
@@ -26,14 +28,14 @@ public class WikiPageZanController {
@Resource
WikiPageZanService wikiPageZanService;
// @PostMapping("/list")
// public ResponseJson<List<WikiPageZan>> list(WikiPageZan wikiPageZan) {
// UpdateWrapper<WikiPageZan> wrapper = new UpdateWrapper<>();
// wrapper.eq("page_id", wikiPageZan.getPageId());
// wrapper.eq(wikiPageZan.getCommentId() != null, "comment_id", wikiPageZan.getCommentId());
// List<WikiPageZan> zanList = wikiPageZanService.list(wrapper);
// return DocResponseJson.ok(zanList);
// }
@PostMapping("/list")
public ResponseJson<List<WikiPageZan>> list(WikiPageZan wikiPageZan) {
UpdateWrapper<WikiPageZan> wrapper = new UpdateWrapper<>();
wrapper.eq("page_id", wikiPageZan.getPageId());
wrapper.eq(wikiPageZan.getCommentId() != null, "comment_id", wikiPageZan.getCommentId());
List<WikiPageZan> zanList = wikiPageZanService.list(wrapper);
return DocResponseJson.ok(zanList);
}
@PostMapping("/update")
public ResponseJson<Object> update(WikiPageZan wikiPageZan) {

View File

@@ -28,7 +28,6 @@
</el-row>
<el-row type="border-card" v-show="rightContentType == 1">
<div class="wiki-title">
<!--狗屎一样的代码如何重构wiki模块正在开发中这只是一个预览页面-->
{{wikiPage.name}}
<div style="float: right;">
<el-button type="text" icon="el-icon-edit" v-on:click="editWiki">编辑</el-button>
@@ -49,6 +48,7 @@
class="upload-page-file"
action="zyplayer-doc-wiki/common/upload"
:on-success="uploadFileSuccess"
:on-error="uploadFileError"
name="files"
show-file-list
multiple
@@ -66,12 +66,17 @@
</el-table-column>
<el-table-column prop="createUserName" label="创建人"></el-table-column>
<el-table-column prop="createTime" label="创建时间"></el-table-column>
<el-table-column label="操作">
<template slot-scope="scope">
<el-button v-on:click="deletePageFile(scope.row)">删除</el-button>
</template>
</el-table-column>
</el-table>
</div>
<div class="wiki-content">
<div v-html="pageContent.content"></div>
</div>
<div style="margin-top: 10px; font-size: 14px;">
<div style="margin-top: 20px; font-size: 14px;">
<span style="vertical-align: top;" class="is-link">
<img src="webjars/doc-wiki/img/zan.png" style="vertical-align: middle;">
<span v-show="wikiPage.selfZan == 0" v-on:click="zanPage(1)"></span>
@@ -84,6 +89,13 @@
<span v-else-if="wikiPage.selfZan == 1 && wikiPage.zanNum > 1"><span class="is-link" v-on:click="showZanPageUser">我和{{wikiPage.zanNum-1}}个其他人</span>赞了它</span>
</span>
</div>
<div v-show="commentList.length > 0" style="margin-top: 20px;">
<div style="margin-bottom: 10px;">评论列表:</div>
<div v-for="(item,index) in commentList" :key="item.id" :data-id="item.id" :data-index="index" style="border-top: 1px solid #ccc;padding: 10px;">
<div>{{item.createUserName}}<div style="color: #888;font-size: 13px;float: right;">{{item.createTime}}</div></div>
<div style="padding-top: 10px;"> {{item.content}}</div>
</div>
</div>
<div style="margin-top: 10px;">
<el-input type="textarea" v-model="commentTextInput" :rows="2" placeholder="请输入评论内容"></el-input>
<div align="right" style="margin-top: 5px;">
@@ -105,6 +117,13 @@
</el-row>
</el-main>
</el-container>
<!--点赞人员弹窗-->
<el-dialog title="赞了它的人" :visible.sync="zanUserDialogVisible" width="600px">
<el-table :data="zanUserList" border :show-header="false" style="width: 100%; margin-bottom: 5px;">
<el-table-column prop="createUserName" show-header label="用户"></el-table-column>
<el-table-column prop="createTime" show-header label="时间"></el-table-column>
</el-table>
</el-dialog>
<!--关于弹窗-->
<el-dialog title="关于zyplayer-doc-wiki" :visible.sync="aboutDialogVisible" width="600px">
<el-form>
@@ -155,6 +174,7 @@
// 搜索的输入内容
searchKeywords: "",
lastClickNode: {},
// 编辑相关
newPageId: "",
newPageTitle: "",
// 页面展示相关
@@ -163,8 +183,11 @@
pageFileList: [],
uploadFileList: [],
uploadFormData: {pageId: 0},
zanUserDialogVisible: false,
zanUserList: [],
// 评论相关
commentTextInput: ""
commentTextInput: "",
commentList: [],
}
},
watch: {
@@ -185,14 +208,46 @@
});
},
showZanPageUser() {
app.zanUserDialogVisible = true;
app.zanUserList = [];
var param = {pageId: app.wikiPage.id};
ajaxTemp("zyplayer-doc-wiki/page/zan/list", "post", "json", param, function (json) {
if (validateResult(json)) {
app.zanUserList = json.data;
}
});
},
submitPageComment() {
Toast.success(app.commentTextInput);
var param = {pageId: app.wikiPage.id, content: app.commentTextInput};
ajaxTemp("zyplayer-doc-wiki/page/comment/update", "post", "json", param, function (json) {
if (validateResult(json)) {
app.commentTextInput = "";
app.commentList.push(json.data);
}
});
},
uploadFileError(err) {
Toast.success("上传失败," + err);
},
uploadFileSuccess(response) {
app.pageFileList.push(response.data);
Toast.success("上传成功!");
if (validateResult(response)) {
app.pageFileList.push(response.data);
Toast.success("上传成功!");
}
},
deletePageFile(row) {
var param = {id: row.id, delFlag: 1};
ajaxTemp("zyplayer-doc-wiki/page/file/update", "post", "json", param, function (json) {
if (validateResult(json)) {
var pageFileList = [];
for (var i = 0; i < app.pageFileList.length; i++) {
if (app.pageFileList[i].id != row.id) {
pageFileList.push(app.pageFileList[i]);
}
}
app.pageFileList = pageFileList;
}
});
},
editWiki() {
this.rightContentType = 2;
@@ -200,18 +255,20 @@
this.newPageTitle = app.wikiPage.name;
page.newPageContentEditor.txt.html(app.pageContent.content || "");
},
createWiki(){
createWiki() {
this.newPageId = "";
this.newPageTitle = "";
page.newPageContentEditor.txt.html("");
this.rightContentType = 2;
},
createWikiCancel(){
createWikiCancel() {
if (isEmpty(this.lastClickNode.label)) {
this.rightContentType = 0;
} else {
this.rightContentType = 1;
}
},
createWikiSave(){
createWikiSave() {
var parentId = app.lastClickNode.id;
if (this.newPageId > 0) {
parentId = "";
@@ -252,6 +309,16 @@
app.uploadFormData = {pageId: app.wikiPage.id};
}
});
this.loadCommentList(pageId);
},
loadCommentList(pageId) {
app.commentList = [];
var param = {pageId: pageId};
ajaxTemp("zyplayer-doc-wiki/page/comment/list", "post", "json", param, function (json) {
if (validateResult(json)) {
app.commentList = json.data || [];
}
});
},
searchByKeywords() {
app.pathIndex = createTreeViewByTreeWithMerge(app.dubboDocList, app.searchKeywords);