index.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. import {createRouter, createWebHashHistory} from "vue-router";
  2. import {useLoginStore} from "@/pinia/login";
  3. export const router= createRouter({
  4. history:createWebHashHistory(),
  5. routes:[
  6. {
  7. path:'',
  8. redirect:'/login'
  9. },
  10. {
  11. path:'/LoginedPage',
  12. component:() => import('../views/LoginedPage/LoginedPage.vue'),
  13. children:[
  14. {path:'/LoginedPage',redirect:'/DataMiddleGroundHome'},
  15. {
  16. path:'/DataMiddleGroundHome',
  17. component:() => import('../views/DataMiddleGroundHome/DataMiddleGroundHome.vue')
  18. },
  19. ]
  20. },
  21. {path:'/login',name:'login',component:() => import('../views/login/login.vue')},
  22. ]
  23. })
  24. router.beforeEach((to,from) => {
  25. console.log('变化; ',to.path,from,localStorage.getItem('userInfoPsdOrUserNameMiddle'))
  26. let userInfo = localStorage.getItem('userInfoPsdOrUserNameMiddle')
  27. if ( to.path !== '/login' && !userInfo){
  28. return ('/login')
  29. }else if ( to.path === '/login' && userInfo){
  30. // 退出
  31. localStorage.removeItem('userInfoPsdOrUserNameMiddle')
  32. localStorage.removeItem('canSeeSystemArr')
  33. const store = useLoginStore()
  34. store.canSeeSystemArr = []
  35. store.loginInfo = {}
  36. }
  37. })