/** * 登录守卫工具(三端通用:train-frontend 小程序) * * 需求:登录前可浏览课程信息,但班级/报名/投票/打卡/支付等实际操作必须登录。 * 未登录触发 requireLogin() 时:toast 提示 + 跳回首页 tab + 触发登录浮层(showLoginSheet)。 */ export function requireLogin() { if (getApp() && getApp().$store && getApp().$store.getters.isLoggedIn) return true uni.showToast({ title: '请先登录', icon: 'none' }) setTimeout(function() { uni.switchTab({ url: '/pages/index/index' }) }, 600) setTimeout(function() { uni.$emit('showLoginSheet', {}) }, 800) return false } /** 页面级守卫:在 onShow/onLoad 首行调用,未登录返回 false 阻止后续加载 */ export function guardPage() { return requireLogin() }