优化聊天界面时间的显示
This commit is contained in:
parent
97056bf5b5
commit
70b747bcd0
@ -23,7 +23,7 @@
|
||||
<!-- 消息列表 -->
|
||||
<block v-for="(message, index) in messages" :key="index">
|
||||
<!-- 时间分割线 -->
|
||||
<view v-if="needShowTime(index)" class="message-time">{{ formatTime(message.time) }}</view>
|
||||
<view v-if="needShowTime(index)" class="message-time">{{ message.times }}</view>
|
||||
|
||||
<!-- 消息项 -->
|
||||
<view :id="'msg-' + index" :class="{
|
||||
@ -76,14 +76,7 @@ export default {
|
||||
userAvatar: '',
|
||||
// 消息列表
|
||||
messages: [],
|
||||
// 测试消息数据
|
||||
testMessages: [
|
||||
{ id: 1, content: '你好,有什么可以帮助你的吗?', time: new Date().getTime() - 300000, isSelf: false },
|
||||
{ id: 2, content: '我想咨询一下产品信息', time: new Date().getTime() - 240000, isSelf: true },
|
||||
{ id: 3, content: '好的,请问您想了解哪款产品?', time: new Date().getTime() - 180000, isSelf: false },
|
||||
{ id: 4, content: '最新推出的那款智能手表', time: new Date().getTime() - 120000, isSelf: true },
|
||||
{ id: 5, content: '好的,我为您介绍一下这款产品的详细信息...', time: new Date().getTime() - 60000, isSelf: false }
|
||||
],
|
||||
|
||||
// 输入的消息
|
||||
inputMessage: '',
|
||||
// 是否可以发送消息
|
||||
@ -243,17 +236,7 @@ export default {
|
||||
await this.loadHistoryMessages()
|
||||
console.log('历史消息加载完成,消息数量:', this.messages.length)
|
||||
|
||||
// 如果没有获取到真实消息,使用测试数据
|
||||
if (this.messages.length === 0) {
|
||||
console.log('没有获取到真实消息,使用测试数据')
|
||||
this.messages = [...this.testMessages]
|
||||
console.log('测试消息加载完成,消息数量:', this.messages.length)
|
||||
|
||||
// 滚动到底部显示最新消息
|
||||
setTimeout(() => {
|
||||
this.scrollToView = 'msg-' + (this.messages.length - 1);
|
||||
}, 100);
|
||||
}
|
||||
|
||||
} catch (error) {
|
||||
console.error('初始化聊天失败', error)
|
||||
this.connectingStatus = '连接失败,请检查网络'
|
||||
@ -367,6 +350,7 @@ export default {
|
||||
const formattedMessages = historyMessages.map(msg => ({
|
||||
content: msg.content,
|
||||
time: new Date(msg.create_time).getTime(),
|
||||
times: msg.update_time,
|
||||
isSelf: msg.send_client === this.selfClientId, // 修正判断条件
|
||||
isLoading: false
|
||||
})).reverse(); // 反转消息顺序,确保最早的消息在最前面
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user