#I3BMNS 代码块高亮,增加判空和状态判断

This commit is contained in:
暮光:城中城
2021-11-01 22:44:11 +08:00
parent 7b4c1ae455
commit d3ed4e8334
7 changed files with 62 additions and 4 deletions

View File

@@ -2898,6 +2898,12 @@
"integrity": "sha1-lEdx/ZyByBJlxNaUGGDaBrtZR5s=",
"dev": true
},
"highlight.js": {
"version": "9.18.5",
"resolved": "https://registry.npmmirror.com/highlight.js/download/highlight.js-9.18.5.tgz",
"integrity": "sha1-0Yo1mGfzeME41oGe38KorNXymCU=",
"dev": true
},
"supports-color": {
"version": "7.1.0",
"resolved": "https://registry.npm.taobao.org/supports-color/download/supports-color-7.1.0.tgz?cache=0&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fsupports-color%2Fdownload%2Fsupports-color-7.1.0.tgz",
@@ -5720,9 +5726,9 @@
"dev": true
},
"highlight.js": {
"version": "9.16.2",
"resolved": "https://registry.npm.taobao.org/highlight.js/download/highlight.js-9.16.2.tgz",
"integrity": "sha1-aDaNA5/+HGIRvMB+SD2vld4+QD4="
"version": "11.3.1",
"resolved": "https://registry.npmmirror.com/highlight.js/download/highlight.js-11.3.1.tgz",
"integrity": "sha1-gTB47zqlGcYXAPhP6QRyMcXcMpE="
},
"highlight.js-async-webpack": {
"version": "1.0.4",
@@ -7009,6 +7015,13 @@
"highlight.js": "^9.11.0",
"highlight.js-async-webpack": "^1.0.4",
"xss": "^1.0.6"
},
"dependencies": {
"highlight.js": {
"version": "9.18.5",
"resolved": "https://registry.npmmirror.com/highlight.js/download/highlight.js-9.18.5.tgz",
"integrity": "sha1-0Yo1mGfzeME41oGe38KorNXymCU="
}
}
},
"md5.js": {
@@ -10800,6 +10813,13 @@
"integrity": "sha1-1mOeMJZNGsyzFvM7TjJm7cHmAS0=",
"requires": {
"highlight.js": "^9.13.1"
},
"dependencies": {
"highlight.js": {
"version": "9.18.5",
"resolved": "https://registry.npmmirror.com/highlight.js/download/highlight.js-9.18.5.tgz",
"integrity": "sha1-0Yo1mGfzeME41oGe38KorNXymCU="
}
}
},
"vue-hot-reload-api": {

View File

@@ -14,6 +14,7 @@
"jquery": "^3.5.1",
"js-cookie": "^2.2.1",
"mavon-editor": "^2.9.0",
"highlight.js": "^11.3.1",
"pouchdb": "^7.1.1",
"qrcodejs2": "0.0.2",
"sql-formatter": "^2.3.3",

View File

@@ -32,6 +32,18 @@ let vue = new Vue({
return h(App);
}
});
// 注册一个全局自定义指令
import hljs from 'highlight.js'
import 'highlight.js/styles/googlecode.css'
Vue.directive('highlight', function (el) {
let blocks = el.querySelectorAll('pre code');
blocks.forEach((block) => {
hljs.highlightBlock(block);
})
});
export default vue;

View File

@@ -55,7 +55,7 @@
</el-table>
</div>
<div ref="pageContent" class="wiki-page-content">
<div v-html="pageShowDetail" class="markdown-body" v-if="wikiPage.editorType == 2"></div>
<div v-html="pageShowDetail" class="markdown-body" v-if="wikiPage.editorType == 2" v-highlight></div>
<div v-html="pageShowDetail" class="wang-editor-body" v-else></div>
</div>
<div style="margin-top: 40px; font-size: 14px;">

View File

@@ -59,7 +59,15 @@ public class WikiPageCommentController {
public ResponseJson<List<WikiPageCommentVo>> list(WikiPageComment pageComment) {
DocUserDetails currentUser = DocUserUtil.getCurrentUser();
WikiPage wikiPageSel = wikiPageService.getById(pageComment.getPageId());
// 页面已删除
if (wikiPageSel == null || Objects.equals(wikiPageSel.getDelFlag(), 1)) {
return DocResponseJson.ok();
}
WikiSpace wikiSpaceSel = wikiSpaceService.getById(wikiPageSel.getSpaceId());
// 空间已删除
if (wikiSpaceSel == null || Objects.equals(wikiSpaceSel.getDelFlag(), 1)) {
return DocResponseJson.ok();
}
// 私人空间
if (SpaceType.isOthersPrivate(wikiSpaceSel.getType(), currentUser.getUserId(), wikiSpaceSel.getCreateUserId())) {
return DocResponseJson.warn("您没有查看该空间的评论权!");

View File

@@ -115,7 +115,15 @@ public class WikiPageController {
public ResponseJson<WikiPageContentVo> detail(WikiPage wikiPage) {
DocUserDetails currentUser = DocUserUtil.getCurrentUser();
WikiPage wikiPageSel = wikiPageService.getById(wikiPage.getId());
// 页面已删除
if (wikiPageSel == null || Objects.equals(wikiPageSel.getDelFlag(), 1)) {
return DocResponseJson.warn("该页面不存在或已删除!");
}
WikiSpace wikiSpaceSel = wikiSpaceService.getById(wikiPageSel.getSpaceId());
// 空间已删除
if (wikiSpaceSel == null || Objects.equals(wikiSpaceSel.getDelFlag(), 1)) {
return DocResponseJson.warn("该页面不存在或已删除!");
}
// 私人空间
if (SpaceType.isOthersPrivate(wikiSpaceSel.getType(), currentUser.getUserId(), wikiSpaceSel.getCreateUserId())) {
return DocResponseJson.warn("您没有权限查看该空间的文章详情!");

View File

@@ -22,6 +22,7 @@ import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import java.util.List;
import java.util.Objects;
/**
* 文档控制器
@@ -48,7 +49,15 @@ public class WikiPageHistoryController {
public ResponseJson<List<WikiPageHistory>> list(Long pageId, Integer pageNum) {
DocUserDetails currentUser = DocUserUtil.getCurrentUser();
WikiPage wikiPageSel = wikiPageService.getById(pageId);
// 私人空间
if (wikiPageSel == null || Objects.equals(wikiPageSel.getDelFlag(), 1)) {
return DocResponseJson.ok();
}
WikiSpace wikiSpaceSel = wikiSpaceService.getById(wikiPageSel.getSpaceId());
// 空间已删除
if (wikiSpaceSel == null || Objects.equals(wikiSpaceSel.getDelFlag(), 1)) {
return DocResponseJson.ok();
}
// 私人空间
if (SpaceType.isOthersPrivate(wikiSpaceSel.getType(), currentUser.getUserId(), wikiSpaceSel.getCreateUserId())) {
return DocResponseJson.warn("您没有权限查看该空间的文章详情!");