chatinput.vue 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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" @confirm="sendMessge" v-model="inputValue" :focus="focus" @blur="blur" :placeholder="placeholder"></input>
  8. </view>
  9. <view class="footer-right">
  10. <view id='msg-type' class="send-comment" @tap="sendMessge">发送</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. props:{
  23. placeholder: {
  24. type: String,
  25. required: true
  26. },
  27. focus: {
  28. type:Boolean,
  29. required: true
  30. }
  31. },
  32. methods: {
  33. blur: function() {//失焦触发通知父组件
  34. var that = this;
  35. this.$emit('blur')
  36. },
  37. startRecognize: function () {
  38. var options = {};
  39. var that = this;
  40. options.engine = 'iFly';
  41. that.inputValue = "";
  42. plus.speech.startRecognize(options, function (s) {
  43. console.log(s);
  44. that.inputValue += s;
  45. }, function (e) {
  46. console.log("语音识别失败:" + e.message);
  47. });
  48. },
  49. sendMessge: function () {
  50. if (!this.inputValue) {
  51. uni.showModal({
  52. content:"还没有输入内容哦!",
  53. showCancel:false
  54. })
  55. return;
  56. }
  57. var that = this;
  58. //点击发送按钮时,通知父组件用户输入的内容
  59. this.$emit('send-message', {
  60. type: 'text',
  61. content: that.inputValue
  62. });
  63. that.inputValue = '';//清空上次输入的内容
  64. }
  65. }
  66. }
  67. </script>
  68. <style>
  69. .footer {
  70. display: flex;
  71. flex-direction: row;
  72. width: 100%;
  73. height: 80upx;
  74. min-height: 80upx;
  75. border-top: solid 1px #bbb;
  76. overflow: hidden;
  77. padding: 5upx;
  78. background-color: #F4F5F6;
  79. }
  80. .footer-left {
  81. width: 80upx;
  82. height: 80upx;
  83. display: flex;
  84. justify-content: center;
  85. align-items: center;
  86. }
  87. .footer-right {
  88. width: 120upx;
  89. height: 80upx;
  90. display: flex;
  91. justify-content: center;
  92. align-items: center;
  93. color: #1482D1;
  94. }
  95. .footer-center {
  96. flex: 1;
  97. padding-left: 20upx;
  98. height: 80upx;
  99. display: flex;
  100. justify-content: center;
  101. align-items: center;
  102. }
  103. .footer-center .input-text {
  104. flex: 1;
  105. background: #fff;
  106. /* border: solid 1upx #ddd; */
  107. padding: 10upx !important;
  108. font-family: verdana !important;
  109. overflow: hidden;
  110. border-radius: 15upx;
  111. }
  112. .footer-right .send-comment{
  113. background-color: #007AFF;
  114. text-align: center;
  115. line-height: 60upx;
  116. color: #FFFFFF;
  117. width: 80upx;
  118. height: 60upx;
  119. border-radius: 5px;
  120. font-size: 10px;
  121. /* height: 60upx; */
  122. }
  123. </style>