inputArea.vue 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  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" @keydown.enter="handleFileEnter">
  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. handleFileEnter (e) {
  89. if (this.filePreviewShow) {
  90. e.stopPropagation()
  91. e.preventDefault()
  92. this.handleFileSend(this.fileInfo)
  93. }
  94. },
  95. handleEmoji () {
  96. this.emojiShow = !this.emojiShow
  97. },
  98. initDrop (e) {
  99. e.preventDefault()
  100. let files = Array.from(e.dataTransfer.files)
  101. files.forEach(file => this.handleFile(file))
  102. },
  103. initDragOver (e) {
  104. e.preventDefault()
  105. },
  106. initPaste (event) {
  107. var items = (event.clipboardData || window.clipboardData).items
  108. if (items && items.length) {
  109. Array.from(items).forEach(item => {
  110. let file = item.getAsFile()
  111. if (file) {
  112. this.handleFile(file)
  113. }
  114. })
  115. }
  116. }
  117. }
  118. }
  119. </script>
  120. <style lang="scss" scoped>
  121. .box-ft {
  122. height: 180px;
  123. border-top: 1px solid #d6d6d6;
  124. padding-right: 16px;
  125. position: relative;
  126. background: #eeeeee;
  127. }
  128. .toolbar {
  129. padding: 10px 20px;
  130. font-size: 0;
  131. background: #eee;
  132. i {
  133. color: #333333;
  134. font-size: 18px;
  135. margin-right: 15px;
  136. vertical-align: middle;
  137. cursor: pointer;
  138. }
  139. }
  140. .send-action {
  141. text-align: right;
  142. }
  143. .look-icon {
  144. background: url("../../assets/icon-face.png") no-repeat;
  145. background-size: 100%;
  146. width: 20px;
  147. height: 20px;
  148. display: inline-block;
  149. vertical-align: middle;
  150. cursor: pointer;
  151. }
  152. .file-icon {
  153. background: url("../../assets/icon-file.png") no-repeat;
  154. background-size: 100%;
  155. width: 19px;
  156. height: 18px;
  157. display: inline-block;
  158. vertical-align: middle;
  159. position: relative;
  160. input[type="file"] {
  161. cursor: pointer;
  162. opacity: 0;
  163. position: absolute;
  164. top: 0;
  165. left: 0;
  166. z-index: 1;
  167. width: 100%;
  168. height: 100%;
  169. }
  170. }
  171. .send-action {
  172. color: #bababa;
  173. font-size: 12px;
  174. button {
  175. margin-left: 10px;
  176. }
  177. }
  178. .input-wrap {
  179. textarea {
  180. display: block;
  181. background-color: #eee;
  182. width: 100%;
  183. box-sizing: border-box;
  184. resize: none;
  185. height: 90px;
  186. line-height: 1.4;
  187. padding-left: 20px;
  188. outline: none;
  189. border: 0;
  190. font-size: 14px;
  191. margin-bottom: 10px;
  192. }
  193. }
  194. .icon-packet{
  195. display: inline-block;
  196. margin-left: 20px;
  197. vertical-align: middle;
  198. background: url('../../assets/icon-packet.png') center center no-repeat;
  199. background-size: 100%;
  200. width: 21px;
  201. height: 21px;
  202. }
  203. .pub-pop-toolbar{
  204. right: auto;
  205. }
  206. </style>