submit_1.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. <template>
  2. <view>
  3. <view class="submit">
  4. <view class="submit-chat">
  5. <!-- 文本框 -->
  6. <textarea cursor-spacing='20' class="chat-send btn" :show-confirm-bar="false"
  7. disable-default-padding="true" auto-height="true" @input="inputs" @focus="focus"
  8. v-model="msg"></textarea>
  9. <view class="bt-img" @tap="more">
  10. <text class="iconfont icon-gengduoneirong"></text>
  11. </view>
  12. </view>
  13. <!-- 更多 -->
  14. <view class="more" :class="{displaynone:!ismore}">
  15. <view class="more-list" @tap="sendImg('album')">
  16. <text class="iconfont icon-tupian"></text>
  17. <view class="more-list-title">图片</view>
  18. </view>
  19. </view>
  20. </view>
  21. </view>
  22. </template>
  23. <script>
  24. export default {
  25. data() {
  26. return {
  27. ismore: false,
  28. msg: "",
  29. };
  30. },
  31. methods: {
  32. //获取高度方法
  33. getElementHeight() {
  34. const query = uni.createSelectorQuery().in(this);
  35. query.select('.submit').boundingClientRect(data => {
  36. this.$emit('heights', data.height);
  37. }).exec();
  38. },
  39. //文字发送
  40. inputs(e) {
  41. var chat = e.detail.value;
  42. var pos = chat.indexOf('\n');
  43. if (pos != -1 && chat.length > 1) {
  44. // 0为表情和文字
  45. let msg = this.msg.replace(/[\r\n]/g, "");
  46. this.send(msg, '0')
  47. }
  48. },
  49. // 输入框聚焦
  50. focus() {
  51. //关闭其他项
  52. this.ismore = false;
  53. setTimeout(() => {
  54. this.getElementHeight()
  55. }, 10)
  56. },
  57. //更多功能
  58. more() {
  59. this.ismore = !this.ismore;
  60. setTimeout(() => {
  61. this.getElementHeight();
  62. }, 10)
  63. },
  64. //图片发送
  65. sendImg(e) {
  66. const that = this;
  67. let serverUrl = that.$config.serverUrl;
  68. uni.chooseImage({
  69. count: 1,
  70. sizeType: ['original', 'compressed'],
  71. sourceType: ['album', 'camera'],
  72. success: async function(res) {
  73. let tempFile = JSON.parse(JSON.stringify(res.tempFilePaths));
  74. const arr = await that.$apifile(`/point/upload`, 'file', tempFile[0], 'file');
  75. if (arr.errcode == '0') {
  76. let filePaths = serverUrl + arr.uri
  77. that.send(filePaths, '1')
  78. } else {
  79. uni.showToast({
  80. title: arr.errmsg,
  81. icon: 'none'
  82. })
  83. }
  84. }
  85. });
  86. },
  87. //发送
  88. send(msg, type) {
  89. let data = {
  90. message: msg,
  91. type: type
  92. }
  93. this.$emit('inputs', data);
  94. setTimeout(() => {
  95. this.msg = '';
  96. }, 0)
  97. }
  98. }
  99. };
  100. </script>
  101. <style lang="scss" scoped>
  102. .displaynone {
  103. display: none;
  104. }
  105. .submit-chat {
  106. width: 100%;
  107. display: flex;
  108. align-items: center;
  109. box-sizing: border-box;
  110. padding: 14rpx 14rpx;
  111. .bt-img {
  112. .iconfont {
  113. font-size: 65rpx;
  114. }
  115. }
  116. .btn {
  117. flex: auto;
  118. background-color: #fff;
  119. border-radius: 10rpx;
  120. padding: 20rpx;
  121. max-height: 160rpx;
  122. margin: 0 10rpx;
  123. }
  124. .chat-send {
  125. line-height: 44rpx;
  126. }
  127. }
  128. .more {
  129. width: 100%;
  130. height: 450rpx;
  131. background: rgba(236, 237, 238, 1);
  132. box-shadow: 0px 11rpx 0px 0px rgba(0, 0, 0, 0.1);
  133. bottom: env(safe-area-inset-bottom);
  134. padding: 8rpx 20rpx;
  135. box-sizing: border-box;
  136. .more-list {
  137. width: 25%;
  138. text-align: center;
  139. float: left;
  140. padding-top: 32rpx;
  141. background-color: #ffffff;
  142. border-radius: 20rpx;
  143. .iconfont {
  144. font-size: 65rpx;
  145. }
  146. .more-list-title {
  147. margin: 10rpx 0;
  148. font-size: 30rpx;
  149. color: rgba(39, 40, 50, 0.5);
  150. line-height: 34rpx;
  151. }
  152. }
  153. }
  154. </style>