123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193 |
- <template>
- <view>
- <view class="submit">
- <view class="submit-chat">
- <!-- 文本框 -->
- <textarea cursor-spacing='20' class="chat-send btn" :show-confirm-bar="false"
- disable-default-padding="true" auto-height="true" @focus="focus" v-model="msg"></textarea>
- <view class="bt-img" @tap="more">
- <text class="iconfont icon-gengduoneirong"></text>
- </view>
- <view class="bt-img" v-if="msg">
- <button class="button" @tap="inputs" type="primary" size="mini">发送</button>
- </view>
- </view>
- <!-- 更多 -->
- <view class="more" :class="{displaynone:!ismore}">
- <view class="more_1">
- <view class="more-list" @tap="sendImg('album')">
- <text class="iconfont icon-tupian"></text>
- <view class="more-list-title">图片</view>
- </view>
- <view class="more-list">
- <text class="iconfont icon-zaixiankefu"></text>
- <button :plain="true" class="button" size="mini" type="default" open-type="contact">人工</button>
- </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() {
- if (this.msg.length > 0) {
- // 0为表情和文字
- let msg = this.msg.replace(/[\r\n]/g, "");
- this.send(msg, '0')
- }
- },
- // 输入框聚焦
- focus() {
- //关闭其他项
- this.ismore = false;
- setTimeout(() => {
- this.getElementHeight()
- }, 10)
- },
- //更多功能
- more() {
- this.ismore = !this.ismore;
- setTimeout(() => {
- this.getElementHeight();
- }, 10)
- },
- //图片发送
- sendImg(e) {
- const that = this;
- let serverUrl = that.$config.serverFile;
- that.$emit('choseImg', true);
- uni.chooseImage({
- count: 1,
- sizeType: ['original', 'compressed'],
- sourceType: ['album', 'camera'],
- success: async function(res) {
- that.$emit('choseImg', true);
- let tempFile = JSON.parse(JSON.stringify(res.tempFilePaths));
- const arr = await that.$apifile(`/travel/applet/upload`, 'file', tempFile[0], 'file');
- if (arr.errcode == '0') {
- let filePaths = serverUrl + arr.uri
- that.send(filePaths, '1')
- } else {
- that.$emit('choseImg', false);
- uni.showToast({
- title: arr.errmsg,
- icon: 'none'
- })
- }
- }
- });
- },
- //发送
- send(msg, type) {
- let data = {
- message: msg,
- type: type
- }
- this.$emit('inputs', data);
- setTimeout(() => {
- this.msg = '';
- }, 0)
- }
- }
- };
- </script>
- <style lang="scss" scoped>
- .displaynone {
- display: none;
- }
- .submit-chat {
- width: 100%;
- display: flex;
- align-items: center;
- box-sizing: border-box;
- padding: 14rpx 14rpx;
- .bt-img {
- margin: 0 0 0 10rpx;
- .iconfont {
- font-size: 65rpx;
- }
- .button {
- background-color: var(--f3CColor);
- color: var(--mainColor);
- font-size: var(--font14Size);
- }
- }
- .btn {
- flex: auto;
- background-color: #fff;
- border-radius: 10rpx;
- padding: 20rpx;
- max-height: 160rpx;
- margin: 0 10rpx;
- }
- .chat-send {
- line-height: 44rpx;
- width: 300rpx;
- }
- }
- .more {
- width: 100%;
- height: 450rpx;
- background: #ecedee;
- box-shadow: 0px 11rpx 0px 0px rgba(0, 0, 0, 0.1);
- bottom: env(safe-area-inset-bottom);
- padding: 8rpx;
- box-sizing: border-box;
- .more_1 {
- display: flex;
- flex-wrap: wrap;
- .more-list {
- width: 18%;
- text-align: center;
- margin: 10rpx;
- padding: 20rpx 15rpx 15rpx 15rpx;
- 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;
- }
- .button {
- border: none !important;
- color: rgba(39, 40, 50, 0.5);
- }
- }
- }
- }
- </style>
|