CommentToolBar.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. <template>
  2. <div class="comment-tool-bar">
  3. <div>
  4. <c-button v-if="isTeacher && !topNumber" @click="handleToTop" theme="green" text icon="publish">置顶</c-button>
  5. <c-button v-if="isTeacher && topNumber" @click="handleCancelToTop" theme="green" text icon="close">取消置顶</c-button>
  6. <c-button v-if="isOwn" @click="handleChangeShow" theme="orange" text :icon="personal ? 'lock_open' : 'lock'">
  7. {{personal ? '公开' : '设为私有'}}
  8. </c-button>
  9. <c-button v-if="isTeacher && !reply" @click="handleShowHideReplyInput" theme="blue" text icon="reply">回复
  10. </c-button>
  11. <c-button v-if="isTeacher && reply" @click="handleDeleteReply" theme="blue" text icon="cancel">删除回复</c-button>
  12. <c-button v-if="isOwn" @click="handleDeleteComment" theme="red" text icon="delete">删除留言</c-button>
  13. </div>
  14. <show-transition-small>
  15. <div v-show="replyInputShow && !reply" class="reply-input-wrapper vertical-center">
  16. <input ref="reply" placeholder="在此输入回复内容" v-model="replyContent">
  17. <icon-button :size="32" @click="handleReply" theme="green">send</icon-button>
  18. </div>
  19. </show-transition-small>
  20. </div>
  21. </template>
  22. <script>
  23. import IconButton from '@/components/Basic/IconButton'
  24. import { mapState } from 'vuex'
  25. import CButton from '@/components/Basic/CButton'
  26. import ShowTransitionSmall from '@/animations/ShowTransitionSmall'
  27. import { FOCUS_ON_INPUT, USE_FOCUS } from '@/store/types/pdf-types'
  28. export default {
  29. props: {
  30. userId: Number,
  31. reply: String,
  32. topNumber: [Number, String],
  33. personal: Boolean
  34. },
  35. components: { ShowTransitionSmall, CButton, IconButton },
  36. data () {
  37. return {
  38. replyInputShow: false,
  39. replyContent: ''
  40. }
  41. },
  42. watch: {
  43. replyInputShow () {
  44. if (this.replyInputShow) {
  45. this.$store.commit(FOCUS_ON_INPUT)
  46. } else {
  47. this.$store.commit(USE_FOCUS)
  48. }
  49. },
  50. focus (newValue) {
  51. if (this.replyInputShow && !newValue) {
  52. this.replyInputShow = false
  53. }
  54. }
  55. },
  56. computed: {
  57. ...mapState({
  58. userInfo: state => state.main.userInfo,
  59. focus: state => state.pdf.focus
  60. }),
  61. isOwn () {
  62. return this.userId === this.userInfo.id
  63. },
  64. isTeacher () {
  65. return this.userInfo.role === 'TEACHER'
  66. }
  67. },
  68. methods: {
  69. handleShowHideReplyInput () {
  70. setTimeout(() => {
  71. this.$refs.reply.focus()
  72. }, 10)
  73. this.replyInputShow = !this.replyInputShow
  74. },
  75. handleReply () {
  76. if (!this.replyContent) {
  77. this.$setInfoMessage('无法回复空消息')
  78. }
  79. this.$emit('reply', this.replyContent)
  80. },
  81. handleDeleteReply () {
  82. this.$emit('delete-reply')
  83. },
  84. handleDeleteComment () {
  85. this.$emit('delete-comment')
  86. },
  87. handleToTop () {
  88. this.$emit('to-top')
  89. },
  90. handleCancelToTop () {
  91. this.$emit('cancel-to-top')
  92. },
  93. handleChangeShow () {
  94. this.$emit('change-show')
  95. }
  96. }
  97. }
  98. </script>
  99. <style lang="scss" scoped>
  100. @import '~@/style/theme.scss';
  101. .comment-tool-bar {
  102. margin: 0 -16px 2px -16px;
  103. }
  104. .c-button {
  105. opacity: .5;
  106. transform: scale(.9);
  107. margin-right: -12px;
  108. &:hover {
  109. opacity: 1;
  110. }
  111. }
  112. .reply-input-wrapper {
  113. input {
  114. background-color: rgba(255, 255, 255, 0.5);
  115. height: 36px;
  116. font-size: 14px;
  117. margin-left: 12px;
  118. }
  119. .icon-button {
  120. margin: 0 12px 0 8px;
  121. }
  122. }
  123. input, textarea {
  124. box-sizing: border-box;
  125. font-size: 16px;
  126. font-weight: bold;
  127. color: #3a4a5a;
  128. background: $input-background-color;
  129. border-radius: 8px;
  130. border: none;
  131. outline: none;
  132. width: 100%;
  133. height: 40px;
  134. line-height: 1.5;
  135. padding: 0 12px 0 12px;
  136. transition: .2s;
  137. &:hover {
  138. background: $input-hover-background-color;
  139. }
  140. &::placeholder {
  141. color: #8a9aaa;
  142. }
  143. }
  144. </style>