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

This commit is contained in:
eoao
2025-09-21 19:26:50 +08:00
parent 6dc126d3b0
commit ea8ad14049
7 changed files with 358 additions and 226 deletions

View File

@@ -166,6 +166,7 @@ async function copyEmail(email) {
} }
function changeLang(lang) { function changeLang(lang) {
setExtend(lang === 'en' ? 'en' : 'zh-cn')
settingStore.lang = lang settingStore.lang = lang
} }

View File

@@ -6,7 +6,7 @@ import {useSettingStore} from "@/store/setting.js";
const settingStore = useSettingStore(); const settingStore = useSettingStore();
dayjs.extend(utc) dayjs.extend(utc)
dayjs.extend(timezone) dayjs.extend(timezone)
dayjs.locale(settingStore.lang === 'zh' ? 'zh-cn' : '') dayjs.locale(settingStore.lang === 'en' ? 'en' : 'zh-cn')
const timeZone = Intl.DateTimeFormat().resolvedOptions().timeZone; const timeZone = Intl.DateTimeFormat().resolvedOptions().timeZone;
export function fromNow(date) { export function fromNow(date) {
@@ -16,25 +16,7 @@ export function fromNow(date) {
const diffMinutes = now.diff(d, 'minute'); const diffMinutes = now.diff(d, 'minute');
const diffHours = now.diff(d, 'hour'); const diffHours = now.diff(d, 'hour');
const isToday = now.isSame(d, 'day'); const isToday = now.isSame(d, 'day');
if (settingStore.lang === 'zh') { if (settingStore.lang === 'en') {
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 (isToday) { if (isToday) {
if (diffSeconds < 60) return `Just now`; if (diffSeconds < 60) return `Just now`;
@@ -52,6 +34,24 @@ export function fromNow(date) {
: d.format('YYYY/MM/DD'); : 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(); const isSameYear = now.year() === d.year();
if (settingStore.lang === 'zh') { if (settingStore.lang === 'en') {
return d.format('YYYY年M月D日 ddd AH:mm');
} else {
return isSameYear return isSameYear
? d.format('ddd, MMM D, h:mm A') ? d.format('ddd, MMM D, h:mm A')
: d.format('ddd, MMM D, YYYY, 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) { export function toUtc(time) {
return dayjs(time).utc() 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

View File

@@ -5,10 +5,10 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0"/> <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<title></title> <title></title>
<link rel="icon" href="/assets/favicon-C5dAZutX.svg" type="image/svg+xml"> <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 src="https://challenges.cloudflare.com/turnstile/v0/api.js" async defer></script>
<script type="module" crossorigin src="/assets/index-CNTu5xWQ.js"></script> <script type="module" crossorigin src="/assets/index-BRemZkSo.js"></script>
<link rel="stylesheet" crossorigin href="/assets/index-NqVTnf-N.css"> <link rel="stylesheet" crossorigin href="/assets/index-B8KYiaRG.css">
</head> </head>
<body> <body>
<div id="loading-first"> <div id="loading-first">
@@ -95,4 +95,4 @@
to { to {
opacity: 1; opacity: 1;
} }
} }

View File

@@ -26,7 +26,11 @@ const init = {
}, },
async v1_7DB(c) { 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) { async v1_6DB(c) {