add locale changer

This commit is contained in:
QuangNN 2023-10-31 00:47:29 +07:00
parent 1740d3d281
commit 2376e9bbc8
5 changed files with 33 additions and 0 deletions

View File

@ -1,4 +1,5 @@
{
"lang": "中文",
"app_name": "Vue FastAPI Admin",
"header": {
"label_profile": "个人信息",

View File

@ -1,4 +1,5 @@
{
"lang": "English",
"app_name": "Vue FastAPI Admin",
"header": {
"label_profile": "Profile",

View File

@ -0,0 +1,25 @@
<template>
<n-dropdown :options="options" @select="handleChangeLocale" v-model="locale">
<n-icon mr-20 size="18" style="cursor: pointer">
<icon-mdi:globe/>
</n-icon>
</n-dropdown>
</template>
<script setup>
import {useI18n} from 'vue-i18n'
const {availableLocales, locale,} = useI18n()
const options = []
availableLocales.forEach(locale => {
options.push({
label: locale,
key: locale
})
})
const handleChangeLocale = (value) => {
locale.value = value
}
</script>

View File

@ -4,6 +4,7 @@
<BreadCrumb ml-15 hidden sm:block />
</div>
<div ml-auto flex items-center>
<Languages />
<ThemeMode />
<GithubSite />
<FullScreen />
@ -18,4 +19,5 @@ import FullScreen from './components/FullScreen.vue'
import UserAvatar from './components/UserAvatar.vue'
import GithubSite from './components/GithubSite.vue'
import ThemeMode from './components/ThemeMode.vue'
import Languages from './components/Languages.vue';
</script>

View File

@ -11,6 +11,7 @@ export const useAppStore = defineStore('app', {
/** keepAlive路由的key重新赋值可重置keepAlive */
aliveKeys: {},
isDark,
locale: 'en'
}
},
actions: {
@ -45,5 +46,8 @@ export const useAppStore = defineStore('app', {
toggleDark() {
this.isDark = !this.isDark
},
setLocale(locale) {
this.locale = locale
}
},
})