|
@@ -67,39 +67,36 @@ const menuList = [
|
|
|
}
|
|
}
|
|
|
]
|
|
]
|
|
|
|
|
|
|
|
-const activeMenu = ref()
|
|
|
|
|
-activeMenu.value = (route.meta?.activeMenu as string) || route.path
|
|
|
|
|
-// console.log('activeMenu', activeMenu.value)
|
|
|
|
|
|
|
+//监听窗口大小
|
|
|
|
|
+const handler = () => {
|
|
|
|
|
+ return (() => {
|
|
|
|
|
+ let screenWidth = document.body.clientWidth
|
|
|
|
|
+ let screenHeight = document.body.clientHeight
|
|
|
|
|
+ if (screenWidth < 1400) {
|
|
|
|
|
+ isCollapse.value = true
|
|
|
|
|
+ } else {
|
|
|
|
|
+ isCollapse.value = false
|
|
|
|
|
+ }
|
|
|
|
|
+ })()
|
|
|
|
|
+}
|
|
|
|
|
+const listeningWindow = () => {
|
|
|
|
|
+ window.addEventListener('resize', handler)
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+const unListeningWindow = () => {
|
|
|
|
|
+ window.removeEventListener('resize', handler)
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+watchEffect(() => {
|
|
|
|
|
+ listeningWindow()
|
|
|
|
|
+})
|
|
|
|
|
|
|
|
-// // 未登录白名单
|
|
|
|
|
-// const whiteList = ['/login', '/public-tracking', '/public-tracking/detail']
|
|
|
|
|
-// // 判断是否允许跳转
|
|
|
|
|
-// const isAllowJump = (path: string) => {
|
|
|
|
|
-// // 判断是否登录
|
|
|
|
|
-// if (!whiteList.includes(path) && !localStorage.getItem('token')) {
|
|
|
|
|
-// if (whiteList.includes(route.path)) {
|
|
|
|
|
-// ElMessage.warning('Please log in to use this feature.')
|
|
|
|
|
-// console.log('跳转')
|
|
|
|
|
-// activeMenu.value = (route.meta?.activeMenu as string) || route.path
|
|
|
|
|
-// return false
|
|
|
|
|
-// } else {
|
|
|
|
|
-// ElMessage.warning('Please log in to use this feature.')
|
|
|
|
|
-// return '/public-tracking'
|
|
|
|
|
-// }
|
|
|
|
|
-// } else {
|
|
|
|
|
-// return path
|
|
|
|
|
-// }
|
|
|
|
|
-// }
|
|
|
|
|
|
|
+onUnmounted(() => {
|
|
|
|
|
+ unListeningWindow()
|
|
|
|
|
+})
|
|
|
|
|
|
|
|
-// const changeRouter = (path: string) => {
|
|
|
|
|
-// let toPath = path
|
|
|
|
|
-// if (path === '/tracking' && !localStorage.getItem('token')) {
|
|
|
|
|
-// toPath = '/public-tracking'
|
|
|
|
|
-// }
|
|
|
|
|
-// if (isAllowJump(toPath)) {
|
|
|
|
|
-// router.push(isAllowJump(toPath))
|
|
|
|
|
-// }
|
|
|
|
|
-// }
|
|
|
|
|
|
|
+const activeMenu = ref()
|
|
|
|
|
+activeMenu.value = (route.meta?.activeMenu as string) || route.path
|
|
|
|
|
|
|
|
const getAllMenuPaths = (menuList: any) => {
|
|
const getAllMenuPaths = (menuList: any) => {
|
|
|
let paths: any = []
|
|
let paths: any = []
|
|
@@ -129,8 +126,7 @@ const isAllowJump = (path: any) => {
|
|
|
return true
|
|
return true
|
|
|
}
|
|
}
|
|
|
// 路由后置守卫
|
|
// 路由后置守卫
|
|
|
-router.afterEach((to, from) => {
|
|
|
|
|
- console.log('路由后置')
|
|
|
|
|
|
|
+router.afterEach(() => {
|
|
|
activeMenu.value = (route.meta?.activeMenu as string) || route.path
|
|
activeMenu.value = (route.meta?.activeMenu as string) || route.path
|
|
|
})
|
|
})
|
|
|
|
|
|
|
@@ -144,9 +140,6 @@ const changeRouter = (path: any) => {
|
|
|
// 如果允许跳转,执行跳转
|
|
// 如果允许跳转,执行跳转
|
|
|
if (isAllowJump(toPath)) {
|
|
if (isAllowJump(toPath)) {
|
|
|
router.push(toPath)
|
|
router.push(toPath)
|
|
|
- console.log('允许跳转')
|
|
|
|
|
-
|
|
|
|
|
- console.log('nextTick', activeMenu.value)
|
|
|
|
|
} else {
|
|
} else {
|
|
|
// 如果不允许跳转,保持当前 activeMenu 不变
|
|
// 如果不允许跳转,保持当前 activeMenu 不变
|
|
|
nextTick(() => {
|
|
nextTick(() => {
|
|
@@ -155,22 +148,13 @@ const changeRouter = (path: any) => {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-// 计算属性,返回当前菜单项
|
|
|
|
|
-const computedActiveMenu = computed(() =>
|
|
|
|
|
- menuPaths.includes(activeMenu.value) ? activeMenu.value : ''
|
|
|
|
|
-)
|
|
|
|
|
-
|
|
|
|
|
const handleCollapseClick = () => {
|
|
const handleCollapseClick = () => {
|
|
|
isCollapse.value = !isCollapse.value
|
|
isCollapse.value = !isCollapse.value
|
|
|
}
|
|
}
|
|
|
const menuRef = ref()
|
|
const menuRef = ref()
|
|
|
-const test = () => {
|
|
|
|
|
- console.log('test', activeMenu.value)
|
|
|
|
|
-}
|
|
|
|
|
</script>
|
|
</script>
|
|
|
|
|
|
|
|
<template>
|
|
<template>
|
|
|
- <el-button @click="test">测试</el-button>
|
|
|
|
|
<el-menu
|
|
<el-menu
|
|
|
ref="menuRef"
|
|
ref="menuRef"
|
|
|
class="layout-menu"
|
|
class="layout-menu"
|
|
@@ -179,7 +163,11 @@ const test = () => {
|
|
|
:collapse="isCollapse"
|
|
:collapse="isCollapse"
|
|
|
>
|
|
>
|
|
|
<template v-for="item in menuList" :key="item.index">
|
|
<template v-for="item in menuList" :key="item.index">
|
|
|
- <el-menu-item v-if="item.type !== 'list'" :index="item.path">
|
|
|
|
|
|
|
+ <el-menu-item
|
|
|
|
|
+ :class="{ 'clear-active-style': route.path === '/login' }"
|
|
|
|
|
+ v-if="item.type !== 'list'"
|
|
|
|
|
+ :index="item.path"
|
|
|
|
|
+ >
|
|
|
<span class="font_family" :class="[`icon-${item.icon}`]"></span>
|
|
<span class="font_family" :class="[`icon-${item.icon}`]"></span>
|
|
|
<template #title>{{ item.label }}</template>
|
|
<template #title>{{ item.label }}</template>
|
|
|
</el-menu-item>
|
|
</el-menu-item>
|
|
@@ -246,6 +234,11 @@ const test = () => {
|
|
|
padding-left: 8px;
|
|
padding-left: 8px;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+li.clear-active-style {
|
|
|
|
|
+ background-color: transparent !important;
|
|
|
|
|
+ color: var(--color-neutral-1) !important;
|
|
|
|
|
+ font-weight: normal !important;
|
|
|
|
|
+}
|
|
|
|
|
|
|
|
:deep(.el-sub-menu__title) {
|
|
:deep(.el-sub-menu__title) {
|
|
|
height: 40px;
|
|
height: 40px;
|