修复切换语言时间格式没有变化

This commit is contained in:
eoao
2025-09-21 19:26:50 +08:00
parent 6953827d23
commit 655c4fc11c
7 changed files with 358 additions and 226 deletions
+1
View File
@@ -166,6 +166,7 @@ async function copyEmail(email) {
}
function changeLang(lang) {
setExtend(lang === 'en' ? 'en' : 'zh-cn')
settingStore.lang = lang
}
+28 -24
View File
@@ -6,7 +6,7 @@ import {useSettingStore} from "@/store/setting.js";
const settingStore = useSettingStore();
dayjs.extend(utc)
dayjs.extend(timezone)
dayjs.locale(settingStore.lang === 'zh' ? 'zh-cn' : '')
dayjs.locale(settingStore.lang === 'en' ? 'en' : 'zh-cn')
const timeZone = Intl.DateTimeFormat().resolvedOptions().timeZone;
export function fromNow(date) {
@@ -16,25 +16,7 @@ export function fromNow(date) {
const diffMinutes = now.diff(d, 'minute');
const diffHours = now.diff(d, 'hour');
const isToday = now.isSame(d, 'day');
if (settingStore.lang === 'zh') {
if (isToday) {
if (diffSeconds < 60) return `几秒前`;
if (diffMinutes < 60) return `${diffMinutes}分钟前`;
if (diffHours >= 1 && diffHours < 2) return '1小时前';
return d.format('HH:mm');
}
else if (now.subtract(1, 'day').isSame(d, 'day')) {
return `昨天 ${d.format('HH:mm')}`;
}
else if (now.subtract(2, 'day').isSame(d, 'day')) {
return `前天 ${d.format('HH:mm')}`;
}
return d.year() === now.year()
? d.format('M月D日')
: d.format('YYYY/M/D');
} else {
if (settingStore.lang === 'en') {
if (isToday) {
if (diffSeconds < 60) return `Just now`;
@@ -52,6 +34,24 @@ export function fromNow(date) {
: d.format('YYYY/MM/DD');
} else {
if (isToday) {
if (diffSeconds < 60) return `几秒前`;
if (diffMinutes < 60) return `${diffMinutes}分钟前`;
if (diffHours >= 1 && diffHours < 2) return '1小时前';
return d.format('HH:mm');
}
else if (now.subtract(1, 'day').isSame(d, 'day')) {
return `昨天 ${d.format('HH:mm')}`;
}
else if (now.subtract(2, 'day').isSame(d, 'day')) {
return `前天 ${d.format('HH:mm')}`;
}
return d.year() === now.year()
? d.format('M月D日')
: d.format('YYYY/M/D');
}
}
@@ -63,12 +63,12 @@ export function formatDetailDate(time) {
const isSameYear = now.year() === d.year();
if (settingStore.lang === 'zh') {
return d.format('YYYY年M月D日 ddd AH:mm');
} else {
if (settingStore.lang === 'en') {
return isSameYear
? d.format('ddd, MMM D, h:mm A')
: d.format('ddd, MMM D, YYYY, h:mm A');
} else {
return d.format('YYYY年M月D日 ddd AH:mm');
}
}
@@ -78,4 +78,8 @@ export function tzDayjs(time) {
export function toUtc(time) {
return dayjs(time).utc()
}
}
export function setExtend(lang) {
dayjs.locale(lang)
}
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
+4 -4
View File
@@ -5,10 +5,10 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<title></title>
<link rel="icon" href="/assets/favicon-C5dAZutX.svg" type="image/svg+xml">
<link href="https://fonts.googleapis.com/css2?family=Noto+Sans+SC:wght@400;500;700&display=swap" rel="stylesheet">
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;600&display=swap" rel="stylesheet">
<script src="https://challenges.cloudflare.com/turnstile/v0/api.js" async defer></script>
<script type="module" crossorigin src="/assets/index-CNTu5xWQ.js"></script>
<link rel="stylesheet" crossorigin href="/assets/index-NqVTnf-N.css">
<script type="module" crossorigin src="/assets/index-BRemZkSo.js"></script>
<link rel="stylesheet" crossorigin href="/assets/index-B8KYiaRG.css">
</head>
<body>
<div id="loading-first">
@@ -95,4 +95,4 @@
opacity: 1;
}
}
</style>
</style>
+5 -1
View File
@@ -26,7 +26,11 @@ const init = {
},
async v1_7DB(c) {
await c.env.db.prepare(`ALTER TABLE setting ADD COLUMN login_domain INTEGER NOT NULL DEFAULT 0;`).run();
try {
await c.env.db.prepare(`ALTER TABLE setting ADD COLUMN login_domain INTEGER NOT NULL DEFAULT 0;`).run();
} catch (e) {
console.error(e.message)
}
},
async v1_6DB(c) {