修复组件多语言bug

This commit is contained in:
ray_wuhao 2023-03-10 16:51:24 +08:00
parent ffef1ee509
commit 94acacf9b8
5 changed files with 34 additions and 32 deletions

View File

@ -15,6 +15,10 @@
## 3.1.2
### Fixes
- 修复 DatePicker 组件国际化部分失效问题
### Feats
- 修改 demo 页面展示

View File

@ -9,7 +9,7 @@ import {
NGlobalStyle,
} from 'naive-ui'
import { useSetting } from '@/store'
import { naiveLocales } from '@/language/index'
const GlobalProvider = defineComponent({
name: 'GlobalProvider',
setup() {
@ -21,7 +21,11 @@ const GlobalProvider = defineComponent({
const modelThemeValue = computed(() =>
settingStore.themeValue ? darkTheme : null,
)
const modelLocal = computed(() => settingStore.naiveLocal)
const localePackage = computed(() => {
const key = settingStore.localeLanguage
return naiveLocales(key)
})
const { message, notification, dialog, loadingBar } = createDiscreteApi(
['message', 'dialog', 'notification', 'loadingBar'],
@ -40,7 +44,7 @@ const GlobalProvider = defineComponent({
return {
modelPrimaryColorOverride,
modelThemeValue,
modelLocal,
localePackage,
}
},
render() {
@ -48,8 +52,8 @@ const GlobalProvider = defineComponent({
<NConfigProvider
themeOverrides={this.modelPrimaryColorOverride}
theme={this.modelThemeValue}
locale={this.modelLocal.local}
dateLocal={this.modelLocal.dateLocal}
locale={this.localePackage.locale}
dateLocale={this.localePackage.dateLocal}
>
<NLoadingBarProvider>
<NMessageProvider>

View File

@ -10,7 +10,6 @@
*/
import { zhCN, dateZhCN } from 'naive-ui' // 导入 `naive ui` 中文包
import { enUS, dateEnUS } from 'naive-ui' // 导入 `naive ui` 英文包
/** 语言包语种添加后, 需要在此文件配置语言包 */
export const localOptions = [
@ -30,24 +29,25 @@ export const localOptions = [
* @returns
*
* @remark . , (https://www.naiveui.com/zh-CN/dark/docs/i18n)
* @remark naive ui
*/
export const naiveLocales = (key: string) => {
switch (key) {
case 'zh-CN':
return {
local: zhCN,
locale: zhCN,
dateLocal: dateZhCN,
}
case 'en-US':
return {
local: enUS,
dateLocal: dateEnUS,
locale: null,
dateLocal: null,
}
default:
return {
local: zhCN,
locale: zhCN,
dateLocal: dateZhCN,
}
}

View File

@ -1,4 +1,4 @@
import { naiveLocales, getDefaultNaiveLocal } from '@/language/index'
import { getDefaultLocal } from '@/language/index'
import { setCache } from '@use-utils/cache'
export const useSetting = defineStore(
@ -14,16 +14,16 @@ export const useSetting = defineStore(
themeValue: false, // `true` 为黑夜主题, `false` 为白色主题
reloadRouteSwitch: true, // 刷新路由开关
menuTagSwitch: true, // 多标签页开关
naiveLocal: getDefaultNaiveLocal(), // `naive ui` 语言包
spinSwitch: false, // 全屏加载
breadcrumbSwitch: true, // 面包屑开关
localeLanguage: getDefaultLocal(),
})
const { locale } = useI18n()
const updateLocale = (key: string) => {
// TODO: 修改语言
locale.value = key
settingState.naiveLocal = naiveLocales(key)
settingState.localeLanguage = key
setCache('localeLanguage', key, 'localStorage')
}

View File

@ -169,7 +169,17 @@ const TableView = defineComponent({
</NLi>
<NLi> RayCollapseGird 使</NLi>
</NUl>
<NH2> RayCollapseGird 使</NH2>
<NH2> RayCollapseGird 使 RayTable </NH2>
<NP>
使 columns action
(v-model:columns)
</NP>
<NP></NP>
<NP></NP>
<NP></NP>
<NP> excel </NP>
<NP></NP>
<NP></NP>
<RayCollapseGrid
bordered={false}
collapsedRows={this.gridCollapsedRows}
@ -219,26 +229,17 @@ const TableView = defineComponent({
)}
data={this.tableData}
columns={this.baseColumns}
action={false}
pagination={{
pageSize: 10,
}}
loading={this.tableLoading}
rightClickMenu={this.tableMenuOptions}
onMenuSelect={this.handleMenuSelect.bind(this)}
>
{{
tableFooter: () => '表格的底部内容区域,有时候你可能会用上',
}}
</RayTable>
<NH2>RayTable </NH2>
<NP>
使 columns action
(v-model:columns)
</NP>
<NP></NP>
<NP></NP>
<NP></NP>
<NP> excel </NP>
<NP></NP>
<RayTable
title={h(NInput, {
placeholder: '请输入检索条件',
@ -247,13 +248,6 @@ const TableView = defineComponent({
data={this.tableData}
v-model:columns={this.actionColumns}
bordered={false}
/>
<NH2></NH2>
<RayTable
title="右键菜单表格"
action={false}
data={this.tableData}
columns={this.baseColumns}
rightClickMenu={this.tableMenuOptions}
onMenuSelect={this.handleMenuSelect.bind(this)}
/>