fix 路由相关问题
This commit is contained in:
parent
87b8bd47dc
commit
aaf85ccf22
@ -4,8 +4,10 @@
|
|||||||
<Logo v-if="setIsShowLogo" />
|
<Logo v-if="setIsShowLogo" />
|
||||||
<Breadcrumb />
|
<Breadcrumb />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<Horizontal :menuList="state.menuList" />
|
||||||
<div class="right-section">
|
<div class="right-section">
|
||||||
<ModuleSwitch :menuList="state.menuList" />
|
<!-- <module-switch :menuList="state.menuList" /> -->
|
||||||
<User />
|
<User />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -21,7 +23,6 @@ import mittBus from '/@/utils/mitt'
|
|||||||
import ModuleSwitch from './module-switch.vue'
|
import ModuleSwitch from './module-switch.vue'
|
||||||
|
|
||||||
// 引入组件
|
// 引入组件
|
||||||
const Breadcrumb = defineAsyncComponent(() => import('/@/layout/navBars/topBar/breadcrumb.vue'))
|
|
||||||
const User = defineAsyncComponent(() => import('/@/layout/navBars/topBar/user.vue'))
|
const User = defineAsyncComponent(() => import('/@/layout/navBars/topBar/user.vue'))
|
||||||
const Logo = defineAsyncComponent(() => import('/@/layout/logo/index.vue'))
|
const Logo = defineAsyncComponent(() => import('/@/layout/logo/index.vue'))
|
||||||
const Horizontal = defineAsyncComponent(() => import('/@/layout/navMenu/horizontal.vue'))
|
const Horizontal = defineAsyncComponent(() => import('/@/layout/navMenu/horizontal.vue'))
|
||||||
@ -138,6 +139,7 @@ onBeforeMount(() => {
|
|||||||
mittBus.emit('setSendClassicChildren', route.path)
|
mittBus.emit('setSendClassicChildren', route.path)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style scoped lang="scss">
|
<style scoped lang="scss">
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
<el-dropdown :show-timeout="70" :hide-timeout="50" trigger="click" @command="onMenuChange">
|
<el-dropdown :show-timeout="70" :hide-timeout="50" trigger="click" @command="onMenuChange">
|
||||||
<div class="layout-navbars-breadcrumb-user-icon">
|
<div class="layout-navbars-breadcrumb-user-icon">
|
||||||
<i class="iconfont icon-diqiu" :title="$t('message.user.title1')"></i>
|
<i class="iconfont icon-diqiu" :title="$t('message.user.title1')"></i>
|
||||||
<span class="current-lang">{{ currentModuleName }}</span>
|
<span class="current-lang">{{ state.currentModuleName }}</span>
|
||||||
</div>
|
</div>
|
||||||
<template #dropdown>
|
<template #dropdown>
|
||||||
<el-dropdown-menu>
|
<el-dropdown-menu>
|
||||||
@ -27,7 +27,6 @@ import { treeToList, listToTree, filterList } from '/@/utils/tree'
|
|||||||
import { cloneDeep } from 'lodash-es'
|
import { cloneDeep } from 'lodash-es'
|
||||||
import { useI18n } from 'vue-i18n'
|
import { useI18n } from 'vue-i18n'
|
||||||
const { t } = useI18n()
|
const { t } = useI18n()
|
||||||
|
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
|
|
||||||
// 引入组件
|
// 引入组件
|
||||||
@ -58,10 +57,6 @@ const menuLists = computed(() => {
|
|||||||
return <RouteItems>props.menuList
|
return <RouteItems>props.menuList
|
||||||
})
|
})
|
||||||
|
|
||||||
const onMenuChange = (path: string) => {
|
|
||||||
console.log('path', path)
|
|
||||||
}
|
|
||||||
|
|
||||||
// 路由过滤递归函数
|
// 路由过滤递归函数
|
||||||
const filterRoutesFun = <T extends RouteItem>(arr: T[]): T[] => {
|
const filterRoutesFun = <T extends RouteItem>(arr: T[]): T[] => {
|
||||||
return arr
|
return arr
|
||||||
@ -108,13 +103,11 @@ const setSendClassicChildren = (path: string) => {
|
|||||||
}
|
}
|
||||||
// 设置页面当前路由高亮
|
// 设置页面当前路由高亮
|
||||||
const setCurrentRouterHighlight = (currentRoute: RouteToFrom) => {
|
const setCurrentRouterHighlight = (currentRoute: RouteToFrom) => {
|
||||||
console.log('currentRoute', currentRoute)
|
|
||||||
const { path, meta } = currentRoute
|
const { path, meta } = currentRoute
|
||||||
|
|
||||||
if (themeConfig.value.layout === 'classic') {
|
if (themeConfig.value.layout === 'classic') {
|
||||||
let rootPath = getRootPath(path || '')
|
let rootPath = getRootPath(path || '')
|
||||||
rootPath = rootPath || path || ''
|
rootPath = rootPath || path || ''
|
||||||
setCurrentModuleName(`/${rootPath?.split('/')[1]}` || '')
|
|
||||||
state.defaultActive = `/${rootPath?.split('/')[1]}`
|
state.defaultActive = `/${rootPath?.split('/')[1]}`
|
||||||
if (!state.defaultActive || state.defaultActive === '/') router.push(routesList.value[0].path)
|
if (!state.defaultActive || state.defaultActive === '/') router.push(routesList.value[0].path)
|
||||||
} else {
|
} else {
|
||||||
@ -124,13 +117,30 @@ const setCurrentRouterHighlight = (currentRoute: RouteToFrom) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const onMenuChange = (path: string) => {
|
||||||
|
console.log('path', path)
|
||||||
|
let to = menuLists.value.find(item => item.path === path)
|
||||||
|
state.currentModuleName = t(to.meta?.title || '未命名模块')
|
||||||
|
setCurrentRouterHighlight(to)
|
||||||
|
let { layout } = themeConfig.value
|
||||||
|
if (layout === 'classic') {
|
||||||
|
mittBus.emit('setSendClassicChildren', setSendClassicChildren(to.path))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 页面加载前
|
// 页面加载前
|
||||||
onBeforeMount(() => {
|
onBeforeMount(() => {
|
||||||
setCurrentRouterHighlight(route)
|
setCurrentRouterHighlight(route)
|
||||||
|
state.currentModuleName = t(route.meta?.title || '未命名模块')
|
||||||
|
let { layout } = themeConfig.value
|
||||||
|
if (layout === 'classic') {
|
||||||
|
mittBus.emit('setSendClassicChildren', setSendClassicChildren(route.path))
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
// 路由更新时
|
// 路由更新时
|
||||||
onBeforeRouteUpdate((to) => {
|
onBeforeRouteUpdate((to) => {
|
||||||
|
state.currentModuleName = t(to.meta?.title || '未命名模块')
|
||||||
// 修复:https://gitee.com/lyt-top/vue-next-admin/issues/I3YX6G
|
// 修复:https://gitee.com/lyt-top/vue-next-admin/issues/I3YX6G
|
||||||
setCurrentRouterHighlight(to)
|
setCurrentRouterHighlight(to)
|
||||||
// 修复经典布局开启切割菜单时,点击tagsView后左侧导航菜单数据不变的问题
|
// 修复经典布局开启切割菜单时,点击tagsView后左侧导航菜单数据不变的问题
|
||||||
|
@ -112,8 +112,7 @@ router.beforeEach(async (to, from, next) => {
|
|||||||
Session.clear()
|
Session.clear()
|
||||||
NProgress.done()
|
NProgress.done()
|
||||||
} else if (token && to.path === '/login') {
|
} else if (token && to.path === '/login') {
|
||||||
console.log('🔄 [路由守卫] 已登录用户访问登录页面,重定向到系统入口页面')
|
next('/')
|
||||||
next('/system-entrance')
|
|
||||||
NProgress.done()
|
NProgress.done()
|
||||||
} else {
|
} else {
|
||||||
const storesRoute = useRoute(pinia)
|
const storesRoute = useRoute(pinia)
|
||||||
|
@ -238,7 +238,7 @@ const signInSuccess = (isNoPower: boolean | undefined) => {
|
|||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
console.log('🚀 [登录成功] 无redirect参数或redirect是首页,跳转到系统入口页面: /system-entrance')
|
console.log('🚀 [登录成功] 无redirect参数或redirect是首页,跳转到系统入口页面: /system-entrance')
|
||||||
router.push('/system-entrance')
|
router.push('/')
|
||||||
}
|
}
|
||||||
// 登录成功提示
|
// 登录成功提示
|
||||||
const signInText = t('message.signInText')
|
const signInText = t('message.signInText')
|
||||||
|
@ -143,7 +143,7 @@ const signInSuccess = (isNoPower: boolean | undefined) => {
|
|||||||
query: Object.keys(<string>route.query?.params).length > 0 ? JSON.parse(<string>route.query?.params) : '',
|
query: Object.keys(<string>route.query?.params).length > 0 ? JSON.parse(<string>route.query?.params) : '',
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
router.push('/system-entrance')
|
router.push('/')
|
||||||
}
|
}
|
||||||
// 登录成功提示
|
// 登录成功提示
|
||||||
const signInText = t('message.signInText')
|
const signInText = t('message.signInText')
|
||||||
|
@ -128,7 +128,7 @@ const signInSuccess = (isNoPower: boolean | undefined) => {
|
|||||||
query: Object.keys(<string>route.query?.params).length > 0 ? JSON.parse(<string>route.query?.params) : '',
|
query: Object.keys(<string>route.query?.params).length > 0 ? JSON.parse(<string>route.query?.params) : '',
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
router.push('/system-entrance')
|
router.push('/')
|
||||||
}
|
}
|
||||||
// 登录成功提示
|
// 登录成功提示
|
||||||
const signInText = t('message.signInText')
|
const signInText = t('message.signInText')
|
||||||
|
Loading…
x
Reference in New Issue
Block a user