西藏巴青项目

index.js 741B

12345678910111213141516171819202122232425262728
  1. import { getToken } from '@/utils/auth'
  2. import { useUserStore } from '@/store/user'
  3. /**
  4. * 应用启动:若有 Token 则静默拉取用户信息(roles/permissions 供接口侧 checkPermi 使用)
  5. * 不做页面跳转拦截,页面可自由浏览
  6. */
  7. export function syncUserOnLaunch() {
  8. if (!getToken()) {
  9. return Promise.resolve()
  10. }
  11. const userStore = useUserStore()
  12. if (userStore.state.roles.length) {
  13. return Promise.resolve()
  14. }
  15. return userStore.fetchUserInfo().catch(() => {
  16. userStore.fedLogOut()
  17. })
  18. }
  19. /** @deprecated 仅保留兼容,已无路由守卫 */
  20. export function initRouteGuard() {}
  21. /** @deprecated 请使用 syncUserOnLaunch */
  22. export function bootstrapAuth() {
  23. return syncUserOnLaunch()
  24. }