123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161 |
- <template>
- <view>
- <view class="submit">
- <view class="submit-chat">
- <!-- 文本框 -->
- <textarea auto-height="true" class="chat-send btn" @confirm="inputs" @focus="focus"
- v-model="msg"></textarea>
- <view class="bt-img" @tap="more">
- <text class="iconfont icon-gengduoneirong"></text>
- </view>
- </view>
- <!-- 更多 -->
- <view class="more" :class="{displaynone:!ismore}">
- <view class="more-list" @tap="sendImg('album')">
- <text class="iconfont icon-tupian"></text>
- <view class="more-list-title">图片</view>
- </view>
- </view>
- </view>
- </view>
- </template>
- <script>
- export default {
- data() {
- return {
- ismore: false,
- msg: "",
- };
- },
- methods: {
- //获取高度方法
- getElementHeight() {
- const query = uni.createSelectorQuery().in(this);
- query.select('.submit').boundingClientRect(data => {
- this.$emit('heights', data.height);
- }).exec();
- },
- //文字发送
- inputs(e) {
- var chatm = e.detail.value;
- if (chatm.length > 1) {
- // 0为表情和文字
- this.send(this.msg, 0)
- }
- },
- // 输入框聚焦
- focus() {
- //关闭其他项
- this.ismore = false;
- setTimeout(() => {
- this.getElementHeight()
- }, 10)
- },
- //更多功能
- more() {
- this.ismore = !this.ismore;
- setTimeout(() => {
- this.getElementHeight();
- }, 10)
- },
- //图片发送
- sendImg(e) {
- uni.chooseImage({
- count: 9, //默认9
- sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图,默认二者都有
- sourceType: [e], //从相册选择
- // success: function (res) { //用function的方式会找不到send方法
- success: (res) => {
- const filePaths = res.tempFilePaths;
- for (let i = 0; i < filePaths.length; i++) {
- this.send(filePaths[i], 1)
- }
- }
- });
- },
- //发送
- send(msg, type) {
- let date = {
- message: msg,
- type: type
- }
- this.$emit('inputs', date);
- setTimeout(() => {
- this.msg = '';
- }, 0)
- }
- }
- };
- </script>
- <style lang="scss" scoped>
- .submit {
- background: rgba(244, 244, 244, 0.96);
- border-top: 1px solid rgba(39, 40, 50, 0.1);
- width: 100%;
- position: fixed;
- bottom: 0;
- z-index: 100;
- padding-bottom: env(safe-area-inset-bottom);
- }
- .displaynone {
- display: none;
- }
- .submit-chat {
- width: 100%;
- display: flex;
- align-items: center;
- box-sizing: border-box;
- padding: 14rpx 14rpx;
- .bt-img {
- .iconfont {
- font-size: 65rpx;
- }
- }
- .btn {
- background-color: #fff;
- border-radius: 10rpx;
- padding: 20rpx;
- margin: 0 10rpx;
- }
- .chat-send {
- line-height: 44rpx;
- }
- }
- .more {
- width: 100%;
- height: 436rpx;
- background: rgba(236, 237, 238, 1);
- box-shadow: 0px 11rpx 0px 0px rgba(0, 0, 0, 0.1);
- bottom: env(safe-area-inset-bottom);
- padding: 8rpx 20rpx;
- box-sizing: border-box;
- .more-list {
- width: 25%;
- text-align: center;
- float: left;
- padding-top: 32rpx;
- background-color: #ffffff;
- border-radius: 20rpx;
- .iconfont {
- font-size: 65rpx;
- }
- .more-list-title {
- margin: 10rpx 0;
- font-size: 30rpx;
- color: rgba(39, 40, 50, 0.5);
- line-height: 34rpx;
- }
- }
- }
- </style>
|