fix: 解决首页需要登录才能看到元素

This commit is contained in:
2025-12-20 17:30:01 +08:00
parent 8a934348a6
commit dd2006dd8c
2 changed files with 7 additions and 29 deletions

View File

@@ -117,10 +117,7 @@ class EventBus {
// 如果 allowAsyncHandlerRun 为 true在每个监听器执行后调用 defaultAsyncHandler // 如果 allowAsyncHandlerRun 为 true在每个监听器执行后调用 defaultAsyncHandler
// 如果 allowAsyncHandlerRun 为 false不调用 defaultAsyncHandler // 如果 allowAsyncHandlerRun 为 false不调用 defaultAsyncHandler
// 注意:如果 allowAsyncHandlerRun 为 falsedefaultAsyncHandler 不会被调用,也不会等待其 resolve // 注意:如果 allowAsyncHandlerRun 为 falsedefaultAsyncHandler 不会被调用,也不会等待其 resolve
// 定义一个设置每个监听器执行后,是否都要调用 defaultAsyncHandler async emit(eventName, data, defaultAsyncHandler, { allowContinuePropagation = true, stopOnError = false, allowAsyncHandlerRun = true } = {}) {
// 如果 callDefaultAsyncHandlerAfterEachListener 为 true每个监听器执行后都调用 defaultAsyncHandler
// 如果 callDefaultAsyncHandlerAfterEachListener 为 false只在所有监听器执行完毕后调用 defaultAsyncHandler
async emit(eventName, data, defaultAsyncHandler, { allowContinuePropagation = true, stopOnError = false, allowAsyncHandlerRun = true, callDefaultAsyncHandlerAfterEachListener = false } = {}) {
// 先创建事件对象,方便传入 defaultAsyncHandler // 先创建事件对象,方便传入 defaultAsyncHandler
const event = this.createEvent(eventName, data) const event = this.createEvent(eventName, data)
@@ -149,23 +146,14 @@ class EventBus {
) )
// 调用 defaultAsyncHandler仅当允许 // 调用 defaultAsyncHandler仅当允许
await callDefaultAsyncHandler(event, null, domResult ?? true) await callDefaultAsyncHandler(event, null, domResult)
// 如果不允许继续传播,则直接返回(根据 defaultPrevented 判断结果) // 如果不允许继续传播,则直接返回(根据 defaultPrevented 判断结果)
if (!allowContinuePropagation) { if (!allowContinuePropagation) {
return !event.defaultPrevented return !event.defaultPrevented
} }
// 否则继续走普通 EventBus 处理fallthrough // 否则继续走普通 EventBus 处理fallthrough
} else if (this.platform === 'h5') { }
// 调用 defaultAsyncHandler仅当允许
await callDefaultAsyncHandler(event, null, true)
// 如果不允许继续传播,则直接返回(根据 defaultPrevented 判断结果)
if (!allowContinuePropagation) {
return !event.defaultPrevented
}
// 否则继续走普通 EventBus 处理fallthrough
}
// 普通 EventBus 触发 // 普通 EventBus 触发
const handlers = this.events.get(eventName) const handlers = this.events.get(eventName)
@@ -202,17 +190,10 @@ class EventBus {
} }
// 在每个监听器执行后,如果允许并且提供了 defaultAsyncHandler就调用并等待它 // 在每个监听器执行后,如果允许并且提供了 defaultAsyncHandler就调用并等待它
if (callDefaultAsyncHandlerAfterEachListener && allowAsyncHandlerRun) { console.log('==> callDefaultAsyncHandler', {event, handler, awaitedResult})
await callDefaultAsyncHandler(event, handler, awaitedResult) await callDefaultAsyncHandler(event, handler, awaitedResult)
}
} catch (error) { } catch (error) {
console.error(`EventBus ${eventName} error:`, error) console.error(`EventBus ${eventName} error:`, error)
// 发现错误,默认调用 defaultAsyncHandler仅当允许
if (allowAsyncHandlerRun && callDefaultAsyncHandlerAfterEachListener) {
await callDefaultAsyncHandler(event, handler, true)
}
// 如果全局或该 handler 指定遇错停止传播,则停止 // 如果全局或该 handler 指定遇错停止传播,则停止
if (stopOnError || handler.options?.stopOnError) { if (stopOnError || handler.options?.stopOnError) {
break break
@@ -226,11 +207,6 @@ class EventBus {
} }
} }
// 如果 callDefaultAsyncHandlerAfterEachListener 为 false只在所有监听器执行完毕后调用 defaultAsyncHandler
if (!callDefaultAsyncHandlerAfterEachListener && allowAsyncHandlerRun) {
await callDefaultAsyncHandler(event, null, true)
}
return !event.defaultPrevented return !event.defaultPrevented
} }

View File

@@ -61,11 +61,13 @@ export default {
}, },
// 统一处理点击及触摸事件 // 统一处理点击及触摸事件
_handleDiyGroupInteractionEvent(payload) { _handleDiyGroupInteractionEvent(payload) {
// 如果已登录,直接返回 true 继续传播
if (this.storeToken) { if (this.storeToken) {
return true; return true;
} }
// 打开登录弹窗 // 打开登录弹窗
console.log('==> _handleDiyGroupInteractionEvent, 未登录,打开登录弹窗', { payload })
this.$refs.login?.open(); this.$refs.login?.open();
// 阻止事件继续传播 // 阻止事件继续传播