feat(I18n): Add Ii8n
feat(LocaleDropdown): Add LocaleDropdown Component feat(store): Add localeStore
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
import { defineStore } from 'pinia'
|
||||
|
||||
import { store } from '../index'
|
||||
|
||||
export type LayoutType = 'Classic' | 'LeftTop' | 'Top' | 'Test'
|
||||
@@ -24,7 +23,6 @@ export interface AppState {
|
||||
requestTime: boolean
|
||||
isDark: boolean
|
||||
size: ElememtPlusSzie
|
||||
lang: string
|
||||
}
|
||||
|
||||
export const useAppStore = defineStore({
|
||||
@@ -48,8 +46,7 @@ export const useAppStore = defineStore({
|
||||
showMenuTab: false, // 是否固定一级菜单
|
||||
requestTime: false, // 是否在接口调用时添加时间戳,避免IE缓存
|
||||
isDark: false, // 是否是暗黑模式
|
||||
size: 'default', // 组件尺寸
|
||||
lang: 'zh-CN' // 语言
|
||||
size: 'default' // 组件尺寸
|
||||
}),
|
||||
getters: {
|
||||
getCollapsed(): boolean {
|
||||
@@ -108,9 +105,6 @@ export const useAppStore = defineStore({
|
||||
},
|
||||
getSize(): ElememtPlusSzie {
|
||||
return this.size
|
||||
},
|
||||
getLang(): string {
|
||||
return this.lang
|
||||
}
|
||||
},
|
||||
actions: {
|
||||
@@ -174,9 +168,6 @@ export const useAppStore = defineStore({
|
||||
},
|
||||
setSize(size: ElememtPlusSzie) {
|
||||
this.size = size
|
||||
},
|
||||
setLang(lang: string) {
|
||||
this.lang = lang
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
55
src/store/modules/locale.ts
Normal file
55
src/store/modules/locale.ts
Normal file
@@ -0,0 +1,55 @@
|
||||
import { defineStore } from 'pinia'
|
||||
import zhCn from 'element-plus/lib/locale/lang/zh-cn'
|
||||
import en from 'element-plus/lib/locale/lang/en'
|
||||
import { store } from '../index'
|
||||
|
||||
const elLocaleMap = {
|
||||
'zh-CN': zhCn,
|
||||
en: en
|
||||
}
|
||||
|
||||
export interface LocaleState {
|
||||
locale: LocaleDropdownType
|
||||
localeMap: LocaleDropdownType[]
|
||||
}
|
||||
|
||||
export const useLocaleStore = defineStore({
|
||||
id: 'locales',
|
||||
state: (): LocaleState => ({
|
||||
// 当前语言
|
||||
locale: {
|
||||
lang: 'zh-CN',
|
||||
elLocale: elLocaleMap['zh-CN']
|
||||
},
|
||||
// 多语言
|
||||
localeMap: [
|
||||
{
|
||||
lang: 'zh-CN',
|
||||
name: '简体中文'
|
||||
},
|
||||
{
|
||||
lang: 'en',
|
||||
name: 'English'
|
||||
}
|
||||
]
|
||||
}),
|
||||
getters: {
|
||||
getLocale(): LocaleDropdownType {
|
||||
return this.locale
|
||||
},
|
||||
getLocaleMap(): LocaleDropdownType[] {
|
||||
return this.localeMap
|
||||
}
|
||||
},
|
||||
actions: {
|
||||
setLocale(localeMap: LocaleDropdownType) {
|
||||
// this.locale = Object.assign(this.locale, localeMap)
|
||||
this.locale.lang = localeMap?.lang
|
||||
this.locale.elLocale = elLocaleMap[localeMap?.lang]
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
export function useLocaleStoreWithOut() {
|
||||
return useLocaleStore(store)
|
||||
}
|
||||
Reference in New Issue
Block a user