CComment.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. <template>
  2. <div class="comment">
  3. <div>
  4. <div class="comment-title">
  5. <span v-if="comment.topNumber" class="icon blue">{{iconMap['put_on_top']}}</span>
  6. 主题:{{comment.title}}
  7. </div>
  8. <div class="comment-content">{{comment.content}}</div>
  9. <div class="comment-author">{{createTime}} | 作者:{{comment.userName}} <span class="role">{{role}}</span></div>
  10. <comment-tool-bar
  11. :top-number="comment.topNumber || ''"
  12. :user-id="comment.userId" :has-reply="comment.reply || ''"
  13. @reply="handleReply"
  14. @delete-reply="handleDeleteReply"
  15. @delete-comment="handleDeleteComment"
  16. @to-top="handleToTop"
  17. @cancel-to-top="handleCancelToTop"
  18. >
  19. </comment-tool-bar>
  20. <div v-if="comment.reply" class="comment-reply">
  21. <div>教师回复:{{comment.reply.content}}</div>
  22. <div class="comment-reply-time">{{replyTime}}</div>
  23. </div>
  24. </div>
  25. </div>
  26. </template>
  27. <script>
  28. import { mapState } from 'vuex'
  29. import iconMap from '@/utils/icon-map'
  30. import { createReply, removeReply } from '@/server/reply'
  31. import { removeComment, topComment, unTopComment } from '@/server/comment'
  32. import CommentToolBar from '@/components/CommentToolBar'
  33. export default {
  34. components: { CommentToolBar },
  35. props: ['comment'],
  36. data () {
  37. return {
  38. replyContent: '',
  39. iconMap: iconMap
  40. }
  41. },
  42. computed: {
  43. ...mapState({
  44. userInfo: state => state.main.userInfo
  45. }),
  46. createTime () {
  47. return this.$moment(this.comment.createAt).fromNow()
  48. },
  49. replyTime () {
  50. return this.$moment(this.comment.reply.createAt).fromNow()
  51. },
  52. role () {
  53. if (this.comment.userType === 'TEACHER') {
  54. return '教师'
  55. } else if (this.comment.userType === 'STUDENT') {
  56. return '学生'
  57. }
  58. return '身份未知'
  59. }
  60. },
  61. methods: {
  62. handleReply (reply) {
  63. createReply({ commentId: this.comment.id, content: reply }).then(res => {
  64. this.$setSuccessMessage('回复成功')
  65. this.$emit('need-refresh')
  66. }).catch(err => {
  67. this.$setErrorMessage(err.response.data.msg)
  68. })
  69. },
  70. handleDeleteReply () {
  71. const msg = '确定删除该回复吗:\n\n' + this.comment.reply.content
  72. if (confirm(msg)) {
  73. removeReply({ replyId: this.comment.reply.id }).then(res => {
  74. this.$setSuccessMessage('删除成功')
  75. this.$emit('need-refresh')
  76. }).catch(err => {
  77. this.$setErrorMessage(err.response.data.msg)
  78. })
  79. }
  80. },
  81. handleDeleteComment () {
  82. const msg = '确定删除该评论吗:\n\n' + '主题:' + this.comment.title
  83. if (confirm(msg)) {
  84. removeComment({ commentId: this.comment.id }).then(res => {
  85. this.$setSuccessMessage('删除成功')
  86. this.$emit('need-refresh')
  87. }).catch(err => {
  88. this.$setErrorMessage(err.response.data.msg)
  89. })
  90. }
  91. },
  92. handleToTop () {
  93. topComment({ commentId: this.comment.id }).then(res => {
  94. this.$setSuccessMessage('置顶成功')
  95. this.$emit('need-refresh')
  96. }).catch(err => {
  97. this.$setErrorMessage(err.response.data.msg)
  98. })
  99. },
  100. handleCancelToTop () {
  101. unTopComment({ commentId: this.comment.id }).then(res => {
  102. this.$setSuccessMessage('取消置顶成功')
  103. this.$emit('need-refresh')
  104. }).catch(err => {
  105. this.$setErrorMessage(err.response.data.msg)
  106. })
  107. }
  108. }
  109. }
  110. </script>
  111. <style lang="scss" scoped>
  112. @import '~@/style/theme.scss';
  113. .comment {
  114. width: 100%;
  115. padding: 16px 0 16px 0;
  116. font-weight: bold;
  117. }
  118. .comment-title {
  119. margin-bottom: 12px;
  120. }
  121. .comment-content {
  122. color: #6a7a8a;
  123. font-size: 14px;
  124. margin-bottom: 8px;
  125. }
  126. .comment-author {
  127. font-size: 14px;
  128. color: #7a8a9a;
  129. margin-bottom: 8px;
  130. .role {
  131. display: inline-block;
  132. padding: 1px 4px;
  133. color: $theme-blue;
  134. background: $theme-blue-transparent;
  135. font-size: 12px;
  136. }
  137. }
  138. .comment-reply {
  139. font-size: 14px;
  140. padding: 4px 8px;
  141. background: $theme-orange-transparent;
  142. &-time {
  143. color: #8a9aaa;
  144. }
  145. }
  146. .icon {
  147. font-family: 'iconfont', sans-serif;
  148. text-align: center;
  149. padding: 4px 0;
  150. color: #7a8a9a;
  151. span {
  152. font-size: 12px;
  153. }
  154. }
  155. .blue {
  156. color: $theme-blue;
  157. font-size: 16px;
  158. transform: scale(1.2);
  159. }
  160. </style>