submit_1.vue 3.2 KB

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