93 lines
1.9 KiB
Vue
93 lines
1.9 KiB
Vue
<script>
|
|
import { getBaseURL } from '@/api/request.js'
|
|
import { isLoggedIn } from '@/utils/auth.js'
|
|
import { getGuestToken } from '@/utils/guest.js'
|
|
|
|
const LOGIN_PAGE = '/pages/login/login'
|
|
const PUBLIC_ROUTES = [
|
|
'pages/nav/nav',
|
|
'pages/login/login',
|
|
'pages/login/register',
|
|
'pages/login/forget',
|
|
'pages/login/geetest-webview',
|
|
'pages/register/confirm',
|
|
'pages/index/index'
|
|
]
|
|
|
|
function currentRoute() {
|
|
try {
|
|
const pages = getCurrentPages()
|
|
if (!pages.length) return ''
|
|
const cur = pages[pages.length - 1]
|
|
return (cur && (cur.route || (cur.$page && cur.$page.path))) || ''
|
|
} catch (e) {
|
|
return ''
|
|
}
|
|
}
|
|
|
|
function ensureLogin() {
|
|
const route = currentRoute()
|
|
if (!route || PUBLIC_ROUTES.indexOf(route) !== -1) return
|
|
if (isLoggedIn()) return
|
|
if (getGuestToken()) return
|
|
uni.reLaunch({ url: LOGIN_PAGE })
|
|
}
|
|
|
|
export default {
|
|
onLaunch() {
|
|
console.log('App Launch, API:', getBaseURL())
|
|
},
|
|
onShow() {
|
|
console.log('App Show')
|
|
ensureLogin()
|
|
},
|
|
onHide() {
|
|
console.log('App Hide')
|
|
}
|
|
}
|
|
</script>
|
|
|
|
<style lang="scss">
|
|
@import 'uview-plus/index.scss';
|
|
@import './src/styles/theme.scss';
|
|
@import './src/styles/tint.scss';
|
|
@import './src/styles/fontawesome.scss';
|
|
@import './src/styles/rich-content.scss';
|
|
|
|
page {
|
|
height: 100%;
|
|
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', sans-serif;
|
|
background-color: $color-bg-page;
|
|
color: $color-text;
|
|
box-sizing: border-box;
|
|
}
|
|
|
|
view,
|
|
text,
|
|
scroll-view,
|
|
swiper,
|
|
swiper-item,
|
|
button,
|
|
input,
|
|
textarea,
|
|
label,
|
|
navigator {
|
|
box-sizing: border-box;
|
|
}
|
|
|
|
@media (min-width: 560px) {
|
|
body {
|
|
background: #e9edf3;
|
|
}
|
|
|
|
#app {
|
|
max-width: 560px;
|
|
min-height: 100vh;
|
|
margin-left: auto;
|
|
margin-right: auto;
|
|
background: $color-bg-page;
|
|
box-shadow: 0 0 1px rgba(15, 23, 42, 0.16), 0 10px 40px rgba(15, 23, 42, 0.08);
|
|
}
|
|
}
|
|
</style>
|