diff --git a/package5/planet/index.vue b/package5/planet/index.vue index 7614626..de3e3aa 100644 --- a/package5/planet/index.vue +++ b/package5/planet/index.vue @@ -550,6 +550,10 @@ this.userId = uni.getStorageSync('id') || '' this.nickname = uni.getStorageSync('nickName') || uni.getStorageSync('nickname') || '' this.avatar = uni.getStorageSync('avatarUrl') || uni.getStorageSync('avatar') || '' + if (!this.hasLogin()) { + this.goLogin() + return + } try { const area = uni.getStorageSync('area') if (area) { @@ -562,11 +566,23 @@ this.loadHome() }, onShow() { + if (!this.hasLogin()) return if (this.loadedOnce) { this.loadHome(true) } }, methods: { + hasLogin() { + const token = uni.getStorageSync('hiver_token') + return !!(token && typeof token === 'string' && token.trim() && token !== 'null' && token !== 'undefined') + }, + goLogin() { + const redirectKey = 'login_redirect_' + Date.now() + uni.setStorageSync(redirectKey, '/package5/planet/index') + uni.navigateTo({ + url: '/package2/login/login?redirect=' + redirectKey + }) + }, initNavHeight() { try { const menu = uni.getMenuButtonBoundingClientRect && uni.getMenuButtonBoundingClientRect() @@ -622,7 +638,7 @@ }, loadHome(silent) { if (!this.userId) { - this.tui.toast('请先登录') + this.goLogin() return } if (!this.regionId) {