From efa7a4c4fa831d5c3765e14ed38291244037797a Mon Sep 17 00:00:00 2001 From: Lewis_yan Date: Thu, 9 Apr 2026 08:59:59 +0800 Subject: [PATCH] fix(i18n): make time-based greeting i18n compatible - Modify formatAxis to return i18n keys instead of hardcoded strings - Update account.vue and changePwd.vue to translate the greeting - Add useI18n to personal/index.vue and translate the greeting --- web/src/utils/formatTime.ts | 18 +++++++++--------- .../views/system/login/component/account.vue | 2 +- .../views/system/login/component/changePwd.vue | 2 +- web/src/views/system/personal/index.vue | 4 +++- 4 files changed, 14 insertions(+), 12 deletions(-) diff --git a/web/src/utils/formatTime.ts b/web/src/utils/formatTime.ts index 441e30c..b9aff43 100644 --- a/web/src/utils/formatTime.ts +++ b/web/src/utils/formatTime.ts @@ -122,16 +122,16 @@ export function formatPast(param: string | Date, format: string = 'YYYY-mm-dd'): * 时间问候语 * @param param 当前时间,new Date() 格式 * @description param 调用 `formatAxis(new Date())` 输出 `上午好` - * @returns 返回拼接后的时间字符串 + * @returns 返回 i18n key 路径 */ export function formatAxis(param: Date): string { let hour: number = new Date(param).getHours(); - if (hour < 6) return '凌晨好'; - else if (hour < 9) return '早上好'; - else if (hour < 12) return '上午好'; - else if (hour < 14) return '中午好'; - else if (hour < 17) return '下午好'; - else if (hour < 19) return '傍晚好'; - else if (hour < 22) return '晚上好'; - else return '夜里好'; + if (hour < 6) return 'message.common.greeting.dawn'; + else if (hour < 9) return 'message.common.greeting.morning'; + else if (hour < 12) return 'message.common.greeting.lateMorning'; + else if (hour < 14) return 'message.common.greeting.noon'; + else if (hour < 17) return 'message.common.greeting.afternoon'; + else if (hour < 19) return 'message.common.greeting.evening'; + else if (hour < 22) return 'message.common.greeting.night'; + else return 'message.common.greeting.lateNight'; } diff --git a/web/src/views/system/login/component/account.vue b/web/src/views/system/login/component/account.vue index 2ac78ae..b9396b8 100644 --- a/web/src/views/system/login/component/account.vue +++ b/web/src/views/system/login/component/account.vue @@ -119,7 +119,7 @@ export default defineComponent({ const formRef = ref(); // 时间获取 const currentTime = computed(() => { - return formatAxis(new Date()); + return t(formatAxis(new Date())); }); // 是否关闭验证码 const isShowCaptcha = computed(() => { diff --git a/web/src/views/system/login/component/changePwd.vue b/web/src/views/system/login/component/changePwd.vue index 4b6d19c..c805cdc 100644 --- a/web/src/views/system/login/component/changePwd.vue +++ b/web/src/views/system/login/component/changePwd.vue @@ -148,7 +148,7 @@ export default defineComponent({ const formRef = ref(); // 时间获取 const currentTime = computed(() => { - return formatAxis(new Date()); + return t(formatAxis(new Date())); }); const applyBtnClick = async () => { diff --git a/web/src/views/system/personal/index.vue b/web/src/views/system/personal/index.vue index 8447b51..b1021f3 100644 --- a/web/src/views/system/personal/index.vue +++ b/web/src/views/system/personal/index.vue @@ -183,6 +183,7 @@