submit_1.vue 3.1 KB

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