inputArea.vue 4.9 KB

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