<script>
export default {
onLaunch: function() {
console.log('onLaunch');
this.checkTokenAndRedirect();
},
onShow: function() {
console.log('onShow');
this.checkTokenAndRedirect();
},
onHide: function() {
console.log('App Hide');
},
methods: {
checkTokenAndRedirect() {
const token = uni.getStorageSync('token');
const tabBarPagePaths = [
'pages/lnformation/index ',
'pages/home/index'
];
const defaultHomePagePath = 'pages/home/index';
const currentPage = uni.getStorageSync('currentPage');
if (token) {
const redirectPath =tabBarPagePaths.includes(currentPage) ? currentPage : defaultHomePagePath;
this.$nextTick(() =>{
uni.redirectTo({
url: redirectPath
});
},200)
} else {
this.$nextTick(() =>{
uni.redirectTo({
url: '/pages/index/index'
});
},200)
}
},
redirectToLogin() {
uni.redirectTo({
url: 'pages/index/index'
});
},
redirectToCurrentPage(currentPage) {
uni.switchTab({
url: currentPage
});
},
redirectToDefaultHomePage(defaultHomePagePath) {
console.log(defaultHomePagePath,'defaultHomePagePath');
uni.switchTab({
url: defaultHomePagePath
});
}
}
}
</script>
<style lang="scss">
/* @import '@/static/css/common.css' */
// @import '@/uni_modules/uview-ui/index.scss'
// 每个页面公共css
</style>