fix: update tab titles when switching language (#17)
parent
a44e3cbc33
commit
c715d68dbb
|
@ -5,10 +5,10 @@ import type {
|
||||||
RouteRecordNormalized,
|
RouteRecordNormalized,
|
||||||
} from 'vue-router';
|
} from 'vue-router';
|
||||||
|
|
||||||
import { computed, watch } from 'vue';
|
import { computed, ref, watch } from 'vue';
|
||||||
import { useRoute, useRouter } from 'vue-router';
|
import { useRoute, useRouter } from 'vue-router';
|
||||||
|
|
||||||
import { $t } from '@vben/locales';
|
import { $t, useI18n } from '@vben/locales';
|
||||||
import {
|
import {
|
||||||
IcRoundClose,
|
IcRoundClose,
|
||||||
IcRoundMultipleStop,
|
IcRoundMultipleStop,
|
||||||
|
@ -33,8 +33,11 @@ function useTabs() {
|
||||||
return route.path;
|
return route.path;
|
||||||
});
|
});
|
||||||
|
|
||||||
const currentTabs = computed(() => {
|
const { locale } = useI18n();
|
||||||
return tabsStore.getTabs;
|
const currentTabs =
|
||||||
|
ref<(RouteLocationNormalized | RouteRecordNormalized)[]>();
|
||||||
|
watch([() => tabsStore.getTabs, () => locale.value], ([tabs, _]) => {
|
||||||
|
currentTabs.value = tabs.map((item) => wrapperTabLocale(item));
|
||||||
});
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -44,9 +47,6 @@ function useTabs() {
|
||||||
const affixTabs = filterTree(router.getRoutes(), (route) => {
|
const affixTabs = filterTree(router.getRoutes(), (route) => {
|
||||||
return !!route.meta?.affixTab;
|
return !!route.meta?.affixTab;
|
||||||
});
|
});
|
||||||
affixTabs.forEach((tab) => {
|
|
||||||
Object.assign(tab, wrapperTabLocale(tab));
|
|
||||||
});
|
|
||||||
tabsStore.setAffixTabs(affixTabs);
|
tabsStore.setAffixTabs(affixTabs);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -83,7 +83,7 @@ function useTabs() {
|
||||||
watch(
|
watch(
|
||||||
() => route.path,
|
() => route.path,
|
||||||
() => {
|
() => {
|
||||||
tabsStore.addTab(wrapperTabLocale(route) as RouteLocationNormalized);
|
tabsStore.addTab(route as RouteLocationNormalized);
|
||||||
},
|
},
|
||||||
{ immediate: true },
|
{ immediate: true },
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in New Issue