submit_1.vue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. <template>
  2. <view>
  3. <view class="submit">
  4. <view class="submit-chat">
  5. <!-- 文本框 -->
  6. <textarea auto-height="true" class="chat-send btn" @confirm="inputs" @focus="focus"
  7. v-model="msg"></textarea>
  8. <view class="bt-img" @tap="more">
  9. <text class="iconfont icon-gengduoneirong"></text>
  10. </view>
  11. </view>
  12. <!-- 更多 -->
  13. <view class="more" :class="{displaynone:!ismore}">
  14. <view class="more-list" @tap="sendImg('album')">
  15. <text class="iconfont icon-tupian"></text>
  16. <view class="more-list-title">图片</view>
  17. </view>
  18. </view>
  19. </view>
  20. </view>
  21. </template>
  22. <script>
  23. export default {
  24. data() {
  25. return {
  26. ismore: false,
  27. msg: "",
  28. };
  29. },
  30. methods: {
  31. //获取高度方法
  32. getElementHeight() {
  33. const query = uni.createSelectorQuery().in(this);
  34. query.select('.submit').boundingClientRect(data => {
  35. this.$emit('heights', data.height);
  36. }).exec();
  37. },
  38. //文字发送
  39. inputs(e) {
  40. var chatm = e.detail.value;
  41. if (chatm.length > 1) {
  42. // 0为表情和文字
  43. this.send(this.msg, 0)
  44. }
  45. },
  46. // 输入框聚焦
  47. focus() {
  48. //关闭其他项
  49. this.ismore = false;
  50. setTimeout(() => {
  51. this.getElementHeight()
  52. }, 10)
  53. },
  54. //更多功能
  55. more() {
  56. this.ismore = !this.ismore;
  57. setTimeout(() => {
  58. this.getElementHeight();
  59. }, 10)
  60. },
  61. //图片发送
  62. sendImg(e) {
  63. uni.chooseImage({
  64. count: 9, //默认9
  65. sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图,默认二者都有
  66. sourceType: [e], //从相册选择
  67. // success: function (res) { //用function的方式会找不到send方法
  68. success: (res) => {
  69. const filePaths = res.tempFilePaths;
  70. for (let i = 0; i < filePaths.length; i++) {
  71. this.send(filePaths[i], 1)
  72. }
  73. }
  74. });
  75. },
  76. //发送
  77. send(msg, type) {
  78. let date = {
  79. message: msg,
  80. type: type
  81. }
  82. this.$emit('inputs', date);
  83. setTimeout(() => {
  84. this.msg = '';
  85. }, 0)
  86. }
  87. }
  88. };
  89. </script>
  90. <style lang="scss" scoped>
  91. .submit {
  92. background: rgba(244, 244, 244, 0.96);
  93. border-top: 1px solid rgba(39, 40, 50, 0.1);
  94. width: 100%;
  95. position: fixed;
  96. bottom: 0;
  97. z-index: 100;
  98. padding-bottom: env(safe-area-inset-bottom);
  99. }
  100. .displaynone {
  101. display: none;
  102. }
  103. .submit-chat {
  104. width: 100%;
  105. display: flex;
  106. align-items: center;
  107. box-sizing: border-box;
  108. padding: 14rpx 14rpx;
  109. .bt-img {
  110. .iconfont {
  111. font-size: 65rpx;
  112. }
  113. }
  114. .btn {
  115. background-color: #fff;
  116. border-radius: 10rpx;
  117. padding: 20rpx;
  118. margin: 0 10rpx;
  119. }
  120. .chat-send {
  121. line-height: 44rpx;
  122. }
  123. }
  124. .more {
  125. width: 100%;
  126. height: 436rpx;
  127. background: rgba(236, 237, 238, 1);
  128. box-shadow: 0px 11rpx 0px 0px rgba(0, 0, 0, 0.1);
  129. bottom: env(safe-area-inset-bottom);
  130. padding: 8rpx 20rpx;
  131. box-sizing: border-box;
  132. .more-list {
  133. width: 25%;
  134. text-align: center;
  135. float: left;
  136. padding-top: 32rpx;
  137. background-color: #ffffff;
  138. border-radius: 20rpx;
  139. .iconfont {
  140. font-size: 65rpx;
  141. }
  142. .more-list-title {
  143. margin: 10rpx 0;
  144. font-size: 30rpx;
  145. color: rgba(39, 40, 50, 0.5);
  146. line-height: 34rpx;
  147. }
  148. }
  149. }
  150. </style>