优化聊天界面时间的显示

This commit is contained in:
赵毅 2025-11-14 17:49:30 +08:00
parent 97056bf5b5
commit 70b747bcd0

View File

@ -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(); //