diff --git a/.eslintrc.js b/.eslintrc.js index bc2fb2eb..6680c5d5 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -28,7 +28,7 @@ module.exports = { }, // plugins: ['vue'], rules: { - // 'prettier/prettier': 'error', + 'prettier/prettier': 'error', // 是否禁止使用any类型 '@typescript-eslint/no-explicit-any': 'off', // 是否开启函数必须要指定类型 diff --git a/src/hooks/web/useI18n.ts b/src/hooks/web/useI18n.ts index cd75d7ae..787c2ba7 100644 --- a/src/hooks/web/useI18n.ts +++ b/src/hooks/web/useI18n.ts @@ -19,3 +19,19 @@ export const deffElementLocale = () => { return { tolocale }; }; + +// 转换国际化,适用于不在i18n配置的国际化语言 +export function translateI18n(message: any = '') { + if (!message) { + return ''; + } + const locale = i18n.global.locale.value; + if (typeof message === 'object') { + return message[locale]; + } + const key = message.split('.')[0]; + if (key && Object.keys(i18n.global.messages.value[locale]).includes(key)) { + return i18n.global.t(message); + } + return message; +} diff --git a/src/layouts/pageLayouts/components/AppTabs/hooks/useTabsChange.ts b/src/layouts/pageLayouts/components/AppTabs/hooks/useTabsChange.ts index 5d159fb5..a5e0d3c7 100644 --- a/src/layouts/pageLayouts/components/AppTabs/hooks/useTabsChange.ts +++ b/src/layouts/pageLayouts/components/AppTabs/hooks/useTabsChange.ts @@ -25,13 +25,19 @@ export const useTabsChange = (multiTabs: Ref) => { // 关闭标签 const closeTabsRoute = (e: string, type: 'other' | 'left' | 'right') => { - const valueIndex = multiTabs.value.findIndex((i) => i.path === e); + const item = multiTabs.value.findIndex((i) => i.path === e); const mapList = multiTabs.value.filter((i, index) => { if (i.path !== e && type === 'other') return true; - else if (index < valueIndex && type === 'left') return true; - else if (index > valueIndex && type === 'right') return true; + else if (index < item && type === 'left') return true; + else if (index > item && type === 'right') return true; return false; }); + if (mapList.find((i) => i.path === route.path)) { + router.push({ + path: multiTabs.value[item].path, + query: multiTabs.value[item].query, + }); + } mapList.forEach((i) => { usePermissionStoreHook().cacheOperate({ mode: 'delete', @@ -39,27 +45,22 @@ export const useTabsChange = (multiTabs: Ref) => { }); usePermissionStoreHook().handleMultiTabs('delete', i); }); - // console.log(multiTabs.value[valueIndex], valueIndex, multiTabs.value); - // router.push({ - // path: multiTabs.value[valueIndex].path, - // query: multiTabs.value[valueIndex].query, - // }); }; // 关闭当前导航 const removeTab = (e: string) => { - const valueIndex = multiTabs.value.findIndex((i) => setTabPaneKey(i) === e); + const item = multiTabs.value.findIndex((i) => setTabPaneKey(i) === e); const tabsLength = multiTabs.value.length; - if (multiTabs.value[valueIndex].name === route.name) { + if (multiTabs.value[item].name === route.name) { let value, toRoute; - if (valueIndex === tabsLength - 1) { - value = multiTabs.value[valueIndex - 1]; + if (item === tabsLength - 1) { + value = multiTabs.value[item - 1]; toRoute = { path: value.path, query: value.query, }; } else { - console.log(valueIndex, tabsLength, multiTabs.value[valueIndex].name, route.name); + console.log(item, tabsLength, multiTabs.value[item].name, route.name); value = multiTabs.value[tabsLength - 1]; toRoute = { @@ -71,9 +72,9 @@ export const useTabsChange = (multiTabs: Ref) => { } usePermissionStoreHook().cacheOperate({ mode: 'delete', - name: multiTabs.value[valueIndex].name || '', + name: multiTabs.value[item].name || '', }); - usePermissionStoreHook().handleMultiTabs('delete', multiTabs.value[valueIndex]); + usePermissionStoreHook().handleMultiTabs('delete', multiTabs.value[item]); }; // 重新加载 diff --git a/src/layouts/pageLayouts/components/AppTabs/index.vue b/src/layouts/pageLayouts/components/AppTabs/index.vue index 333294b8..5adb73f6 100644 --- a/src/layouts/pageLayouts/components/AppTabs/index.vue +++ b/src/layouts/pageLayouts/components/AppTabs/index.vue @@ -7,19 +7,14 @@ :closable="multiTabs.length > 1" @tab-remove="tabRemoveChange" > - + @@ -67,7 +62,7 @@ diff --git a/src/layouts/pageLayouts/components/Sidebar/hooks/useSelectMenu.ts b/src/layouts/pageLayouts/components/Sidebar/hooks/useSelectMenu.ts index aa2c4903..e43b7fe0 100644 --- a/src/layouts/pageLayouts/components/Sidebar/hooks/useSelectMenu.ts +++ b/src/layouts/pageLayouts/components/Sidebar/hooks/useSelectMenu.ts @@ -6,8 +6,12 @@ export const useSelectMenu = () => { const selectMenu = (path: string) => { const findRoute = findRouteByPath(path, sidebarRouteList); if (findRoute) { + if (findRoute.redirect && findRoute.children && findRoute.children.length) { + selectMenu(findRoute.children[0].path); + return; + } emitter.emit('siteBarChange', { - routeRow: findRoute, + routeRaw: findRoute, }); } }; diff --git a/src/layouts/pageLayouts/components/Sidebar/index.vue b/src/layouts/pageLayouts/components/Sidebar/index.vue index 57524f84..1273757b 100644 --- a/src/layouts/pageLayouts/components/Sidebar/index.vue +++ b/src/layouts/pageLayouts/components/Sidebar/index.vue @@ -48,9 +48,9 @@ }); function getSubMenuData(path: string) { - // path的上级路由组成的数组 + // path的父级路由组成的数组 const parentPathArr = getParentPaths(path, usePermissionStoreHook().wholeMenus); - // 当前路由的父级路由信息 + // 当前路由的信息 const parenetRoute = findRouteByPath(parentPathArr[0], usePermissionStoreHook().wholeMenus); if (parenetRoute) { if (parenetRoute.children) subMenuData.value = parenetRoute.children; diff --git a/src/router/utils.ts b/src/router/utils.ts index bb007fcd..ccfc443e 100644 --- a/src/router/utils.ts +++ b/src/router/utils.ts @@ -7,6 +7,7 @@ import { AppRouteRecordRaw, Menu } from '#/route'; import { sidebarRouteList } from './index'; import { isExternal } from '@/utils/validate'; +// 初始化权限路由 async function initAsyncRoute(power: string) { resetRouter(); const res = await getRouteApi({ name: power }); diff --git a/src/utils/mitt.ts b/src/utils/mitt.ts index 63eb502c..5ceb352f 100644 --- a/src/utils/mitt.ts +++ b/src/utils/mitt.ts @@ -4,7 +4,7 @@ import mitt from 'mitt'; type Events = { siteBarChange: { - routeRow: AppRouteRecordRaw; + routeRaw: AppRouteRecordRaw; }; }; diff --git a/src/views/details-page/index.vue b/src/views/details-page/index.vue index c38c021f..e56753d6 100644 --- a/src/views/details-page/index.vue +++ b/src/views/details-page/index.vue @@ -16,7 +16,7 @@ name: 'RtDetailsInfo', query, meta: { - title: `详情页-${item}`, + title: { 'zh-ch': `详情页-${item}`, en: `pageDatails-${item}` }, }, }); router.push({ name: 'RtDetailsInfo', query });