chatinput.vue 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. <template>
  2. <view class="footheight">
  3. <view class="footer">
  4. <view class="footer-left">
  5. <view class="uni-icon uni-icon-mic" @tap="startRecognize"> </view>
  6. </view>
  7. <view class="footer-center">
  8. <input class="input-text" type="text" v-model="inputValue" @focus="foc" :focus="focus"></input>
  9. </view>
  10. <view class="footer-emotion" @tap="show">
  11. <i class="icon iconfont icon-face"></i>
  12. </view>
  13. <view class="footer-right" @tap="sendMessge">
  14. <view id='msg-type'>发送</view>
  15. </view>
  16. </view>
  17. <emotion @emotion="handleEmotion" :height="200" v-if="showPannel"></emotion>
  18. </view>
  19. </template>
  20. <script>
  21. import Emotion from './Emotion/index.vue'
  22. export default {
  23. name: "chat-input",
  24. components: {
  25. Emotion
  26. },
  27. data() {
  28. return {
  29. inputValue: '',
  30. showPannel: false,
  31. focus: false
  32. }
  33. },
  34. methods: {
  35. startRecognize: function() {
  36. var options = {};
  37. var that = this;
  38. options.engine = 'iFly';
  39. that.inputValue = "";
  40. plus.speech.startRecognize(options, function(s) {
  41. console.log(s);
  42. that.inputValue += s;
  43. }, function(e) {
  44. console.log("语音识别失败:" + e.message);
  45. });
  46. },
  47. sendMessge: function() {
  48. var that = this;
  49. if (that.inputValue.trim() == '') {
  50. that.inputValue = '';
  51. } else {
  52. //点击发送按钮时,通知父组件用户输入的内容
  53. this.$emit('send-message', {
  54. type: 'text',
  55. content: that.inputValue
  56. });
  57. that.inputValue = '';
  58. this.showPannel = false
  59. }
  60. },
  61. // 展示表情
  62. show() {
  63. this.showPannel = !this.showPannel;
  64. this.$emit('show')
  65. },
  66. // 光标触发隐藏表情
  67. foc() {
  68. this.showPannel = false
  69. this.$emit('foc')
  70. },
  71. emotion(res) {
  72. let word = res.replace(/\#|\;/gi, '')
  73. const list = ['微笑', '撇嘴', '色', '发呆', '得意', '流泪', '害羞', '闭嘴', '睡', '大哭', '尴尬', '发怒', '调皮', '呲牙', '惊讶', '难过', '酷',
  74. '冷汗', '抓狂', '吐', '偷笑', '可爱', '白眼', '傲慢', '饥饿', '困', '惊恐', '流汗', '憨笑', '大兵', '奋斗', '咒骂', '疑问', '嘘', '晕', '折磨', '衰',
  75. '骷髅', '敲打', '再见', '擦汗', '抠鼻', '鼓掌', '糗大了', '坏笑', '左哼哼', '右哼哼', '哈欠', '鄙视', '委屈', '快哭了', '阴险', '亲亲', '吓', '可怜',
  76. '菜刀', '西瓜', '啤酒', '篮球', '乒乓', '咖啡', '饭', '猪头', '玫瑰', '凋谢', '示爱', '爱心', '心碎', '蛋糕', '闪电', '炸弹', '刀', '足球', '瓢虫',
  77. '便便', '月亮', '太阳', '礼物', '拥抱', '强', '弱', '握手', '胜利', '抱拳', '勾引', '拳头', '差劲', '爱你', 'NO', 'OK', '爱情', '飞吻', '跳跳',
  78. '发抖', '怄火', '转圈', '磕头', '回头', '跳绳', '挥手', '激动', '街舞', '献吻', '左太极', '右太极'
  79. ]
  80. let index = list.indexOf(word)
  81. return `<img src="https://res.wx.qq.com/mpres/htmledition/images/icon/emotion/${index}.gif" align="middle">`
  82. },
  83. handleEmotion(i) {
  84. this.inputValue += i
  85. },
  86. }
  87. }
  88. </script>
  89. <style>
  90. .footer {
  91. display: flex;
  92. flex-direction: row;
  93. width: 100%;
  94. height: 80upx;
  95. min-height: 80upx;
  96. border-top: solid 1px #bbb;
  97. overflow: hidden;
  98. padding: 5upx;
  99. background-color: #fafafa;
  100. }
  101. .footer-left {
  102. width: 80upx;
  103. height: 80upx;
  104. display: flex;
  105. justify-content: center;
  106. align-items: center;
  107. }
  108. .footer-right {
  109. width: 100upx;
  110. height: 80upx;
  111. display: flex;
  112. justify-content: center;
  113. align-items: center;
  114. color: #1482D1;
  115. }
  116. .footer-emotion {
  117. width: 60upx;
  118. height: 80upx;
  119. display: flex;
  120. justify-content: flex-end;
  121. align-items: center;
  122. color: #1482D1;
  123. }
  124. .footer-center {
  125. flex: 1;
  126. height: 80upx;
  127. display: flex;
  128. justify-content: center;
  129. align-items: center;
  130. }
  131. .footer-center .input-text {
  132. flex: 1;
  133. background: #fff;
  134. border: solid 1upx #ddd;
  135. padding: 10upx !important;
  136. font-family: verdana !important;
  137. overflow: hidden;
  138. border-radius: 15upx;
  139. }
  140. @font-face {
  141. font-family: 'iconfont';
  142. /* project id 1134039 */
  143. src: url('http://at.alicdn.com/t/font_1134039_uait6xu86bf.eot');
  144. src: url('http://at.alicdn.com/t/font_1134039_uait6xu86bf.eot?#iefix') format('embedded-opentype'),
  145. url('http://at.alicdn.com/t/font_1134039_uait6xu86bf.woff2') format('woff2'),
  146. url('http://at.alicdn.com/t/font_1134039_uait6xu86bf.woff') format('woff'),
  147. url('http://at.alicdn.com/t/font_1134039_uait6xu86bf.ttf') format('truetype'),
  148. url('http://at.alicdn.com/t/font_1134039_uait6xu86bf.svg#iconfont') format('svg');
  149. }
  150. .iconfont {
  151. font-family: "iconfont" !important;
  152. font-size: 18px;
  153. font-style: normal;
  154. -webkit-font-smoothing: antialiased;
  155. -moz-osx-font-smoothing: grayscale;
  156. }
  157. .icon-face:before {
  158. content: "\e71c";
  159. font-size: 50upx;
  160. }
  161. </style>