西藏巴青项目

index.js 887B

1234567891011121314151617181920212223242526272829303132333435
  1. import { getToken } from '@/utils/auth'
  2. import { useUserStore } from '@/store/user'
  3. import { PARTNER_ROLE_DENIED_MSG } from '@/utils/partnerRole'
  4. /**
  5. * 应用启动:若有 Token 则拉取用户信息;非供应商/承销商则清登录态
  6. */
  7. export function syncUserOnLaunch() {
  8. if (!getToken()) {
  9. return Promise.resolve()
  10. }
  11. const userStore = useUserStore()
  12. if (userStore.isLoggedIn()) {
  13. return Promise.resolve()
  14. }
  15. return userStore.fetchUserInfo().catch((err) => {
  16. userStore.fedLogOut()
  17. if (err && err.message === PARTNER_ROLE_DENIED_MSG) {
  18. uni.showToast({
  19. title: PARTNER_ROLE_DENIED_MSG,
  20. icon: 'none',
  21. duration: 2500
  22. })
  23. }
  24. })
  25. }
  26. /** @deprecated 仅保留兼容 */
  27. export function initRouteGuard() {}
  28. /** @deprecated 请使用 syncUserOnLaunch */
  29. export function bootstrapAuth() {
  30. return syncUserOnLaunch()
  31. }