submit_1.vue 3.3 KB

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