49 lines
1.2 KiB
Vue
49 lines
1.2 KiB
Vue
<script>
|
||
import { isLoggedIn } from './utils/session.js'
|
||
|
||
/** 无需登录即可访问(公开报告链接、登录页) */
|
||
const isPublicRoute = (route) => {
|
||
if (!route) return false
|
||
if (route.includes('pages/login/Login')) return true
|
||
if (route.includes('pages/report-view/reportView')) return true
|
||
return false
|
||
}
|
||
|
||
function scheduleAuthGuard() {
|
||
setTimeout(() => {
|
||
try {
|
||
if (isLoggedIn()) return
|
||
const pages = getCurrentPages()
|
||
if (pages.length === 0) return // 还没加载完页面,默认第一个页面是 login,不需要拦截
|
||
const cur = pages[pages.length - 1]
|
||
const route = cur && cur.route ? cur.route : ''
|
||
if (isPublicRoute(route)) return
|
||
uni.reLaunch({ url: '/pages/login/Login' })
|
||
} catch (_) {
|
||
uni.reLaunch({ url: '/pages/login/Login' })
|
||
}
|
||
}, 50)
|
||
}
|
||
|
||
export default {
|
||
onLaunch() {
|
||
scheduleAuthGuard()
|
||
},
|
||
onShow() {
|
||
scheduleAuthGuard()
|
||
}
|
||
}
|
||
</script>
|
||
|
||
<style>
|
||
@import './assets/global.css';
|
||
page {
|
||
margin: 0;
|
||
padding: 0;
|
||
box-sizing: border-box;
|
||
background: #fafaf8;
|
||
font-family: -apple-system, BlinkMacSystemFont, 'PingFang SC', 'Helvetica Neue', Helvetica, Arial, sans-serif;
|
||
color: #1a1a1a;
|
||
}
|
||
</style>
|