| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- <script lang="uts">
- // #ifdef APP-ANDROID || APP-HARMONY
- let firstBackTime = 0
- // #endif
- export default {
- onLaunch() {
- console.log('App Launch')
- // 1. 从本地缓存读取 token(或用户信息)
- const token = uni.getStorageSync('token');
- console.log(token, 'token');
- // 2. 判断登录态
- if (token === '' || token === null || token === 'undefined') {
- // 未登录:跳转到默认登录页
- uni.reLaunch({ url: '/pages/login/login' })
- } else {
- // 已登录:正常进入首页
- uni.switchTab({ url: '/pages/homepage/console' })
- }
- },
- onShow() {
- console.log('App Show')
- },
- onHide() {
- console.log('App Hide')
- },
- // #ifdef APP-ANDROID || APP-HARMONY
- onLastPageBackPress() {
- console.log('App LastPageBackPress')
- if (firstBackTime == 0) {
- uni.showToast({
- title: '再按一次退出应用',
- position: 'bottom',
- })
- firstBackTime = Date.now()
- setTimeout(() => {
- firstBackTime = 0
- }, 2000)
- } else if (Date.now() - firstBackTime < 2000) {
- firstBackTime = Date.now()
- uni.exit()
- }
- },
- // #endif
- onExit() {
- console.log('App Exit')
- },
- }
- </script>
- <style lang="scss">
- /*每个页面公共css */
- .uni-row {
- flex-direction: row;
- }
- .uni-column {
- flex-direction: column;
- }
- </style>
|