|
@@ -15,6 +15,7 @@
|
|
|
:class="{ [menu.key]: true }"
|
|
|
>
|
|
|
<img style="height: 10px" :src="menu.icon" />
|
|
|
+
|
|
|
{{ menu.label }}
|
|
|
</a-menu-item>
|
|
|
</a-menu>
|
|
@@ -41,7 +42,7 @@
|
|
|
class="menu-item"
|
|
|
:class="{ [menu.key]: true }"
|
|
|
>
|
|
|
- {{ menu.label }}
|
|
|
+ {{ t(menu.label) }}
|
|
|
</a-menu-item>
|
|
|
</a-menu>
|
|
|
</template>
|
|
@@ -76,6 +77,7 @@ import { LocaleType } from '#/config'
|
|
|
import { showLoading } from '@/components/loading'
|
|
|
import { getImgSrc } from '@/utils/getImgSrc'
|
|
|
import browser from '@/utils/browser'
|
|
|
+import { storeToRefs } from 'pinia'
|
|
|
// const getImgSrc = inject('getImgSrc')
|
|
|
|
|
|
defineOptions({ name: 'LayoutHeader' })
|
|
@@ -84,6 +86,7 @@ const userStore = useUserStore()
|
|
|
|
|
|
userStore.fetch()
|
|
|
const { localInfo, getLocale } = useLocaleStore()
|
|
|
+
|
|
|
const { t } = useI18n()
|
|
|
const currentLang = ref({
|
|
|
key: getLocale,
|
|
@@ -96,7 +99,7 @@ const currentLang = ref({
|
|
|
// label: t(`base.lang.${unref(getLocale)}`)
|
|
|
// }
|
|
|
// })
|
|
|
-const isEn = computed(() => unref(getLocale) === 'en')
|
|
|
+const isEn = computed(() => unref(currentLang).key === 'en')
|
|
|
// console.log('getImgSrc', getImgSrc)
|
|
|
const langList = localInfo.availableLocales.map((item: string) => {
|
|
|
return {
|
|
@@ -109,8 +112,8 @@ const langList = localInfo.availableLocales.map((item: string) => {
|
|
|
console.log('langList', langList)
|
|
|
|
|
|
const menus = [
|
|
|
- { label: t('base.personalCenter'), key: 'user' },
|
|
|
- { label: t('base.logout'), key: 'logout' }
|
|
|
+ { label: 'base.personalCenter', key: 'user' },
|
|
|
+ { label: 'base.logout', key: 'logout' }
|
|
|
]
|
|
|
const handlerMenuClick: MenuProps['onClick'] = async e => {
|
|
|
if (e.key === 'logout') {
|
|
@@ -123,15 +126,18 @@ const handlerMenuClick: MenuProps['onClick'] = async e => {
|
|
|
|
|
|
const handlerLangClick: MenuProps['onClick'] = async e => {
|
|
|
console.log(e.key)
|
|
|
- // showLoading()
|
|
|
+ showLoading()
|
|
|
const searchParam = new URLSearchParams(location.search)
|
|
|
searchParam.set('lang', `${e.key}`)
|
|
|
+ const { changeLocale } = useLocale()
|
|
|
+ changeLocale(e.key as LocaleType)
|
|
|
console.log('searchParam', searchParam.toString())
|
|
|
- const replaceUrl = location.origin + location.pathname + '?' + searchParam.toString();
|
|
|
- history.replaceState(null, '', replaceUrl);
|
|
|
+ const replaceUrl =
|
|
|
+ location.origin + location.pathname + '?' + searchParam.toString()
|
|
|
+ history.replaceState(null, '', replaceUrl)
|
|
|
setTimeout(() => {
|
|
|
location.reload()
|
|
|
- }, 1000)
|
|
|
+ }, 300)
|
|
|
}
|
|
|
|
|
|
onMounted(() => {
|
|
@@ -143,16 +149,6 @@ onMounted(() => {
|
|
|
currentLang.value.key = lang
|
|
|
currentLang.value.label = t(`base.lang.${unref(lang)}`)
|
|
|
}
|
|
|
-
|
|
|
- watch(
|
|
|
- () => getLocale,
|
|
|
- () => {
|
|
|
- setCurrentLang(getLocale)
|
|
|
- },
|
|
|
- {
|
|
|
- immediate: true
|
|
|
- }
|
|
|
- )
|
|
|
const lang = browser.getURLParam('lang')
|
|
|
let defaultLang: LocaleType = 'zh'
|
|
|
console.log('lang', lang)
|