|
|
@@ -1,19 +1,68 @@
|
|
|
<template>
|
|
|
<div class="comment">
|
|
|
- <div class="comment-title">主题:{{comment.title}}</div>
|
|
|
- <div class="comment-content">详情:{{comment.content}}</div>
|
|
|
- <div class="comment-author">{{createTime}} | 作者:{{comment.userName}} <span class="role">{{role}}</span></div>
|
|
|
- <div v-if="comment.reply" class="comment-reply">教师回复:{{comment.reply}}</div>
|
|
|
+ <div @click="showActions = !showActions">
|
|
|
+ <div class="comment-title">主题:{{comment.title}}</div>
|
|
|
+ <div class="comment-content">详情:{{comment.content}}</div>
|
|
|
+ <div class="comment-author">{{createTime}} | 作者:{{comment.userName}} <span class="role">{{role}}</span></div>
|
|
|
+ <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'
|
|
|
+
|
|
|
export default {
|
|
|
+ components: { CInput, CButton },
|
|
|
props: ['comment'],
|
|
|
+ data () {
|
|
|
+ return {
|
|
|
+ showActions: false,
|
|
|
+ replyContent: '',
|
|
|
+ iconMap: iconMap
|
|
|
+ }
|
|
|
+ },
|
|
|
computed: {
|
|
|
+ ...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()
|
|
|
},
|
|
|
+ replyTime () {
|
|
|
+ return this.$moment(this.comment.reply.createAt).fromNow()
|
|
|
+ },
|
|
|
role () {
|
|
|
if (this.comment.userType === 'TEACHER') {
|
|
|
return '教师'
|
|
|
@@ -22,6 +71,38 @@ export default {
|
|
|
}
|
|
|
return '身份未知'
|
|
|
}
|
|
|
+ },
|
|
|
+ methods: {
|
|
|
+ handleCreateReply () {
|
|
|
+ createReply({ commentId: this.comment.id, content: this.replyContent }).then(res => {
|
|
|
+ this.$setSuccessMessage('回复成功')
|
|
|
+ this.$emit('need-refresh')
|
|
|
+ }).catch(err => {
|
|
|
+ this.$setErrorMessage(err.response.data.msg)
|
|
|
+ })
|
|
|
+ },
|
|
|
+ handleDeleteReply () {
|
|
|
+ const msg = '确定删除该回复吗:\n\n' + this.comment.reply.content
|
|
|
+ if (confirm(msg)) {
|
|
|
+ removeReply({ replyId: this.comment.reply.id }).then(res => {
|
|
|
+ this.$setSuccessMessage('删除成功')
|
|
|
+ this.$emit('need-refresh')
|
|
|
+ }).catch(err => {
|
|
|
+ this.$setErrorMessage(err.response.data.msg)
|
|
|
+ })
|
|
|
+ }
|
|
|
+ },
|
|
|
+ handleDeleteComment () {
|
|
|
+ const msg = '确定删除该评论吗:\n\n' + '主题:' + this.comment.title
|
|
|
+ if (confirm(msg)) {
|
|
|
+ removeComment({ commentId: this.comment.id }).then(res => {
|
|
|
+ this.$setSuccessMessage('删除成功')
|
|
|
+ this.$emit('need-refresh')
|
|
|
+ }).catch(err => {
|
|
|
+ this.$setErrorMessage(err.response.data.msg)
|
|
|
+ })
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
</script>
|
|
|
@@ -31,7 +112,7 @@ export default {
|
|
|
|
|
|
.comment {
|
|
|
width: 100%;
|
|
|
- padding: 16px 0 24px 0;
|
|
|
+ padding: 16px 0 16px 0;
|
|
|
font-weight: bold;
|
|
|
}
|
|
|
|
|
|
@@ -48,7 +129,8 @@ export default {
|
|
|
.comment-author {
|
|
|
font-size: 14px;
|
|
|
color: #7a8a9a;
|
|
|
- margin-bottom: 4px;
|
|
|
+ margin-bottom: 8px;
|
|
|
+
|
|
|
.role {
|
|
|
display: inline-block;
|
|
|
padding: 1px 4px;
|
|
|
@@ -62,5 +144,20 @@ export default {
|
|
|
font-size: 14px;
|
|
|
padding: 4px 8px;
|
|
|
background: $theme-orange-transparent;
|
|
|
+
|
|
|
+ &-time {
|
|
|
+ color: #8a9aaa;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+.icon {
|
|
|
+ font-family: 'iconfont', sans-serif;
|
|
|
+ text-align: center;
|
|
|
+ padding: 4px 0;
|
|
|
+ color: #7a8a9a;
|
|
|
+
|
|
|
+ span {
|
|
|
+ font-size: 12px;
|
|
|
+ }
|
|
|
}
|
|
|
</style>
|