|
@@ -1,5 +1,8 @@
|
|
|
<template>
|
|
|
<view>
|
|
|
+ <view class="notice">
|
|
|
+ <up-notice-bar text="为了您的交易安全和售后保障,请您务必在平台内完成交易!" icon=""></up-notice-bar>
|
|
|
+ </view>
|
|
|
<view class="container" :style="pageHeight">
|
|
|
<view class="box-1">
|
|
|
<scroll-view scroll-y refresher-background="transparent" style="height: 100%;"
|
|
@@ -7,9 +10,11 @@
|
|
|
:refresher-triggered="scrollView.refresherTriggered" :scroll-into-view="scrollView.intoView">
|
|
|
<view class="talk-list">
|
|
|
<view v-for="(item, index) in talkList" :key="item.msgSendTime" :id="'msg-' + item.msgSendTime">
|
|
|
+ <view v-if="showTimeLabel(item, index)" class="time-label"> {{ showTimeLabel(item, index) }}</view>
|
|
|
<view class="item flex-col" :class="item.senderId == this.userId ? 'push' : 'pull'">
|
|
|
<!-- <image :src="item.pic" mode="aspectFill" class="pic"></image> -->
|
|
|
- <img v-if="item.senderId !== this.userId" :src="orderInfo.conversationAvatar || '/static/serverImg/mine/user.png' " alt=""
|
|
|
+ <img v-if="item.senderId !== this.userId"
|
|
|
+ :src="orderInfo.conversationAvatar || '/static/serverImg/mine/user.png'" alt=""
|
|
|
class="pic" mode="aspectFill" />
|
|
|
<img src="/static/serverImg/mine/user.png" alt="" class="pic" mode="aspectFill"
|
|
|
v-else />
|
|
@@ -45,9 +50,11 @@
|
|
|
|
|
|
<script>
|
|
|
import { wxUploadFile, wxMakePhoneCall } from '@/utils/wxRequest.js'
|
|
|
-import { sendMsg, getOrderConversationInfo, getListConversationInfo, setRead,getHistoryMsg } from '@/api/conversation.js';
|
|
|
+import { sendMsg, getOrderConversationInfo, getListConversationInfo, setRead, getHistoryMsg } from '@/api/conversation.js';
|
|
|
import { onMounted } from "vue";
|
|
|
-import store from "@/store"
|
|
|
+import dayjs from 'dayjs/esm/index'
|
|
|
+import store from "@/store";
|
|
|
+import { handleTime } from '../../request/dateTime';
|
|
|
export default {
|
|
|
data() {
|
|
|
return {
|
|
@@ -73,8 +80,8 @@ export default {
|
|
|
system: '2',
|
|
|
userId: uni.getStorageSync('userId'), //读取本地存储
|
|
|
conversationRecordId: null,//会话id
|
|
|
- storeUser: store.state.user,
|
|
|
- store:store,
|
|
|
+ storeUser: store.state.user,
|
|
|
+ store: store,
|
|
|
}
|
|
|
},
|
|
|
computed: {
|
|
@@ -107,7 +114,7 @@ export default {
|
|
|
|
|
|
this.getMessage();
|
|
|
|
|
|
-
|
|
|
+
|
|
|
|
|
|
},
|
|
|
onMounted() {
|
|
@@ -122,7 +129,7 @@ export default {
|
|
|
|
|
|
|
|
|
// });
|
|
|
-
|
|
|
+
|
|
|
|
|
|
},
|
|
|
methods: {
|
|
@@ -131,13 +138,13 @@ export default {
|
|
|
console.log("TCL: 下拉刷新 -> e", e)
|
|
|
this.scrollView.refresherTriggered = true;
|
|
|
// this.getMessage();
|
|
|
- const conversationMsgRecordId = this.talkList[this.talkList.length-1].conversationMsgRecordId;
|
|
|
- console.log("TCL: refresherrefresh -> conversationMsgRecordId", conversationMsgRecordId,this.talkList[this.talkList.length-1])
|
|
|
- const msgSendTime = this.talkList[this.talkList.length-1].msgSendTime
|
|
|
- getHistoryMsg({conversationMsgRecordId,conversationRecordId:this.conversationRecordId}).then(res => {
|
|
|
+ const conversationMsgRecordId = this.talkList[this.talkList.length - 1].conversationMsgRecordId;
|
|
|
+ console.log("TCL: refresherrefresh -> conversationMsgRecordId", conversationMsgRecordId, this.talkList[this.talkList.length - 1])
|
|
|
+ const msgSendTime = this.talkList[this.talkList.length - 1].msgSendTime
|
|
|
+ getHistoryMsg({ conversationMsgRecordId, conversationRecordId: this.conversationRecordId }).then(res => {
|
|
|
console.log("TCL: refresherrefresh -> res", res)
|
|
|
- if(res.code === 200){
|
|
|
- if(res.data.length === 0) {
|
|
|
+ if (res.code === 200) {
|
|
|
+ if (res.data.length === 0) {
|
|
|
uni.showToast({
|
|
|
title: '没有更多消息了',
|
|
|
icon: 'none'
|
|
@@ -145,14 +152,14 @@ export default {
|
|
|
this.scrollView.refresherTriggered = false;
|
|
|
return
|
|
|
}
|
|
|
- this.talkList = [...this.talkList,...res.data];
|
|
|
+ this.talkList = [...this.talkList, ...res.data];
|
|
|
this.scrollView.refresherTriggered = false;
|
|
|
this.scrollView.intoView = `msg-${msgSendTime}`;
|
|
|
}
|
|
|
})
|
|
|
},
|
|
|
- listsMessage(){
|
|
|
- console.log('-----listsMessage---->', this.storeUser,this.storeUser.wsManager);
|
|
|
+ listsMessage() {
|
|
|
+ console.log('-----listsMessage---->', this.storeUser, this.storeUser.wsManager);
|
|
|
|
|
|
this.storeUser.wsManager.onMessage(res => {
|
|
|
console.log('--------->', res)
|
|
@@ -173,8 +180,8 @@ export default {
|
|
|
if (!this.storeUser.wsManager) {
|
|
|
store.dispatch('GetInfo').then((res) => {
|
|
|
this.listsMessage();
|
|
|
- });
|
|
|
- }else{
|
|
|
+ });
|
|
|
+ } else {
|
|
|
this.listsMessage();
|
|
|
}
|
|
|
|
|
@@ -197,7 +204,7 @@ export default {
|
|
|
|
|
|
const res = await apiFun(parmas);
|
|
|
console.log("TCL: getOrder -> res", res)
|
|
|
-
|
|
|
+
|
|
|
if (res.code === 200) {
|
|
|
const data = res.data.vos;
|
|
|
// 获取待滚动元素选择器,解决插入数据后,滚动条定位时使用。取当前消息数据的第一条信息元素
|
|
@@ -255,7 +262,7 @@ export default {
|
|
|
msgContent: content,
|
|
|
msgSendTime: new Date().getTime(),
|
|
|
senderId: this.userId,
|
|
|
- msgType: contentType =='text'?'1':'2',//消息类型 1文字消息 2图片消息
|
|
|
+ msgType: contentType == 'text' ? '1' : '2',//消息类型 1文字消息 2图片消息
|
|
|
}
|
|
|
const res = await sendMsg({
|
|
|
...this.orderInfo,
|
|
@@ -266,6 +273,31 @@ export default {
|
|
|
this.talkList.unshift({ ...data, code: res.code });
|
|
|
this.scrollView.intoView = `msg-${data.msgSendTime}`;
|
|
|
},
|
|
|
+ showTimeLabel(item, index) {
|
|
|
+ const { talkList } = this;
|
|
|
+ const isLastItem = index === talkList.length - 1;
|
|
|
+
|
|
|
+ // 最后一条消息,强制显示时间
|
|
|
+ if (isLastItem) {
|
|
|
+ return handleTime(item.msgSendTime);
|
|
|
+ }
|
|
|
+
|
|
|
+ const nextItem = talkList[index + 1];
|
|
|
+
|
|
|
+ // 如果没有下一条,不显示
|
|
|
+ if (!nextItem) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ const diffInMinutes = dayjs(nextItem.msgSendTime).diff(dayjs(item.msgSendTime), 'minute');
|
|
|
+
|
|
|
+ // 如果下一条消息与当前消息间隔 >= 30 分钟,则由下一条显示时间
|
|
|
+ if (Math.abs(diffInMinutes) >= 30) {
|
|
|
+ return handleTime(item.msgSendTime);
|
|
|
+ }
|
|
|
+
|
|
|
+ return null;
|
|
|
+ }
|
|
|
|
|
|
},
|
|
|
|
|
@@ -280,8 +312,12 @@ page {
|
|
|
font-size: 28rpx;
|
|
|
}
|
|
|
|
|
|
+.notice {
|
|
|
+ height: 40px;
|
|
|
+}
|
|
|
+
|
|
|
.container {
|
|
|
- height: calc(100vh - var(--window-top));
|
|
|
+ height: calc(100vh - var(--window-top) - 40px);
|
|
|
display: flex;
|
|
|
flex-direction: column;
|
|
|
flex-wrap: nowrap;
|
|
@@ -446,4 +482,9 @@ page {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+.time-label {
|
|
|
+ text-align: center;
|
|
|
+ margin-top: 16rpx;
|
|
|
+}
|
|
|
</style>
|