submit_1.vue 4.2 KB

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