fix: 静态路由菜单国际化/切换刷新
This commit is contained in:
@@ -16,6 +16,7 @@ export default function useLocale() {
|
|||||||
const changeLocale = (value: string) => {
|
const changeLocale = (value: string) => {
|
||||||
i18n.locale.value = value;
|
i18n.locale.value = value;
|
||||||
localSet(CACHE_LOCAL_I18N, value);
|
localSet(CACHE_LOCAL_I18N, value);
|
||||||
|
window.location.reload()
|
||||||
};
|
};
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|||||||
@@ -121,6 +121,16 @@ export default {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// 静态路由
|
||||||
|
router: {
|
||||||
|
index: "Home",
|
||||||
|
account: {
|
||||||
|
index: "Personal Center",
|
||||||
|
profile: "Personal Info",
|
||||||
|
settings: "Personal Settings",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
// 校验
|
// 校验
|
||||||
valid: {
|
valid: {
|
||||||
userNameReg: 'The account cannot start with a number and can contain uppercase and lowercase letters, numbers, and no less than 5 digits.',
|
userNameReg: 'The account cannot start with a number and can contain uppercase and lowercase letters, numbers, and no less than 5 digits.',
|
||||||
|
|||||||
@@ -121,6 +121,16 @@ export default {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// 静态路由
|
||||||
|
router: {
|
||||||
|
index: "Home",
|
||||||
|
account: {
|
||||||
|
index: "个人中心",
|
||||||
|
profile: "个人信息",
|
||||||
|
settings: "个人设置",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
// 校验
|
// 校验
|
||||||
valid: {
|
valid: {
|
||||||
userNameReg: '账号不能以数字开头,可包含大写小写字母,数字,且不少于5位',
|
userNameReg: '账号不能以数字开头,可包含大写小写字母,数字,且不少于5位',
|
||||||
|
|||||||
@@ -85,7 +85,7 @@ const breadcrumb = computed(() => {
|
|||||||
.map(item => {
|
.map(item => {
|
||||||
return {
|
return {
|
||||||
path: item.path,
|
path: item.path,
|
||||||
breadcrumbName: item.meta.title || '-',
|
breadcrumbName: fnLocale(item.meta.title || '-'),
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -120,6 +120,16 @@ function fnComponentSetName(component: any, to: any) {
|
|||||||
// 清空导航栏标签
|
// 清空导航栏标签
|
||||||
tabsStore.clear();
|
tabsStore.clear();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 国际化翻译转换
|
||||||
|
*/
|
||||||
|
function fnLocale(title: string) {
|
||||||
|
if (title.indexOf('router.') !== -1) {
|
||||||
|
title = t(title);
|
||||||
|
}
|
||||||
|
return title;
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
// fnGetServerTime();
|
// fnGetServerTime();
|
||||||
@@ -186,6 +196,7 @@ document.addEventListener('visibilitychange', function () {
|
|||||||
v-bind="proConfig"
|
v-bind="proConfig"
|
||||||
:iconfont-url="scriptUrl"
|
:iconfont-url="scriptUrl"
|
||||||
:sider-width="208"
|
:sider-width="208"
|
||||||
|
:locale="(fnLocale as any)"
|
||||||
>
|
>
|
||||||
<!--插槽-菜单头-->
|
<!--插槽-菜单头-->
|
||||||
<template #menuHeaderRender>
|
<template #menuHeaderRender>
|
||||||
|
|||||||
@@ -92,6 +92,16 @@ function fnTabClose(path: string) {
|
|||||||
router.push(to);
|
router.push(to);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 国际化翻译转换
|
||||||
|
*/
|
||||||
|
function fnLocale(title: string) {
|
||||||
|
if (title.indexOf('router.') !== -1) {
|
||||||
|
title = t(title);
|
||||||
|
}
|
||||||
|
return title;
|
||||||
|
}
|
||||||
|
|
||||||
/**监听当前路由添加到导航标签列表 */
|
/**监听当前路由添加到导航标签列表 */
|
||||||
watch(router.currentRoute, v => tabsStore.tabOpen(v), { immediate: true });
|
watch(router.currentRoute, v => tabsStore.tabOpen(v), { immediate: true });
|
||||||
</script>
|
</script>
|
||||||
@@ -120,7 +130,7 @@ watch(router.currentRoute, v => tabsStore.tabOpen(v), { immediate: true });
|
|||||||
<template #tab>
|
<template #tab>
|
||||||
<span>
|
<span>
|
||||||
<IconFont :type="tab.icon" style="margin: 0"></IconFont>
|
<IconFont :type="tab.icon" style="margin: 0"></IconFont>
|
||||||
{{ tab.title }}
|
{{ fnLocale(tab.title) }}
|
||||||
</span>
|
</span>
|
||||||
</template>
|
</template>
|
||||||
</a-tab-pane>
|
</a-tab-pane>
|
||||||
|
|||||||
@@ -28,21 +28,20 @@ const constantRoutes: RouteRecordRaw[] = [
|
|||||||
{
|
{
|
||||||
path: '/',
|
path: '/',
|
||||||
name: 'Root',
|
name: 'Root',
|
||||||
meta: { title: '根节点' },
|
|
||||||
component: BasicLayout,
|
component: BasicLayout,
|
||||||
redirect: '/index',
|
redirect: '/index',
|
||||||
children: [
|
children: [
|
||||||
{
|
{
|
||||||
path: '/index',
|
path: '/index',
|
||||||
name: 'Index',
|
name: 'Index',
|
||||||
meta: { title: '首页', icon: 'icon-pcduan' },
|
meta: { title: 'router.index', icon: 'icon-pcduan' },
|
||||||
component: () => import('@/views/index.vue'),
|
component: () => import('@/views/index.vue'),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: '/account',
|
path: '/account',
|
||||||
name: 'Account',
|
name: 'Account',
|
||||||
meta: {
|
meta: {
|
||||||
title: '个人中心',
|
title: 'router.account.index',
|
||||||
hideInMenu: true,
|
hideInMenu: true,
|
||||||
},
|
},
|
||||||
component: BlankLayout,
|
component: BlankLayout,
|
||||||
@@ -51,13 +50,13 @@ const constantRoutes: RouteRecordRaw[] = [
|
|||||||
{
|
{
|
||||||
path: 'profile',
|
path: 'profile',
|
||||||
name: 'Profile',
|
name: 'Profile',
|
||||||
meta: { title: '个人信息', cache: true },
|
meta: { title: 'router.account.profile', cache: true },
|
||||||
component: () => import('@/views/account/profile.vue'),
|
component: () => import('@/views/account/profile.vue'),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: 'settings',
|
path: 'settings',
|
||||||
name: 'Settings',
|
name: 'Settings',
|
||||||
meta: { title: '个人设置', cache: true },
|
meta: { title: 'router.account.settings', cache: true },
|
||||||
component: () => import('@/views/account/settings.vue'),
|
component: () => import('@/views/account/settings.vue'),
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
@@ -67,25 +66,21 @@ const constantRoutes: RouteRecordRaw[] = [
|
|||||||
{
|
{
|
||||||
path: '/login',
|
path: '/login',
|
||||||
name: 'Login',
|
name: 'Login',
|
||||||
meta: { title: '登录' },
|
|
||||||
component: () => import('@/views/login.vue'),
|
component: () => import('@/views/login.vue'),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: '/register',
|
path: '/register',
|
||||||
name: 'Register',
|
name: 'Register',
|
||||||
meta: { title: '注册' },
|
|
||||||
component: () => import('@/views/register.vue'),
|
component: () => import('@/views/register.vue'),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: '/403',
|
path: '/403',
|
||||||
name: 'NotPermission',
|
name: 'NotPermission',
|
||||||
meta: { title: '没有访问权限' },
|
|
||||||
component: () => import('@/views/error/403.vue'),
|
component: () => import('@/views/error/403.vue'),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: '/redirect',
|
path: '/redirect',
|
||||||
name: 'Redirect',
|
name: 'Redirect',
|
||||||
meta: { title: '重定向' },
|
|
||||||
component: BasicLayout,
|
component: BasicLayout,
|
||||||
children: [
|
children: [
|
||||||
{
|
{
|
||||||
@@ -96,7 +91,6 @@ const constantRoutes: RouteRecordRaw[] = [
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: '/:pathMatch(.*)*',
|
path: '/:pathMatch(.*)*',
|
||||||
meta: { title: '找不到匹配页面' },
|
|
||||||
component: () => import('@/views/error/404.vue'),
|
component: () => import('@/views/error/404.vue'),
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|||||||
Reference in New Issue
Block a user