chatinput.vue 5.0 KB

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