|
|
@@ -0,0 +1,348 @@
|
|
|
+<config>
|
|
|
+{
|
|
|
+ "navigationBarTitleText":'',
|
|
|
+ "backgroundColor":"#F5F7FA"
|
|
|
+}
|
|
|
+</config>
|
|
|
+<template>
|
|
|
+ <div class="page">
|
|
|
+ <div
|
|
|
+ id="chat-list"
|
|
|
+ class="chat-list"
|
|
|
+ @click="showAttach = ''"
|
|
|
+ :style="{ paddingBottom: `calc(${100 + attachHeight}px + env(safe-area-inset-bottom))` }"
|
|
|
+ >
|
|
|
+ <chat-info
|
|
|
+ v-for="(item, index) in list"
|
|
|
+ :key="index"
|
|
|
+ :info="item"
|
|
|
+ :isMine="userInfo && item.sendId === userInfo.id"
|
|
|
+ :contentType="item.messageType"
|
|
|
+ ></chat-info>
|
|
|
+
|
|
|
+ <div class="loading" v-if="loading">
|
|
|
+ <van-loading size="24px">加载中...</van-loading>
|
|
|
+ </div>
|
|
|
+ <!-- <chat-info isMine></chat-info>
|
|
|
+ <chat-info isMine contentType="image"></chat-info> -->
|
|
|
+ </div>
|
|
|
+
|
|
|
+ <div class="bottom-box">
|
|
|
+ <div class="input-box">
|
|
|
+ <van-field
|
|
|
+ :boder="false"
|
|
|
+ placeholder="请输入需要咨询的问题"
|
|
|
+ :value="message"
|
|
|
+ @blur="message = $event.detail.value"
|
|
|
+ @input="message = $event.detail"
|
|
|
+ @confirm="confirm"
|
|
|
+ clearable
|
|
|
+ />
|
|
|
+
|
|
|
+ <img @click="showAttach = showAttach !== 'emoji' ? 'emoji' : ''" alt="" class="icon" />
|
|
|
+ <van-button type="primary" size="small" @click="confirm('')" v-if="message"> 发送</van-button>
|
|
|
+ <img @click="showAttach = showAttach != 'img' ? 'img' : ''" alt="" class="icon" v-else />
|
|
|
+ </div>
|
|
|
+ <div class="attach-box" :style="{ height: `${attachHeight}px` }">
|
|
|
+ <div class="up-btn" @click="sendImg" v-if="showAttach === 'img'">
|
|
|
+ <!-- <img src="/native/svgs/icon_zhaopian.svg" alt="" /> -->
|
|
|
+ </div>
|
|
|
+
|
|
|
+ <div class="emojiList" v-else>
|
|
|
+ <div class="emoji-item" @click="addEmoji(item)" v-for="(item, index) in connectemoji" :key="index">
|
|
|
+ {{ item }}
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+</template>
|
|
|
+
|
|
|
+<script>
|
|
|
+import ChatInfo from '@/components/ChatInfo';
|
|
|
+import { mapState } from 'vuex';
|
|
|
+import dayjs from 'dayjs';
|
|
|
+import * as calendar from 'dayjs/plugin/calendar';
|
|
|
+import 'dayjs/locale/zh-cn';
|
|
|
+dayjs.locale('zh-cn');
|
|
|
+dayjs.extend(calendar);
|
|
|
+export default {
|
|
|
+ name: 'Chat',
|
|
|
+ components: {
|
|
|
+ ChatInfo
|
|
|
+ },
|
|
|
+ data() {
|
|
|
+ return {
|
|
|
+ message: '',
|
|
|
+ showAttach: '',
|
|
|
+ topicInfo: null,
|
|
|
+ list: [],
|
|
|
+ toUserId: 0,
|
|
|
+ loading: true,
|
|
|
+ timeFormat: {
|
|
|
+ sameDay: 'A hh:mm', // The same day ( Today at 2:30 AM )
|
|
|
+ nextDay: '[明天]', // The next day ( Tomorrow at 2:30 AM )
|
|
|
+ nextWeek: 'dddd', // The next week ( Sunday at 2:30 AM )
|
|
|
+ lastDay: 'MM/DD HH:mm', // The day before ( Yesterday at 2:30 AM )
|
|
|
+ lastWeek: 'MM/DD HH:mm', // Last week ( Last Monday at 2:30 AM )
|
|
|
+ sameElse: 'YYYY/MM/DD' // Everything else ( 7/10/2011 )
|
|
|
+ },
|
|
|
+ connectemoji: [
|
|
|
+ '😊',
|
|
|
+ '😅',
|
|
|
+ '😲',
|
|
|
+ '😭',
|
|
|
+ '😂',
|
|
|
+ '😄',
|
|
|
+ '😩',
|
|
|
+ '😞',
|
|
|
+ '😵',
|
|
|
+ '😒',
|
|
|
+ '😍',
|
|
|
+ '😤',
|
|
|
+ '😜',
|
|
|
+ '😝',
|
|
|
+ '😋',
|
|
|
+ '😘',
|
|
|
+ '😚',
|
|
|
+ '😷',
|
|
|
+ '😳',
|
|
|
+ '😃',
|
|
|
+ '😆',
|
|
|
+ '😁',
|
|
|
+ '😢',
|
|
|
+ '😨',
|
|
|
+ '😠',
|
|
|
+ '😣',
|
|
|
+ '😌',
|
|
|
+ '😖',
|
|
|
+ '😔',
|
|
|
+ '😰',
|
|
|
+ '😱',
|
|
|
+ '😪',
|
|
|
+ '😏',
|
|
|
+ '😓'
|
|
|
+ ]
|
|
|
+ };
|
|
|
+ },
|
|
|
+ computed: {
|
|
|
+ ...mapState(['userInfo', 'systemInfo']),
|
|
|
+ attachHeight() {
|
|
|
+ return this.showAttach ? 200 : 0;
|
|
|
+ }
|
|
|
+ },
|
|
|
+ onLoad(options) {
|
|
|
+ // if (options.toName) {
|
|
|
+ // wx.setNavigationBarTitle({
|
|
|
+ // title: options.toName
|
|
|
+ // });
|
|
|
+ // }
|
|
|
+ // if (options.toUserId) {
|
|
|
+ // this.toUserId = options.toUserId;
|
|
|
+ // }
|
|
|
+ },
|
|
|
+ methods: {
|
|
|
+ // loginMethods() {
|
|
|
+ // let eventChannel = this.$mp.page.getOpenerEventChannel();
|
|
|
+ // this.$http
|
|
|
+ // .post('/topic/newTopic', {
|
|
|
+ // targetId: this.$mp.options.toUserId
|
|
|
+ // })
|
|
|
+ // .then(res => {
|
|
|
+ // this.topicInfo = res;
|
|
|
+ // return this.getList();
|
|
|
+ // })
|
|
|
+ // .then(() => {
|
|
|
+ // if (eventChannel && eventChannel.on) {
|
|
|
+ // eventChannel.on('productInfo', data => {
|
|
|
+ // this.newMessage(JSON.stringify(data), true, 'LINK');
|
|
|
+ // setTimeout(() => {
|
|
|
+ // this.newMessage('欢迎光临本店,小店客服会尽快为您提供服务。', false, 'TEXT', false);
|
|
|
+ // }, 1000);
|
|
|
+ // });
|
|
|
+ // }
|
|
|
+ // });
|
|
|
+ // },
|
|
|
+ // sendImg() {
|
|
|
+ // this.choosePhoto().then(res => {
|
|
|
+ // console.log(res);
|
|
|
+ // this.newMessage(res, true, 'IMAGE');
|
|
|
+ // });
|
|
|
+ // },
|
|
|
+ // getList() {
|
|
|
+ // this.loading = true;
|
|
|
+ // return this.$http
|
|
|
+ // .get('/message/findTopicMessages', {
|
|
|
+ // topicId: this.topicInfo.id
|
|
|
+ // })
|
|
|
+ // .then(res => {
|
|
|
+ // console.log(res);
|
|
|
+ // this.loading = false;
|
|
|
+ // this.list = res.map((item, index) => {
|
|
|
+ // let time = '';
|
|
|
+ // if (index == 0) {
|
|
|
+ // time = dayjs(item.createdAt).calendar(null, this.timeFormat);
|
|
|
+ // } else {
|
|
|
+ // const date1 = dayjs(item.createdAt);
|
|
|
+ // if (date1.diff(res[index - 1].createdAt, 'minute') > 5) {
|
|
|
+ // time = dayjs(item.createdAt).calendar(null, this.timeFormat);
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // return {
|
|
|
+ // ...item,
|
|
|
+ // time: time
|
|
|
+ // };
|
|
|
+ // });
|
|
|
+ // this.$nextTick(() => {
|
|
|
+ // setTimeout(() => {
|
|
|
+ // wx.createSelectorQuery()
|
|
|
+ // .select('#chat-list')
|
|
|
+ // .boundingClientRect(rect => {
|
|
|
+ // wx.pageScrollTo({
|
|
|
+ // scrollTop: rect.height + 100
|
|
|
+ // });
|
|
|
+ // })
|
|
|
+ // .exec();
|
|
|
+ // }, 100);
|
|
|
+ // });
|
|
|
+ // this.$http.post('/message/allRead', {
|
|
|
+ // topicId: this.topicInfo.id
|
|
|
+ // });
|
|
|
+ // return Promise.resolve();
|
|
|
+ // });
|
|
|
+ // },
|
|
|
+ // confirm(e) {
|
|
|
+ // this.$nextTick(() => {
|
|
|
+ // this.newMessage(e ? e.detail : this.message);
|
|
|
+ // this.message = '';
|
|
|
+ // });
|
|
|
+ // },
|
|
|
+ // newMessage(info, isSend = true, messageType = 'TEXT', beenRead = false) {
|
|
|
+ // let data = {
|
|
|
+ // topicId: this.topicInfo.id,
|
|
|
+ // info: info,
|
|
|
+ // messageType: messageType,
|
|
|
+ // beenRead: beenRead
|
|
|
+ // };
|
|
|
+ // if (isSend) {
|
|
|
+ // data.sendId = this.$store.state.userInfo.id;
|
|
|
+ // data.resId = this.toUserId;
|
|
|
+ // } else {
|
|
|
+ // data.sendId = this.toUserId;
|
|
|
+ // data.resId = this.$store.state.userInfo.id;
|
|
|
+ // }
|
|
|
+ // this.$http.postJson('/message/save', data).then(res => {
|
|
|
+ // this.getList();
|
|
|
+ // });
|
|
|
+ // },
|
|
|
+ // addEmoji(emoji) {
|
|
|
+ // this.message = this.message + emoji + ' ';
|
|
|
+ // }
|
|
|
+ }
|
|
|
+};
|
|
|
+</script>
|
|
|
+<style lang="less" scoped>
|
|
|
+/deep/ page {
|
|
|
+ background-color: @bg;
|
|
|
+}
|
|
|
+.chat-list {
|
|
|
+ padding: 10px 20px 100px;
|
|
|
+ z-index: 1;
|
|
|
+}
|
|
|
+
|
|
|
+.bottom-box {
|
|
|
+ .bottom();
|
|
|
+ background-color: #fff;
|
|
|
+ position: fixed;
|
|
|
+ z-index: 200;
|
|
|
+ bottom: 0;
|
|
|
+ left: 0;
|
|
|
+ right: 0;
|
|
|
+}
|
|
|
+.input-box {
|
|
|
+ .flex();
|
|
|
+
|
|
|
+ .icon {
|
|
|
+ width: 28px;
|
|
|
+ height: 28px;
|
|
|
+ margin-left: 12px;
|
|
|
+ }
|
|
|
+
|
|
|
+ ._van-field {
|
|
|
+ flex-grow: 1;
|
|
|
+ }
|
|
|
+
|
|
|
+ padding: 8px 20px;
|
|
|
+}
|
|
|
+
|
|
|
+/deep/ .input-box {
|
|
|
+ .van-cell {
|
|
|
+ --cell-background-color: @bg;
|
|
|
+
|
|
|
+ border-radius: 8px;
|
|
|
+ &::after {
|
|
|
+ content: none;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ input {
|
|
|
+ font-weight: normal;
|
|
|
+ }
|
|
|
+
|
|
|
+ .van-button {
|
|
|
+ --button-small-min-width: 50px;
|
|
|
+ margin-left: 10px;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+.attach-box {
|
|
|
+ transition: height ease-in-out 0.3s;
|
|
|
+ padding: 0 20px;
|
|
|
+ overflow: hidden;
|
|
|
+ z-index: 2;
|
|
|
+ .up-btn {
|
|
|
+ width: 60px;
|
|
|
+ height: 60px;
|
|
|
+ border-radius: 8px;
|
|
|
+ border: 1px solid #f5f7fa;
|
|
|
+ .flex();
|
|
|
+ justify-content: center;
|
|
|
+ img {
|
|
|
+ width: 30px;
|
|
|
+ height: 20px;
|
|
|
+ display: block;
|
|
|
+ }
|
|
|
+
|
|
|
+ &:active {
|
|
|
+ background-color: #00000010;
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+.loading {
|
|
|
+ padding: 20px;
|
|
|
+ .flex();
|
|
|
+ justify-content: center;
|
|
|
+}
|
|
|
+.emojiList {
|
|
|
+ padding: 5px 0;
|
|
|
+ overflow: auto;
|
|
|
+ box-sizing: border-box;
|
|
|
+ height: 100%;
|
|
|
+ .flex();
|
|
|
+ flex-wrap: wrap;
|
|
|
+}
|
|
|
+.emoji-item {
|
|
|
+ width: 20%;
|
|
|
+ flex-shrink: 0;
|
|
|
+ text-align: center;
|
|
|
+ padding: 10px 0;
|
|
|
+ margin-top: 10px;
|
|
|
+ border-radius: 2px;
|
|
|
+ &:active {
|
|
|
+ background-color: #00000010;
|
|
|
+ }
|
|
|
+ font-family: 'color-emoji';
|
|
|
+ font-size: 25px;
|
|
|
+}
|
|
|
+</style>
|