App.vue 958 B

12345678910111213141516171819202122232425262728293031323334
  1. <script>
  2. import { hasServerAuth, isLoggedIn } from './utils/storage'
  3. import { getServerConfig } from './utils/auth'
  4. function guardLogin() {
  5. const pages = getCurrentPages()
  6. const currentRoute = pages[pages.length - 1]?.route || ''
  7. const onLoginPage = currentRoute === 'pages/login/index'
  8. const config = getServerConfig()
  9. if (!isLoggedIn() && !onLoginPage) {
  10. uni.reLaunch({ url: '/pages/login/index' })
  11. } else if (isLoggedIn() && onLoginPage) {
  12. uni.reLaunch({ url: '/pages/home/index' })
  13. } else if (config.mode === 'server' && !hasServerAuth()) {
  14. // 服务器模式下没有真实 token(demo token 残留 / 从未登录),强制回登录页
  15. uni.reLaunch({ url: '/pages/login/index' })
  16. }
  17. }
  18. export default {
  19. onLaunch() {
  20. console.log('Aimill HR Mobile launched')
  21. setTimeout(guardLogin, 0)
  22. },
  23. onShow() {
  24. setTimeout(guardLogin, 0)
  25. },
  26. }
  27. </script>
  28. <style lang="scss">
  29. @use './styles/global.scss';
  30. </style>