| 12345678910111213141516171819202122232425262728293031323334 |
- <script>
- import { hasServerAuth, isLoggedIn } from './utils/storage'
- import { getServerConfig } from './utils/auth'
- function guardLogin() {
- const pages = getCurrentPages()
- const currentRoute = pages[pages.length - 1]?.route || ''
- const onLoginPage = currentRoute === 'pages/login/index'
- const config = getServerConfig()
- if (!isLoggedIn() && !onLoginPage) {
- uni.reLaunch({ url: '/pages/login/index' })
- } else if (isLoggedIn() && onLoginPage) {
- uni.reLaunch({ url: '/pages/home/index' })
- } else if (config.mode === 'server' && !hasServerAuth()) {
- // 服务器模式下没有真实 token(demo token 残留 / 从未登录),强制回登录页
- uni.reLaunch({ url: '/pages/login/index' })
- }
- }
- export default {
- onLaunch() {
- console.log('Aimill HR Mobile launched')
- setTimeout(guardLogin, 0)
- },
- onShow() {
- setTimeout(guardLogin, 0)
- },
- }
- </script>
- <style lang="scss">
- @use './styles/global.scss';
- </style>
|