chat_input.vue 2.8 KB

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