优化topNav打开菜单

This commit is contained in:
不做码农 2023-02-09 11:49:08 +08:00
parent 5ce9ec92b1
commit 6d9b76e5b1

View File

@ -43,10 +43,10 @@ import usePermissionStore from '@/store/modules/permission'
//
const visibleNumber = ref(5)
//
const isFrist = ref(false)
// index
const currentIndex = ref(undefined)
//
const hideList = ['/index', '/user/profile']
const appStore = useAppStore()
const settingsStore = useSettingsStore()
@ -82,10 +82,10 @@ const childrenMenus = computed(() => {
for (let item in router.children) {
if (router.children[item].parentPath === undefined) {
if (router.path === '/') {
router.children[item].path = getNormalPath('/redirect/' + router.children[item].path)
router.children[item].path = '/' + router.children[item].path
} else {
if (!isHttp(router.children[item].path)) {
router.children[item].path = getNormalPath(router.path + '/' + router.children[item].path)
router.children[item].path = router.path + '/' + router.children[item].path
}
}
router.children[item].parentPath = router.path
@ -99,52 +99,39 @@ const childrenMenus = computed(() => {
//
const activeMenu = computed(() => {
const path = route.path
let activePath = defaultRouter.value
if (path.lastIndexOf('/') > 0) {
let activePath = path
if (path !== undefined && path.lastIndexOf('/') > 0 && hideList.indexOf(path) === -1) {
const tmpPath = path.substring(1, path.length)
activePath = '/' + tmpPath.substring(0, tmpPath.indexOf('/'))
} else if ('/index' == path || '' == path) {
if (!isFrist.value) {
isFrist.value = true
} else {
activePath = 'index'
if (!route.meta.link) {
appStore.toggleSideBarHide(false)
}
} else if (!route.children) {
activePath = path
appStore.toggleSideBarHide(true)
}
let routes = activeRoutes(activePath)
if (routes.length === 0) {
activePath = currentIndex.value || defaultRouter.value
activeRoutes(activePath)
}
activeRoutes(activePath)
return activePath
})
//
const defaultRouter = computed(() => {
let router
Object.keys(routers.value).some((key) => {
if (!routers.value[key].hidden) {
router = routers.value[key].path
return true
}
})
return router
})
function setVisibleNumber() {
const width = document.body.getBoundingClientRect().width / 3
visibleNumber.value = parseInt(width / 85)
}
function handleSelect(key, keyPath) {
currentIndex.value = key
const route = routers.value.find((item) => item.path === key)
if (isHttp(key)) {
// http(s)://
window.open(key, '_blank')
} else if (key.indexOf('/redirect') !== -1) {
// /redirect
router.push({ path: key.replace('/redirect', '') }).catch((err) => {})
} else if (!route || !route.children) {
//
router.push({ path: key })
appStore.toggleSideBarHide(true)
} else {
//
activeRoutes(key)
appStore.toggleSideBarHide(false)
}
}
//
@ -159,6 +146,8 @@ function activeRoutes(key) {
}
if (routes.length > 0) {
permissionStore.setSidebarRouters(routes)
} else {
// appStore.toggleSideBarHide(true)
}
return routes
}