inputArea.vue 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. <template>
  2. <div class="box-ft">
  3. <transition name="msgbox-fade">
  4. <Emoji v-show="emojiShow" :emojiShow="emojiShow" @addEmoji="addEmoji" @closeEmojiList="closeEmojiList"></Emoji>
  5. </transition>
  6. <file-preview v-show="filePreviewShow" :fileInfo='fileInfo' @handleFileSend="handleFileSend" @closeFilePreview="closeFilePreview"></file-preview>
  7. <chat-at
  8. ref="chatAt"
  9. v-if="atShow"
  10. @atperson="atPerson"
  11. :curInd="atInd"
  12. :filterList="filterMembers"
  13. ></chat-at>
  14. <div class="toolbar">
  15. <i class="look-icon" @click.stop="handleEmoji"></i>
  16. <div class="file-icon">
  17. <input type="file" ref="inputFile" @change="handleFile">
  18. </div>
  19. <i class="icon-packet" @click="$packetSend"></i>
  20. </div>
  21. <div class="send-content">
  22. <form class="input-wrap" @submit="handleSend">
  23. <textarea
  24. @click.stop="handleClick"
  25. @input="handleInput"
  26. @keydown.up="handleUp"
  27. @keydown.down="handleDown"
  28. @keydown.left="handleLeft"
  29. @keydown.right="handleRight"
  30. @keydown.delete="handleDel"
  31. @keydown.esc="handleEsc"
  32. cols="1"
  33. ref="chatInput"
  34. rows="1"
  35. @keydown.enter="handleKeyDown"
  36. placeholder
  37. v-focus
  38. v-model="inputMsg"
  39. @focus="handleFocus"
  40. @blur="handleBlur"
  41. @contextmenu.prevent="handleContextmenu"
  42. />
  43. </form>
  44. <ul class="pub-pop-toolbar" v-show="isShowContextmenu" :style="{top:`${menuTop}px`,left:`${menuLeft}px`}">
  45. <li @click.prevent="handlePaste">{{$t('chat.paste')}}</li>
  46. </ul>
  47. </div>
  48. <div class="send-action">{{$t('chat.enterTips')}}
  49. <el-button @click="handleSend" :disabled="!!!inputMsg">{{$t('chat.send')}}</el-button>
  50. </div>
  51. </div>
  52. </template>
  53. <script>
  54. import Emoji from '@/components/emoji'
  55. import chatAt from '@/components/chatAt'
  56. import filePreview from './filePreview'
  57. import { mapState } from 'vuex'
  58. import { chatAtMixin, chatInputMixin } from '@/mixins'
  59. import { inputMixin } from '@/mixins/chat'
  60. export default {
  61. name: 'inputArea',
  62. mixins: [chatAtMixin, chatInputMixin, inputMixin],
  63. components: {
  64. Emoji,
  65. chatAt,
  66. filePreview
  67. },
  68. watch: {
  69. '$route' () {
  70. this.$refs.chatInput.focus()
  71. this.inputMsg = ''
  72. }
  73. },
  74. computed: {
  75. ...mapState(['curSession'])
  76. },
  77. mounted () {
  78. document.addEventListener('paste', this.initPaste)
  79. document.addEventListener('drop', this.initDrop)
  80. document.addEventListener('dragover', this.initDragOver)
  81. },
  82. beforeDestroy () {
  83. document.removeEventListener('paste', this.initPaste)
  84. document.removeEventListener('drop', this.initDrop)
  85. document.removeEventListener('dragover', this.initDragOver)
  86. },
  87. methods: {
  88. handleEmoji () {
  89. this.emojiShow = !this.emojiShow
  90. },
  91. initDrop (e) {
  92. e.preventDefault()
  93. let files = Array.from(e.dataTransfer.files)
  94. files.forEach(file => this.handleFile(file))
  95. },
  96. initDragOver (e) {
  97. e.preventDefault()
  98. },
  99. initPaste (event) {
  100. var items = (event.clipboardData || window.clipboardData).items
  101. if (items && items.length) {
  102. Array.from(items).forEach(item => {
  103. let file = item.getAsFile()
  104. if (file) {
  105. this.handleFile(file)
  106. }
  107. })
  108. }
  109. }
  110. }
  111. }
  112. </script>
  113. <style lang="scss" scoped>
  114. .box-ft {
  115. height: 180px;
  116. border-top: 1px solid #d6d6d6;
  117. padding-right: 16px;
  118. position: relative;
  119. background: #eeeeee;
  120. }
  121. .toolbar {
  122. padding: 10px 20px;
  123. font-size: 0;
  124. background: #eee;
  125. i {
  126. color: #333333;
  127. font-size: 18px;
  128. margin-right: 15px;
  129. vertical-align: middle;
  130. cursor: pointer;
  131. }
  132. }
  133. .send-action {
  134. text-align: right;
  135. }
  136. .look-icon {
  137. background: url("../../assets/icon-face.png") no-repeat;
  138. background-size: 100%;
  139. width: 20px;
  140. height: 20px;
  141. display: inline-block;
  142. vertical-align: middle;
  143. cursor: pointer;
  144. }
  145. .file-icon {
  146. background: url("../../assets/icon-file.png") no-repeat;
  147. background-size: 100%;
  148. width: 19px;
  149. height: 18px;
  150. display: inline-block;
  151. vertical-align: middle;
  152. position: relative;
  153. input[type="file"] {
  154. cursor: pointer;
  155. opacity: 0;
  156. position: absolute;
  157. top: 0;
  158. left: 0;
  159. z-index: 1;
  160. width: 100%;
  161. height: 100%;
  162. }
  163. }
  164. .send-action {
  165. color: #bababa;
  166. font-size: 12px;
  167. button {
  168. margin-left: 10px;
  169. }
  170. }
  171. .input-wrap {
  172. textarea {
  173. display: block;
  174. background-color: #eee;
  175. width: 100%;
  176. box-sizing: border-box;
  177. resize: none;
  178. height: 90px;
  179. line-height: 1.4;
  180. padding-left: 20px;
  181. outline: none;
  182. border: 0;
  183. font-size: 14px;
  184. margin-bottom: 10px;
  185. }
  186. }
  187. .icon-packet{
  188. display: inline-block;
  189. margin-left: 20px;
  190. vertical-align: middle;
  191. background: url('../../assets/icon-packet.png') center center no-repeat;
  192. background-size: 100%;
  193. width: 21px;
  194. height: 21px;
  195. }
  196. .pub-pop-toolbar{
  197. right: auto;
  198. }
  199. </style>