refactor(chat): 优化时间戳显示和处理

- 移除了对 createdAtTimestamp 的引用,改为使用 createdAt
- 添加了对时间戳的格式化处理,支持字符串和数字类型的时间戳
- 增加了时间戳的有效性检查
- 调整了时间戳的显示位置和样式
This commit is contained in:
Lexcubia 2025-04-27 16:59:58 +08:00
parent 009d16d5c3
commit a101fc182b
1 changed files with 23 additions and 8 deletions

View File

@ -21,9 +21,9 @@
<el-avatar :src="userAvatarUrl" :size="40" class="avatar" />
<div class="message-content">
<div class="message-text-wrapper">
<!-- <div v-if="message.createdAt" class="message-timestamp">
{{ formatTimestamp(message.createdAtTimestamp) }}
</div> -->
<div v-if="message.createdAt" class="message-timestamp">
{{ formatTimestamp(message.createdAt) }}
</div>
<div class="message-text">{{ message.question }}</div>
</div>
<!-- 改进建议部分 -->
@ -55,9 +55,9 @@
<el-avatar :src="customAvatarUrl" :size="40" class="avatar" />
<div class="message-content">
<div class="message-text-wrapper">
<!-- <div v-if="message.createdAt" class="message-timestamp">
{{ formatTimestamp(message.createdAtTimestamp) }}
</div> -->
<div v-if="message.createdAt" class="message-timestamp">
{{ formatTimestamp(message.createdAt) }}
</div>
<div class="message-text">
<span v-html="message.kehu"></span>
<span v-if="message.respondingType === 'kehu'" class="typing-indicator">
@ -310,9 +310,20 @@ const toggleSummary = () => {
//
const formatTimestamp = (timestamp) => {
console.log('%c timestamp:', 'color: #2196F3; font-weight: bold', timestamp)
if (!timestamp) return ''
const date = new Date(timestamp)
//
const timestampNum = typeof timestamp === 'string' ? parseInt(timestamp) : timestamp
//
const date = new Date(timestampNum.toString().length === 10 ? timestampNum * 1000 : timestampNum)
//
if (isNaN(date.getTime())) {
console.error('Invalid timestamp:', timestamp)
return ''
}
return date.toLocaleString('zh-CN', {
year: 'numeric',
month: '2-digit',
@ -561,6 +572,9 @@ html.dark .background-section .background-content {
flex-direction: column;
align-items: flex-end;
}
.message-timestamp {
right: 0;
}
}
&.assistant {
@ -865,6 +879,7 @@ html.dark .background-section .background-content {
top: -20px;
opacity: 0;
transition: opacity 0.2s ease;
width: max-content;
}
.message-text-wrapper {