submit_1.vue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. <template>
  2. <view>
  3. <view class="submit">
  4. <view class="submit-chat">
  5. <!-- 文本框 -->
  6. <textarea auto-height="true" fixed="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. const that = this;
  64. let serverUrl = that.$config.serverUrl;
  65. uni.chooseImage({
  66. count: 1,
  67. sizeType: ['original', 'compressed'],
  68. sourceType: ['album', 'camera'],
  69. success: async function(res) {
  70. let tempFile = JSON.parse(JSON.stringify(res.tempFilePaths));
  71. const arr = await that.$apifile(`/point/upload`, 'file', tempFile[0], 'file');
  72. if (arr.errcode == '0') {
  73. let filePaths = {
  74. name: arr.name,
  75. uri: arr.uri,
  76. url: serverUrl + arr.uri
  77. }
  78. that.send([filePaths], 1)
  79. } else {
  80. uni.showToast({
  81. title: arr.errmsg,
  82. icon: 'none'
  83. })
  84. }
  85. }
  86. });
  87. },
  88. //发送
  89. send(msg, type) {
  90. let date = {
  91. message: msg,
  92. type: type
  93. }
  94. this.$emit('inputs', date);
  95. setTimeout(() => {
  96. this.msg = '';
  97. }, 0)
  98. }
  99. }
  100. };
  101. </script>
  102. <style lang="scss" scoped>
  103. .displaynone {
  104. display: none;
  105. }
  106. .submit-chat {
  107. width: 100%;
  108. display: flex;
  109. align-items: center;
  110. box-sizing: border-box;
  111. padding: 14rpx 14rpx;
  112. .bt-img {
  113. .iconfont {
  114. font-size: 65rpx;
  115. }
  116. }
  117. .btn {
  118. background-color: #fff;
  119. border-radius: 10rpx;
  120. padding: 20rpx;
  121. margin: 0 10rpx;
  122. }
  123. .chat-send {
  124. line-height: 44rpx;
  125. }
  126. }
  127. .more {
  128. width: 100%;
  129. height: 436rpx;
  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>