修复切换语言失败BUG

This commit is contained in:
2026-03-17 15:04:05 +08:00
parent 5b5e923a0b
commit 1892c7bcb7
3 changed files with 17 additions and 5 deletions

View File

@@ -178,7 +178,7 @@
import { useMenuStore } from '@/store/modules/menu'
import AppConfig from '@/config'
import { languageOptions } from '@/locales'
import { invalidatePageLocaleCache } from '@/locales/pageLocaleLoader'
import { invalidatePageLocaleCache, loadPageLocale } from '@/locales/pageLocaleLoader'
import { mittBus } from '@/utils/sys'
import { themeAnimation } from '@/utils/ui/animation'
import { useCommon } from '@/hooks/core/useCommon'
@@ -285,12 +285,12 @@
* 切换系统语言
* @param {LanguageEnum} lang - 目标语言类型
*/
const changeLanguage = (lang: LanguageEnum): void => {
const changeLanguage = async (lang: LanguageEnum): Promise<void> => {
if (locale.value === lang) return
locale.value = lang
userStore.setLanguage(lang)
invalidatePageLocaleCache()
reload(50)
await loadPageLocale(router.currentRoute.value.path)
}
/**

View File

@@ -90,7 +90,7 @@
:disabled="item.disabled"
class="flex-1 min-w-0 [&_.el-checkbox__label]:overflow-hidden [&_.el-checkbox__label]:text-ellipsis [&_.el-checkbox__label]:whitespace-nowrap"
>{{
item.label || (item.type === 'selection' ? t('table.selection') : '')
getColumnDisplayLabel(item.label, item.type)
}}</ElCheckbox
>
</div>
@@ -173,6 +173,15 @@
(e: 'update:showSearchBar', value: boolean): void
}>()
/** 列标题显示table./page. 开头的 key 用 t() 翻译,随语言切换更新 */
const getColumnDisplayLabel = (label: unknown, type?: string): string => {
if (type === 'selection') return t('table.selection')
if (label && typeof label === 'string' && (label.startsWith('table.') || label.startsWith('page.'))) {
return t(label)
}
return (label as string) || ''
}
/**
* 获取列的显示状态
* 优先使用 visible 字段,如果不存在则使用 checked 字段

View File

@@ -311,9 +311,12 @@
/** 表头 label 为 table. 或 page. 开头的 i18n key 时自动翻译,切换语言后表头随动 */
const displayColumns = computed(() => {
const list = props.columns || []
const localeRef = i18n.global.locale as { value?: string }
const currentLocale = localeRef && typeof localeRef === 'object' && 'value' in localeRef ? localeRef.value : (i18n.global.locale as string)
void currentLocale
return list.map((col) => {
const label = col.label
if (label && typeof label === 'string' && (label.startsWith('table.') || label.startsWith('page.')) && i18n.global.te(label)) {
if (label && typeof label === 'string' && (label.startsWith('table.') || label.startsWith('page.'))) {
return { ...col, label: $t(label) }
}
return col