diff --git a/common/js/event-bus.js b/common/js/event-bus.js index 9d2fb5a..0c69b3d 100644 --- a/common/js/event-bus.js +++ b/common/js/event-bus.js @@ -117,10 +117,7 @@ class EventBus { // 如果 allowAsyncHandlerRun 为 true,在每个监听器执行后调用 defaultAsyncHandler // 如果 allowAsyncHandlerRun 为 false,不调用 defaultAsyncHandler // 注意:如果 allowAsyncHandlerRun 为 false,defaultAsyncHandler 不会被调用,也不会等待其 resolve - // 定义一个设置每个监听器执行后,是否都要调用 defaultAsyncHandler - // 如果 callDefaultAsyncHandlerAfterEachListener 为 true,每个监听器执行后都调用 defaultAsyncHandler - // 如果 callDefaultAsyncHandlerAfterEachListener 为 false,只在所有监听器执行完毕后调用 defaultAsyncHandler - async emit(eventName, data, defaultAsyncHandler, { allowContinuePropagation = true, stopOnError = false, allowAsyncHandlerRun = true, callDefaultAsyncHandlerAfterEachListener = false } = {}) { + async emit(eventName, data, defaultAsyncHandler, { allowContinuePropagation = true, stopOnError = false, allowAsyncHandlerRun = true } = {}) { // 先创建事件对象,方便传入 defaultAsyncHandler const event = this.createEvent(eventName, data) @@ -149,23 +146,14 @@ class EventBus { ) // 调用 defaultAsyncHandler(仅当允许) - await callDefaultAsyncHandler(event, null, domResult ?? true) + await callDefaultAsyncHandler(event, null, domResult) // 如果不允许继续传播,则直接返回(根据 defaultPrevented 判断结果) if (!allowContinuePropagation) { return !event.defaultPrevented } // 否则继续走普通 EventBus 处理(fallthrough) - } else if (this.platform === 'h5') { - // 调用 defaultAsyncHandler(仅当允许) - await callDefaultAsyncHandler(event, null, true) - - // 如果不允许继续传播,则直接返回(根据 defaultPrevented 判断结果) - if (!allowContinuePropagation) { - return !event.defaultPrevented - } - // 否则继续走普通 EventBus 处理(fallthrough) - } + } // 普通 EventBus 触发 const handlers = this.events.get(eventName) @@ -202,17 +190,10 @@ class EventBus { } // 在每个监听器执行后,如果允许并且提供了 defaultAsyncHandler,就调用并等待它 - if (callDefaultAsyncHandlerAfterEachListener && allowAsyncHandlerRun) { - await callDefaultAsyncHandler(event, handler, awaitedResult) - } + console.log('==> callDefaultAsyncHandler', {event, handler, awaitedResult}) + await callDefaultAsyncHandler(event, handler, awaitedResult) } catch (error) { console.error(`EventBus ${eventName} error:`, error) - - // 发现错误,默认调用 defaultAsyncHandler(仅当允许) - if (allowAsyncHandlerRun && callDefaultAsyncHandlerAfterEachListener) { - await callDefaultAsyncHandler(event, handler, true) - } - // 如果全局或该 handler 指定遇错停止传播,则停止 if (stopOnError || handler.options?.stopOnError) { break @@ -226,11 +207,6 @@ class EventBus { } } - // 如果 callDefaultAsyncHandlerAfterEachListener 为 false,只在所有监听器执行完毕后调用 defaultAsyncHandler - if (!callDefaultAsyncHandlerAfterEachListener && allowAsyncHandlerRun) { - await callDefaultAsyncHandler(event, null, true) - } - return !event.defaultPrevented } diff --git a/pages/index/public/js/index.js b/pages/index/public/js/index.js index 06b1580..38aad64 100644 --- a/pages/index/public/js/index.js +++ b/pages/index/public/js/index.js @@ -61,11 +61,13 @@ export default { }, // 统一处理点击及触摸事件 _handleDiyGroupInteractionEvent(payload) { + // 如果已登录,直接返回 true 继续传播 if (this.storeToken) { return true; } // 打开登录弹窗 + console.log('==> _handleDiyGroupInteractionEvent, 未登录,打开登录弹窗', { payload }) this.$refs.login?.open(); // 阻止事件继续传播