useMenu.ts 948 Bytes
import router from '@/router'
import useSettingsStore from '@/store/modules/settings'
import useMenuStore from '@/store/modules/menu'
import useUserStore from '@/store/modules/user'

export default function useMenu() {
  const settingsStore = useSettingsStore()
  const menuStore = useMenuStore()
  const userStore = useUserStore()

  function switchTo(index: number | string) {
    menuStore.setActived(index)
    if (settingsStore.settings.menu.switchMainMenuAndPageJump) {
      if (menuStore.sidebarMenusFirstDeepestPath !== '/') {
        const combPath = menuStore.sidebarMenusFirstDeepestPath.split('/')[1]
        if (userStore.tabbarMap[combPath].activePath) {
          router.push(userStore.tabbarMap[combPath].activePath)
        } else {
          router.push(menuStore.sidebarMenusFirstDeepestPath)
        }
      } else {
        router.push(menuStore.sidebarMenusFirstDeepestPath)
      }
    }
  }

  return {
    switchTo,
  }
}