inputArea.vue 4.5 KB

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