AutoLogin.vue 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <script setup>
  2. import {apiSystemCommon} from '@/api/system'
  3. import { useRoute, useRouter } from 'vue-router'
  4. const route=useRoute()
  5. const router=useRouter()
  6. // 获取有菜单跳转
  7. async function handleNavigation(){
  8. const res=await apiSystemCommon.menuList()
  9. if(res.Ret!==200) return
  10. const arr=res.Data.List||[]
  11. if(arr.length===0){
  12. MessagePlugin.warning('无任何菜单权限,请联系管理员')
  13. return
  14. }
  15. const path=arr[0].children[0].path
  16. router.replace(path)
  17. }
  18. function init(){
  19. const code=route.query.code
  20. if(!code) return
  21. apiSystemCommon.loginWithCode({
  22. AuthCode:code
  23. }).then(res=>{
  24. if(res.Ret===200){
  25. sessionStorage.setItem('token',res.Data.Authorization)
  26. sessionStorage.setItem('userInfo',JSON.stringify(res.Data))
  27. sessionStorage.setItem('Role',res.Data.RoleTypeCode)
  28. handleNavigation()
  29. }
  30. })
  31. }
  32. init()
  33. </script>
  34. <template>
  35. <div class="auto-login-page">
  36. 登录中...
  37. </div>
  38. </template>
  39. <style lang="scss" scoped>
  40. .auto-login-page{
  41. width: 100%;
  42. height: 100%;
  43. display: flex;
  44. align-items: center;
  45. justify-content: center;
  46. }
  47. </style>