This commit is contained in:
Himit_ZH 2021-06-29 23:22:34 +08:00
parent 3e40500a49
commit 6e4e8a44de
11 changed files with 53 additions and 47 deletions

View File

@ -157,7 +157,10 @@ public class CommentController {
if (comment.getFromUid().equals(userRolesVo.getUid()) || SecurityUtils.getSubject().hasRole("root") if (comment.getFromUid().equals(userRolesVo.getUid()) || SecurityUtils.getSubject().hasRole("root")
|| SecurityUtils.getSubject().hasRole("admin") || SecurityUtils.getSubject().hasRole("problem_admin")) { || SecurityUtils.getSubject().hasRole("admin") || SecurityUtils.getSubject().hasRole("problem_admin")) {
// 删除该数据 // 获取需要删除该评论的回复数
int replyNum = replyService.count(new UpdateWrapper<Reply>().eq("comment_id", comment.getId()));
// 删除该数据 包括关联外键的reply表数据
boolean isDeleteComment = commentService.remove(new UpdateWrapper<Comment>().eq("id", comment.getId())); boolean isDeleteComment = commentService.remove(new UpdateWrapper<Comment>().eq("id", comment.getId()));
// 同时需要删除该评论的回复表数据 // 同时需要删除该评论的回复表数据
@ -168,7 +171,7 @@ public class CommentController {
if (comment.getDid() != null) { if (comment.getDid() != null) {
UpdateWrapper<Discussion> discussionUpdateWrapper = new UpdateWrapper<>(); UpdateWrapper<Discussion> discussionUpdateWrapper = new UpdateWrapper<>();
discussionUpdateWrapper.eq("id", comment.getDid()) discussionUpdateWrapper.eq("id", comment.getDid())
.setSql("comment_num=comment_num-1"); .setSql("comment_num=comment_num" + (replyNum + 1));
discussionService.update(discussionUpdateWrapper); discussionService.update(discussionUpdateWrapper);
} }
return CommonResult.successResponse(null, "删除成功"); return CommonResult.successResponse(null, "删除成功");

View File

@ -1089,6 +1089,14 @@
"@hapi/hoek": "^8.3.0" "@hapi/hoek": "^8.3.0"
} }
}, },
"@iktakahiro/markdown-it-katex": {
"version": "4.0.1",
"resolved": "https://registry.npm.taobao.org/@iktakahiro/markdown-it-katex/download/@iktakahiro/markdown-it-katex-4.0.1.tgz",
"integrity": "sha1-Zf+dEq/UwLdoTdJHq+fOQvwe2sM=",
"requires": {
"katex": "^0.12.0"
}
},
"@intervolga/optimize-cssnano-plugin": { "@intervolga/optimize-cssnano-plugin": {
"version": "1.0.6", "version": "1.0.6",
"resolved": "https://registry.npm.taobao.org/@intervolga/optimize-cssnano-plugin/download/@intervolga/optimize-cssnano-plugin-1.0.6.tgz", "resolved": "https://registry.npm.taobao.org/@intervolga/optimize-cssnano-plugin/download/@intervolga/optimize-cssnano-plugin-1.0.6.tgz",

View File

@ -7,6 +7,7 @@
"build": "vue-cli-service build" "build": "vue-cli-service build"
}, },
"dependencies": { "dependencies": {
"@iktakahiro/markdown-it-katex": "^4.0.1",
"axios": "^0.21.0", "axios": "^0.21.0",
"browser-detect": "^0.2.28", "browser-detect": "^0.2.28",
"compression-webpack-plugin": "^5.0.1", "compression-webpack-plugin": "^5.0.1",
@ -16,7 +17,6 @@
"font-awesome": "^4.7.0", "font-awesome": "^4.7.0",
"highlight.js": "^10.3.2", "highlight.js": "^10.3.2",
"jquery": "^3.5.1", "jquery": "^3.5.1",
"katex": "^0.12.0",
"mavon-editor": "^2.9.1", "mavon-editor": "^2.9.1",
"moment": "^2.29.1", "moment": "^2.29.1",
"muse-ui": "^3.0.2", "muse-ui": "^3.0.2",

View File

@ -1,45 +1,45 @@
<template> <template>
<el-form> <el-form>
<el-form-item label="Input"> <el-form-item label="Input">
<el-input type="textarea" v-model="input" @change="changeInput" @keyup.enter.native="changeInput"></el-input> <el-input
type="textarea"
v-model="input"
@change="changeInput"
@keyup.enter.native="changeInput"
></el-input>
</el-form-item> </el-form-item>
<el-form-item label="Output"> <el-form-item label="Output"> </el-form-item>
</el-form-item>
<div v-html="text"></div> <div v-html="text"></div>
</el-form> </el-form>
</template> </template>
<script> <script>
import katex from 'katex' export default {
export default { name: '',
name: '', data() {
data () { return {
return { input: '$c = \\pm\\sqrt{a^2 + b^2}$',
input: 'c = \\pm\\sqrt{a^2 + b^2}', text: '',
text: '' };
},
mounted() {
this.text = this.renderTex(this.input);
},
methods: {
renderTex(data) {
return this.$markDown.render(data);
},
changeInput() {
try {
this.text = this.renderTex(this.input);
} catch (e) {
this.text =
'<p style="text-align: center"><span style="color:red">Error Input</span></p>';
} }
}, },
mounted () { },
this.text = this.renderTex(this.input) };
},
methods: {
renderTex (data) {
return katex.renderToString(data, {
displayMode: true,
throwOnError: false
})
},
changeInput () {
try {
this.text = this.renderTex(this.input)
} catch (e) {
this.text = '<p style="text-align: center"><span style="color:red">Error Input</span></p>'
}
}
}
}
</script> </script>
<style scoped> <style scoped></style>
</style>

View File

@ -717,9 +717,8 @@ export default {
}) })
.then(() => { .then(() => {
let replyDeleteData = { let replyDeleteData = {
id: reply.id,
did: this.did, did: this.did,
fromUid: reply.fromUid, reply: reply,
}; };
api.deleteReply(replyDeleteData).then((res) => { api.deleteReply(replyDeleteData).then((res) => {
myMessage.success(res.data.msg); myMessage.success(res.data.msg);

View File

@ -10,6 +10,8 @@ import Message from 'vue-m-message'
import 'vue-m-message/dist/index.css' import 'vue-m-message/dist/index.css'
import axios from 'axios' import axios from 'axios'
import Md_Katex from '@iktakahiro/markdown-it-katex'
// 注释表示使用cdn引入 // 注释表示使用cdn引入
// import 'xe-utils' // import 'xe-utils'
// import VXETable from 'vxe-table' // import VXETable from 'vxe-table'
@ -81,7 +83,7 @@ Vue.use(SlideVerify) // 滑动验证码组件
Vue.prototype.$axios = axios Vue.prototype.$axios = axios
Vue.prototype.$markDown = mavonEditor.markdownIt Vue.prototype.$markDown = mavonEditor.markdownIt.use(Md_Katex) // 挂载到vue
Vue.config.productionTip = false Vue.config.productionTip = false
new Vue({ new Vue({

View File

@ -61,7 +61,6 @@
<div class="contest-description"> <div class="contest-description">
<blockquote <blockquote
v-html="contest.description" v-html="contest.description"
v-katex
v-highlight v-highlight
class="markdown-body" class="markdown-body"
></blockquote> ></blockquote>

View File

@ -100,7 +100,6 @@
<el-card class="box-card"> <el-card class="box-card">
<div <div
v-html="descriptionHtml" v-html="descriptionHtml"
v-katex
v-highlight v-highlight
class="markdown-body" class="markdown-body"
></div> ></div>

View File

@ -96,12 +96,7 @@
</div> </div>
</div> </div>
<div class="body-article"> <div class="body-article">
<div <div class="markdown-body" v-html="contentHtml" v-highlight></div>
class="markdown-body"
v-html="contentHtml"
v-katex
v-highlight
></div>
</div> </div>
</div> </div>
<el-dialog <el-dialog
@ -325,6 +320,8 @@ export default {
contentHtml() { contentHtml() {
if (this.discussion.content) { if (this.discussion.content) {
return this.$markDown.render(this.discussion.content); return this.$markDown.render(this.discussion.content);
} else {
return null;
} }
}, },
}, },

View File

@ -110,7 +110,6 @@
<div <div
class="markdown-body" class="markdown-body"
v-html="contentHtml" v-html="contentHtml"
v-katex
v-highlight v-highlight
v-if="contentHtml" v-if="contentHtml"
></div> ></div>

View File

@ -27,7 +27,7 @@ const cdn = {
css: [ css: [
'https://cdn.bootcdn.net/ajax/libs/element-ui/2.14.0/theme-chalk/index.min.css', 'https://cdn.bootcdn.net/ajax/libs/element-ui/2.14.0/theme-chalk/index.min.css',
"https://cdn.bootcdn.net/ajax/libs/github-markdown-css/4.0.0/github-markdown.min.css", "https://cdn.bootcdn.net/ajax/libs/github-markdown-css/4.0.0/github-markdown.min.css",
"https://cdn.jsdelivr.net/npm/vxe-table@2.9.26/lib/style.css" "https://cdn.jsdelivr.net/npm/vxe-table@2.9.26/lib/style.css",
], ],
// cdn的js链接 // cdn的js链接
js: [ js: [