chatinput.vue 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <template>
  2. <view class="footer">
  3. <view class="footer-left">
  4. <view class="uni-icon uni-icon-mic" @tap="startRecognize"> </view>
  5. </view>
  6. <view class="footer-center">
  7. <input class="input-text" type="text" v-model="inputValue"></input>
  8. </view>
  9. <view class="footer-right" @tap="sendMessge">
  10. <view id='msg-type' >发送</view>
  11. </view>
  12. </view>
  13. </template>
  14. <script>
  15. export default {
  16. name: "chat-input",
  17. data() {
  18. return {
  19. inputValue: ''
  20. }
  21. },
  22. methods: {
  23. startRecognize: function () {
  24. var options = {};
  25. var that = this;
  26. options.engine = 'iFly';
  27. that.inputValue = "";
  28. plus.speech.startRecognize(options, function (s) {
  29. console.log(s);
  30. that.inputValue += s;
  31. }, function (e) {
  32. console.log("语音识别失败:" + e.message);
  33. });
  34. },
  35. sendMessge: function () {
  36. var that = this;
  37. if (that.inputValue.trim() == '') {
  38. that.inputValue = '';
  39. } else {
  40. //点击发送按钮时,通知父组件用户输入的内容
  41. this.$emit('send-message', {
  42. type: 'text',
  43. content: that.inputValue
  44. });
  45. that.inputValue = '';
  46. }
  47. }
  48. }
  49. }
  50. </script>
  51. <style>
  52. .footer {
  53. display: flex;
  54. flex-direction: row;
  55. width: 100%;
  56. height: 80upx;
  57. min-height: 80upx;
  58. border-top: solid 1px #bbb;
  59. overflow: hidden;
  60. padding: 5upx;
  61. background-color: #fafafa;
  62. }
  63. .footer-left {
  64. width: 80upx;
  65. height: 80upx;
  66. display: flex;
  67. justify-content: center;
  68. align-items: center;
  69. }
  70. .footer-right {
  71. width: 120upx;
  72. height: 80upx;
  73. display: flex;
  74. justify-content: center;
  75. align-items: center;
  76. color: #1482D1;
  77. }
  78. .footer-center {
  79. flex: 1;
  80. height: 80upx;
  81. display: flex;
  82. justify-content: center;
  83. align-items: center;
  84. }
  85. .footer-center .input-text {
  86. flex: 1;
  87. background: #fff;
  88. border: solid 1upx #ddd;
  89. padding: 10upx !important;
  90. font-family: verdana !important;
  91. overflow: hidden;
  92. border-radius: 15upx;
  93. }
  94. </style>