123456789101112131415161718192021222324252627282930313233343536373839404142 |
- import {createRouter, createWebHashHistory} from "vue-router";
- import {useLoginStore} from "@/pinia/login";
- export const router= createRouter({
- history:createWebHashHistory(),
- routes:[
- {
- path:'',
- redirect:'/login'
- },
- {
- path:'/LoginedPage',
- component:() => import('../views/LoginedPage/LoginedPage.vue'),
- children:[
- {path:'/LoginedPage',redirect:'/DataMiddleGroundHome'},
- {
- path:'/DataMiddleGroundHome',
- component:() => import('../views/DataMiddleGroundHome/DataMiddleGroundHome.vue')
- },
- ]
- },
- {path:'/login',name:'login',component:() => import('../views/login/login.vue')},
- ]
- })
- router.beforeEach((to,from) => {
- console.log('变化; ',to.path,from,localStorage.getItem('userInfoPsdOrUserNameMiddle'))
- let userInfo = localStorage.getItem('userInfoPsdOrUserNameMiddle')
- if ( to.path !== '/login' && !userInfo){
- return ('/login')
- }else if ( to.path === '/login' && userInfo){
- // 退出
- localStorage.removeItem('userInfoPsdOrUserNameMiddle')
- localStorage.removeItem('canSeeSystemArr')
- const store = useLoginStore()
- store.canSeeSystemArr = []
- store.loginInfo = {}
- }
- })
|