优化全局未登录拦截,点击任何地方弹出登录窗口
功能改进: 1. 全局事件监听 - App.vue添加setupGlobalListeners方法 - 监听showAuthModal和hideAuthModal事件 - 在onHide时移除监听器 2. 统一的登录拦截机制 - authCheck.js使用uni.$emit触发全局事件 - 点击"去登录"按钮触发showAuthModal事件 - App.vue接收事件后显示授权窗口 3. 用户体验优化 - 未登录时点击任何功能都会弹出提示 - 提示框包含"去登录"按钮 - 点击"去登录"后从底部滑出授权窗口 - 授权窗口占据屏幕70% 工作流程: 1. 用户点击功能模块 2. 检查登录状态 3. 未登录弹出提示框 4. 点击"去登录" 5. 触发showAuthModal事件 6. App.vue显示授权窗口 7. 用户完成授权 8. 继续使用功能
This commit is contained in:
1 parent
0d30d40794
commit
ea7752f554
1 file changed
+19
@@ -13,14 +13,33 @@ export default {
|
||||
onLaunch: function() {
|
||||
console.log('App Launch')
|
||||
this.checkUserAuth()
|
||||
this.setupGlobalListeners()
|
||||
},
|
||||
onShow: function() {
|
||||
console.log('App Show')
|
||||
},
|
||||
onHide: function() {
|
||||
console.log('App Hide')
|
||||
this.removeGlobalListeners()
|
||||
},
|
||||
methods: {
|
||||
setupGlobalListeners() {
|
||||
uni.$on('showAuthModal', () => {
|
||||
console.log('收到showAuthModal事件,显示授权窗口')
|
||||
this.showAuthModal = true
|
||||
})
|
||||
|
||||
uni.$on('hideAuthModal', () => {
|
||||
console.log('收到hideAuthModal事件,隐藏授权窗口')
|
||||
this.showAuthModal = false
|
||||
})
|
||||
},
|
||||
|
||||
removeGlobalListeners() {
|
||||
uni.$off('showAuthModal')
|
||||
uni.$off('hideAuthModal')
|
||||
},
|
||||
|
||||
checkUserAuth() {
|
||||
const userInfo = uni.getStorageSync('userInfo')
|
||||
const hasShownAuth = uni.getStorageSync('hasShownAuth')
|
||||
|
||||
Reference in new issue
Block a user