feat: stores 部分接入 i18n(auth/settings/apistats/dashboard/clients:标题、错误与日期提示本地化)

This commit is contained in:
Wangnov
2025-09-10 18:04:26 +08:00
parent 5f5826ce56
commit 01eadea10b
5 changed files with 53 additions and 35 deletions

View File

@@ -1,6 +1,7 @@
import { defineStore } from 'pinia'
import { ref } from 'vue'
import { apiClient } from '@/config/api'
import i18n from '@/i18n'
export const useSettingsStore = defineStore('settings', () => {
// 状态
@@ -77,7 +78,7 @@ export const useSettingsStore = defineStore('settings', () => {
const applyOemSettings = () => {
// 更新页面标题
if (oemSettings.value.siteName) {
document.title = `${oemSettings.value.siteName} - 管理后台`
document.title = `${oemSettings.value.siteName} - ${i18n.global.t('header.adminPanel')}`
}
// 更新favicon
@@ -94,7 +95,9 @@ export const useSettingsStore = defineStore('settings', () => {
// 格式化日期时间
const formatDateTime = (dateString) => {
if (!dateString) return ''
return new Date(dateString).toLocaleString('zh-CN', {
const localeMap = { 'zh-cn': 'zh-CN', 'zh-tw': 'zh-TW', en: 'en-US' }
const currentLocale = localeMap[i18n.global.locale.value] || 'en-US'
return new Date(dateString).toLocaleString(currentLocale, {
year: 'numeric',
month: '2-digit',
day: '2-digit',
@@ -110,13 +113,13 @@ export const useSettingsStore = defineStore('settings', () => {
// 检查文件大小 (350KB)
if (file.size > 350 * 1024) {
errors.push('图标文件大小不能超过 350KB')
errors.push(i18n.global.t('settings.validation.iconTooLarge'))
}
// 检查文件类型
const allowedTypes = ['image/x-icon', 'image/png', 'image/jpeg', 'image/jpg', 'image/svg+xml']
if (!allowedTypes.includes(file.type)) {
errors.push('不支持的文件类型,请选择 .ico, .png, .jpg 或 .svg 文件')
errors.push(i18n.global.t('settings.validation.iconTypeNotSupported'))
}
return {