|
|
@@ -1,45 +1,42 @@
|
|
|
<template>
|
|
|
<div class="comment">
|
|
|
- <div @click="showActions = !showActions">
|
|
|
- <div class="comment-title">主题:{{comment.title}}</div>
|
|
|
+ <div>
|
|
|
+ <div class="comment-title">
|
|
|
+ <span v-if="comment.topNumber" class="icon blue">{{iconMap['put_on_top']}}</span>
|
|
|
+ 主题:{{comment.title}}
|
|
|
+ </div>
|
|
|
<div class="comment-content">{{comment.content}}</div>
|
|
|
<div class="comment-author">{{createTime}} | 作者:{{comment.userName}} <span class="role">{{role}}</span></div>
|
|
|
+ <comment-tool-bar
|
|
|
+ :top-number="comment.topNumber || ''"
|
|
|
+ :user-id="comment.userId" :has-reply="comment.reply || ''"
|
|
|
+ @reply="handleReply"
|
|
|
+ @delete-reply="handleDeleteReply"
|
|
|
+ @delete-comment="handleDeleteComment"
|
|
|
+ @to-top="handleToTop"
|
|
|
+ @cancel-to-top="handleCancelToTop"
|
|
|
+ >
|
|
|
+ </comment-tool-bar>
|
|
|
<div v-if="comment.reply" class="comment-reply">
|
|
|
<div>教师回复:{{comment.reply.content}}</div>
|
|
|
<div class="comment-reply-time">{{replyTime}}</div>
|
|
|
</div>
|
|
|
</div>
|
|
|
- <template v-if="showActions && hasActions">
|
|
|
- <div v-if="isTeacher && !comment.reply" class="mt-8 mb-8">
|
|
|
- <c-input textarea="true" placeholder="在此输入回复" class="mb-8" v-model="replyContent"></c-input>
|
|
|
- <c-button class="full-width secondary" @click="handleCreateReply">提交回复</c-button>
|
|
|
- </div>
|
|
|
- <template v-if="isTeacher && comment.reply">
|
|
|
- <c-button class="full-width warning mt-16 mb-8" @click="handleDeleteReply">删除回复</c-button>
|
|
|
- </template>
|
|
|
- <c-button v-if="canDelete" class="error full-width mb-8" @click="handleDeleteComment">删除评论</c-button>
|
|
|
- </template>
|
|
|
- <div v-if="hasActions" class="icon" @click="showActions = !showActions">
|
|
|
- {{iconMap[showActions ? 'up' : 'down']}}
|
|
|
- <span>{{showActions ? '隐藏操作' : '更多操作'}}</span>
|
|
|
- </div>
|
|
|
</div>
|
|
|
</template>
|
|
|
|
|
|
<script>
|
|
|
import { mapState } from 'vuex'
|
|
|
import iconMap from '@/utils/icon-map'
|
|
|
-import CButton from '@/components/CButton'
|
|
|
-import CInput from '@/components/CInput'
|
|
|
import { createReply, removeReply } from '@/server/reply'
|
|
|
-import { removeComment } from '@/server/comment'
|
|
|
+import { removeComment, topComment, unTopComment } from '@/server/comment'
|
|
|
+import CommentToolBar from '@/components/CommentToolBar'
|
|
|
|
|
|
export default {
|
|
|
- components: { CInput, CButton },
|
|
|
+ components: { CommentToolBar },
|
|
|
props: ['comment'],
|
|
|
data () {
|
|
|
return {
|
|
|
- showActions: false,
|
|
|
replyContent: '',
|
|
|
iconMap: iconMap
|
|
|
}
|
|
|
@@ -48,15 +45,6 @@ export default {
|
|
|
...mapState({
|
|
|
userInfo: state => state.main.userInfo
|
|
|
}),
|
|
|
- canDelete () {
|
|
|
- return this.userInfo.id === this.comment.userId
|
|
|
- },
|
|
|
- isTeacher () {
|
|
|
- return this.userInfo.type === 'TEACHER'
|
|
|
- },
|
|
|
- hasActions () {
|
|
|
- return this.isTeacher || this.canDelete
|
|
|
- },
|
|
|
createTime () {
|
|
|
return this.$moment(this.comment.createAt).fromNow()
|
|
|
},
|
|
|
@@ -73,8 +61,8 @@ export default {
|
|
|
}
|
|
|
},
|
|
|
methods: {
|
|
|
- handleCreateReply () {
|
|
|
- createReply({ commentId: this.comment.id, content: this.replyContent }).then(res => {
|
|
|
+ handleReply (reply) {
|
|
|
+ createReply({ commentId: this.comment.id, content: reply }).then(res => {
|
|
|
this.$setSuccessMessage('回复成功')
|
|
|
this.$emit('need-refresh')
|
|
|
}).catch(err => {
|
|
|
@@ -102,6 +90,22 @@ export default {
|
|
|
this.$setErrorMessage(err.response.data.msg)
|
|
|
})
|
|
|
}
|
|
|
+ },
|
|
|
+ handleToTop () {
|
|
|
+ topComment({ commentId: this.comment.id }).then(res => {
|
|
|
+ this.$setSuccessMessage('置顶成功')
|
|
|
+ this.$emit('need-refresh')
|
|
|
+ }).catch(err => {
|
|
|
+ this.$setErrorMessage(err.response.data.msg)
|
|
|
+ })
|
|
|
+ },
|
|
|
+ handleCancelToTop () {
|
|
|
+ unTopComment({ commentId: this.comment.id }).then(res => {
|
|
|
+ this.$setSuccessMessage('取消置顶成功')
|
|
|
+ this.$emit('need-refresh')
|
|
|
+ }).catch(err => {
|
|
|
+ this.$setErrorMessage(err.response.data.msg)
|
|
|
+ })
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -160,4 +164,10 @@ export default {
|
|
|
font-size: 12px;
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+.blue {
|
|
|
+ color: $theme-blue;
|
|
|
+ font-size: 16px;
|
|
|
+ transform: scale(1.2);
|
|
|
+}
|
|
|
</style>
|