修复切换语言失败BUG
This commit is contained in:
@@ -178,7 +178,7 @@
|
|||||||
import { useMenuStore } from '@/store/modules/menu'
|
import { useMenuStore } from '@/store/modules/menu'
|
||||||
import AppConfig from '@/config'
|
import AppConfig from '@/config'
|
||||||
import { languageOptions } from '@/locales'
|
import { languageOptions } from '@/locales'
|
||||||
import { invalidatePageLocaleCache } from '@/locales/pageLocaleLoader'
|
import { invalidatePageLocaleCache, loadPageLocale } from '@/locales/pageLocaleLoader'
|
||||||
import { mittBus } from '@/utils/sys'
|
import { mittBus } from '@/utils/sys'
|
||||||
import { themeAnimation } from '@/utils/ui/animation'
|
import { themeAnimation } from '@/utils/ui/animation'
|
||||||
import { useCommon } from '@/hooks/core/useCommon'
|
import { useCommon } from '@/hooks/core/useCommon'
|
||||||
@@ -285,12 +285,12 @@
|
|||||||
* 切换系统语言
|
* 切换系统语言
|
||||||
* @param {LanguageEnum} lang - 目标语言类型
|
* @param {LanguageEnum} lang - 目标语言类型
|
||||||
*/
|
*/
|
||||||
const changeLanguage = (lang: LanguageEnum): void => {
|
const changeLanguage = async (lang: LanguageEnum): Promise<void> => {
|
||||||
if (locale.value === lang) return
|
if (locale.value === lang) return
|
||||||
locale.value = lang
|
locale.value = lang
|
||||||
userStore.setLanguage(lang)
|
userStore.setLanguage(lang)
|
||||||
invalidatePageLocaleCache()
|
invalidatePageLocaleCache()
|
||||||
reload(50)
|
await loadPageLocale(router.currentRoute.value.path)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -90,7 +90,7 @@
|
|||||||
:disabled="item.disabled"
|
:disabled="item.disabled"
|
||||||
class="flex-1 min-w-0 [&_.el-checkbox__label]:overflow-hidden [&_.el-checkbox__label]:text-ellipsis [&_.el-checkbox__label]:whitespace-nowrap"
|
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
|
}}</ElCheckbox
|
||||||
>
|
>
|
||||||
</div>
|
</div>
|
||||||
@@ -173,6 +173,15 @@
|
|||||||
(e: 'update:showSearchBar', value: boolean): void
|
(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 字段
|
* 优先使用 visible 字段,如果不存在则使用 checked 字段
|
||||||
|
|||||||
@@ -311,9 +311,12 @@
|
|||||||
/** 表头 label 为 table. 或 page. 开头的 i18n key 时自动翻译,切换语言后表头随动 */
|
/** 表头 label 为 table. 或 page. 开头的 i18n key 时自动翻译,切换语言后表头随动 */
|
||||||
const displayColumns = computed(() => {
|
const displayColumns = computed(() => {
|
||||||
const list = props.columns || []
|
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) => {
|
return list.map((col) => {
|
||||||
const label = col.label
|
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, label: $t(label) }
|
||||||
}
|
}
|
||||||
return col
|
return col
|
||||||
|
|||||||
Reference in New Issue
Block a user