chatinput.vue 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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. @import "../common/icon.css";
  53. .footer {
  54. display: flex;
  55. flex-direction: row;
  56. width: 100%;
  57. height: 80px;
  58. min-height: 80px;
  59. border-top: solid 1px #bbb;
  60. overflow: hidden;
  61. padding: 5px;
  62. background-color: #fafafa;
  63. }
  64. .footer-left {
  65. width: 40px;
  66. height: 80px;
  67. display: flex;
  68. justify-content: center;
  69. align-items: center;
  70. }
  71. .footer-right {
  72. width: 120px;
  73. height: 80px;
  74. display: flex;
  75. justify-content: center;
  76. align-items: center;
  77. color: #1482D1;
  78. }
  79. .footer-center {
  80. flex: 1;
  81. height: 80px;
  82. display: flex;
  83. justify-content: center;
  84. align-items: center;
  85. }
  86. .footer-center .input-text {
  87. flex: 1;
  88. background: #fff;
  89. border: solid 1px #ddd;
  90. padding: 10px !important;
  91. font-family: verdana !important;
  92. overflow: hidden;
  93. border-radius: 15px;
  94. height: 38px;
  95. }
  96. </style>