mirror of
https://gitee.com/mateos/mateclaw.git
synced 2026-09-15 20:08:18 +08:00
feat(ui-chat): respect locale and bucket message bubble timestamps by today/yesterday/earlier
Replace hardcoded zh-CN locale with vue-i18n locale.value, add a yesterday bucket reusing the security.activity.yesterday key, and fall back to YYYY/MM/DD HH:mm for older messages. Computes the previous day with setDate(getDate()-1) so DST transitions stay correct, and short-circuits invalid Date inputs.
This commit is contained in:
parent
d09b9de8a6
commit
7b9ec75137
@ -423,7 +423,7 @@ import type { Message, MessageSegment, ChatAttachment, ToolCallMeta, PlanMeta }
|
|||||||
import type { ChatErrorInfo } from '@/types/chatError'
|
import type { ChatErrorInfo } from '@/types/chatError'
|
||||||
|
|
||||||
const { renderMarkdown } = useMarkdownRenderer()
|
const { renderMarkdown } = useMarkdownRenderer()
|
||||||
const { t } = useI18n()
|
const { t,locale} = useI18n()
|
||||||
const { getToolLabel } = useToolLabel()
|
const { getToolLabel } = useToolLabel()
|
||||||
const { blobUrls, loadAllImages, loadAllVideos, loadAllAudios, loadAllModels, downloadFile, openImage, getDisplayUrl, revokeAll } = useAuthenticatedAttachment()
|
const { blobUrls, loadAllImages, loadAllVideos, loadAllAudios, loadAllModels, downloadFile, openImage, getDisplayUrl, revokeAll } = useAuthenticatedAttachment()
|
||||||
|
|
||||||
@ -747,8 +747,39 @@ watch(model3dAttachments, (atts) => {
|
|||||||
|
|
||||||
// --- 时间 ---
|
// --- 时间 ---
|
||||||
const formattedTime = computed(() => {
|
const formattedTime = computed(() => {
|
||||||
if (!props.message.createTime) return ''
|
const createTime = props.message.createTime
|
||||||
return new Date(props.message.createTime).toLocaleTimeString('zh-CN', {
|
if (!createTime) return ''
|
||||||
|
|
||||||
|
const date = new Date(createTime)
|
||||||
|
if (Number.isNaN(date.getTime())) return ''
|
||||||
|
|
||||||
|
const now = new Date()
|
||||||
|
|
||||||
|
const sameDay = (a: Date, b: Date) =>
|
||||||
|
a.getFullYear() === b.getFullYear() &&
|
||||||
|
a.getMonth() === b.getMonth() &&
|
||||||
|
a.getDate() === b.getDate()
|
||||||
|
|
||||||
|
const currentLocale = locale.value
|
||||||
|
|
||||||
|
const time = date.toLocaleTimeString(currentLocale, {
|
||||||
|
hour: '2-digit',
|
||||||
|
minute: '2-digit',
|
||||||
|
})
|
||||||
|
|
||||||
|
if (sameDay(date, now)) return time
|
||||||
|
|
||||||
|
const yesterday = new Date(now)
|
||||||
|
yesterday.setDate(now.getDate() - 1)
|
||||||
|
|
||||||
|
if (sameDay(date, yesterday)) {
|
||||||
|
return `${t('security.activity.yesterday')} ${time}`
|
||||||
|
}
|
||||||
|
|
||||||
|
return date.toLocaleString(currentLocale, {
|
||||||
|
year: 'numeric',
|
||||||
|
month: '2-digit',
|
||||||
|
day: '2-digit',
|
||||||
hour: '2-digit',
|
hour: '2-digit',
|
||||||
minute: '2-digit',
|
minute: '2-digit',
|
||||||
})
|
})
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user