WriteNewComment.vue 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. <template>
  2. <div class="write-new-comment">
  3. <label>
  4. <input ref="title" @keydown="handleTitleKey" type="text" v-model="title" :placeholder="placeholder || '讨论主题'" maxlength="100">
  5. </label>
  6. <label>
  7. <textarea @keyup="handleContentKey" ref="content" v-model="content" placeholder="详细内容"></textarea>
  8. </label>
  9. <icon-button class="send-button" theme="green" @click="handleSubmitComment" :size="32">send</icon-button>
  10. </div>
  11. </template>
  12. <script>
  13. import IconButton from '@/components/Basic/IconButton'
  14. import { mapState } from 'vuex'
  15. export default {
  16. props: ['placeholder'],
  17. components: { IconButton },
  18. computed: {
  19. ...mapState({
  20. focus: state => state.pdf.focus
  21. })
  22. },
  23. watch: {
  24. focus: {
  25. handler () {
  26. this.focus && this.$refs.title.focus()
  27. }
  28. }
  29. },
  30. data () {
  31. return {
  32. title: '',
  33. content: ''
  34. }
  35. },
  36. methods: {
  37. handleSubmitComment () {
  38. if (!(this.title && this.content)) {
  39. this.$setInfoMessage('主题和内容均需要填写')
  40. return
  41. }
  42. this.$emit('comment-submit', { title: this.title, content: this.content })
  43. },
  44. resetContent () {
  45. this.title = ''
  46. this.content = ''
  47. },
  48. handleTitleKey (e) {
  49. if (this.title && !e.isComposing && e.key === 'Enter') {
  50. this.$refs.content.focus()
  51. e.preventDefault()
  52. }
  53. if (e.shiftKey && !e.isComposing && e.key === 'Enter') {
  54. e.preventDefault()
  55. this.handleSubmitComment()
  56. }
  57. },
  58. handleContentKey (e) {
  59. if (e.shiftKey && !e.isComposing && e.key === 'Enter') {
  60. e.preventDefault()
  61. this.handleSubmitComment()
  62. }
  63. }
  64. }
  65. }
  66. </script>
  67. <style lang="scss" scoped>
  68. @import '~@/style/theme.scss';
  69. .write-new-comment {
  70. position: relative;
  71. }
  72. input, textarea {
  73. box-sizing: border-box;
  74. font-size: 14px;
  75. color: #3a4a5a;
  76. border-radius: 4px;
  77. border: none;
  78. outline: none;
  79. width: 100%;
  80. height: 36px;
  81. line-height: 1.6;
  82. padding: 8px;
  83. transition: .2s;
  84. background-color: transparent;
  85. &:hover {
  86. border-color: #6a7a8a;
  87. transform: translateY(-1px);
  88. }
  89. &::placeholder {
  90. color: #9aaaba;
  91. }
  92. }
  93. input {
  94. border-radius: 4px 4px 0 0;
  95. border: 1px solid #bacada;
  96. }
  97. textarea {
  98. transform: translateY(-1px);
  99. border-radius: 0 0 4px 4px;
  100. border: 1px solid #bacada;
  101. min-height: 96px;
  102. padding-bottom: 32px;
  103. height: 100%;
  104. resize: vertical;
  105. }
  106. .send-button {
  107. position: absolute;
  108. bottom: 12px;
  109. right: 12px;
  110. background: white;
  111. &:hover {
  112. background: lighten($theme-green-light, 2);
  113. }
  114. }
  115. </style>