From f7b6e5e1b9eb4fe731b448dfc4b1dd44cb0e38ee Mon Sep 17 00:00:00 2001 From: xpz2018 <107107461@qq.com> Date: Thu, 10 Jun 2021 14:53:56 +0800 Subject: [PATCH] no message --- colorui/components/cu-custom.js | 2 +- pages/index/scene.js | 16 +++++++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/colorui/components/cu-custom.js b/colorui/components/cu-custom.js index 82b5edc..a8f619e 100644 --- a/colorui/components/cu-custom.js +++ b/colorui/components/cu-custom.js @@ -90,7 +90,7 @@ Component({ } }, toHome() { - if (app.userInfo.userId) { + if (app.userInfo && app.userInfo.userId) { wx.redirectTo({ url: '/pages/index/index' }) } else { wx.reLaunch({ url: '/pages/login/index' }) diff --git a/pages/index/scene.js b/pages/index/scene.js index 66c7cc3..6cf9864 100644 --- a/pages/index/scene.js +++ b/pages/index/scene.js @@ -1,5 +1,6 @@ +const app = getApp() export default function Scene(config) { - const { onLoad } = config + const { onLoad, onUnload } = config config.onLoad = function(options) { if (onLoad) { onLoad.call(this, options) @@ -11,5 +12,18 @@ export default function Scene(config) { } } } + config.onUnload = function(options) { + if (onUnload) { + onUnload.call(this, options) + } + let pages = getCurrentPages() //当前页面栈 + if (pages.length == 1 && pages[0].route != 'pages/index/index') { + if (app.userInfo && app.userInfo.userId) { + wx.redirectTo({ url: '/pages/index/index' }) + } else { + wx.reLaunch({ url: '/pages/login/index' }) + } + } + } return Page(config) }