petstore-frontend/src/App.vue

49 lines
1.2 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<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>