diff --git a/packages/uni-h5-vue/dist/vue.runtime.cjs.js b/packages/uni-h5-vue/dist/vue.runtime.cjs.js index 50c1c8cb3f44a26adf6e3069b3507dfb37be3404..a81fc6e93ef15d28da3384d8fa1295e9c066552a 100644 --- a/packages/uni-h5-vue/dist/vue.runtime.cjs.js +++ b/packages/uni-h5-vue/dist/vue.runtime.cjs.js @@ -1859,7 +1859,9 @@ function emit$1(instance, event, ...rawArgs) { handler = props[(handlerName = shared.toHandlerKey(shared.hyphenate(event)))]; } if (handler) { - callWithAsyncErrorHandling(handler, instance, 6 /* COMPONENT_EVENT_HANDLER */, args); + callWithAsyncErrorHandling(handler, instance, 6 /* COMPONENT_EVENT_HANDLER */, + // fixed by xxxxxx + normalizeWxsEventArgs(instance, handler, args)); } const onceHandler = props[handlerName + `Once`]; if (onceHandler) { @@ -1870,9 +1872,52 @@ function emit$1(instance, event, ...rawArgs) { return; } instance.emitted[handlerName] = true; - callWithAsyncErrorHandling(onceHandler, instance, 6 /* COMPONENT_EVENT_HANDLER */, args); + callWithAsyncErrorHandling(onceHandler, instance, 6 /* COMPONENT_EVENT_HANDLER */, + // fixed by xxxxxx + normalizeWxsEventArgs(instance, onceHandler, args)); } } +/** + * 补充 wxs 事件参数 + * @param instance + * @param handler + * @param args + * @returns + */ +function normalizeWxsEventArgs(instance, handler, args) { + // 系统组件事件参数长度一定是 1 + if (args.length !== 1) { + return args; + } + // 判断是否可能需要补充 ownerInstance 参数 + if (shared.isFunction(handler)) { + // 单函数,且参数小于 2 的直接返回 + if (handler.length < 2) { + return args; + } + } + else { + // 多函数,且参数没有大于等于 2 的直接返回 + if (!handler.find(item => item.length >= 2)) { + return args; + } + } + // 系统组件事件对象 + const $sysEvent = args[0]; + if ($sysEvent && + shared.hasOwn($sysEvent, 'type') && + shared.hasOwn($sysEvent, 'timeStamp') && + shared.hasOwn($sysEvent, 'target') && + shared.hasOwn($sysEvent, 'currentTarget') && + shared.hasOwn($sysEvent, 'detail')) { + const proxy = instance.proxy; + const $ownerInstance = proxy.$gcd(proxy, true); + if ($ownerInstance) { + args.push($ownerInstance); + } + } + return args; +} function normalizeEmitsOptions(comp, appContext, asMixin = false) { const cache = appContext.emitsCache; const cached = cache.get(comp); diff --git a/packages/uni-h5-vue/dist/vue.runtime.esm.js b/packages/uni-h5-vue/dist/vue.runtime.esm.js index 3d565a022b5ebbaffe3e0520e1fdaf8945f8ad39..9c9bf35e72610ca251339a54921d1046313e1c0e 100644 --- a/packages/uni-h5-vue/dist/vue.runtime.esm.js +++ b/packages/uni-h5-vue/dist/vue.runtime.esm.js @@ -1880,7 +1880,9 @@ function emit$1(instance, event, ...rawArgs) { handler = props[(handlerName = toHandlerKey(hyphenate(event)))]; } if (handler) { - callWithAsyncErrorHandling(handler, instance, 6 /* COMPONENT_EVENT_HANDLER */, args); + callWithAsyncErrorHandling(handler, instance, 6 /* COMPONENT_EVENT_HANDLER */, + // fixed by xxxxxx + normalizeWxsEventArgs(instance, handler, args)); } const onceHandler = props[handlerName + `Once`]; if (onceHandler) { @@ -1891,9 +1893,52 @@ function emit$1(instance, event, ...rawArgs) { return; } instance.emitted[handlerName] = true; - callWithAsyncErrorHandling(onceHandler, instance, 6 /* COMPONENT_EVENT_HANDLER */, args); + callWithAsyncErrorHandling(onceHandler, instance, 6 /* COMPONENT_EVENT_HANDLER */, + // fixed by xxxxxx + normalizeWxsEventArgs(instance, onceHandler, args)); } } +/** + * 补充 wxs 事件参数 + * @param instance + * @param handler + * @param args + * @returns + */ +function normalizeWxsEventArgs(instance, handler, args) { + // 系统组件事件参数长度一定是 1 + if (args.length !== 1) { + return args; + } + // 判断是否可能需要补充 ownerInstance 参数 + if (isFunction(handler)) { + // 单函数,且参数小于 2 的直接返回 + if (handler.length < 2) { + return args; + } + } + else { + // 多函数,且参数没有大于等于 2 的直接返回 + if (!handler.find(item => item.length >= 2)) { + return args; + } + } + // 系统组件事件对象 + const $sysEvent = args[0]; + if ($sysEvent && + hasOwn($sysEvent, 'type') && + hasOwn($sysEvent, 'timeStamp') && + hasOwn($sysEvent, 'target') && + hasOwn($sysEvent, 'currentTarget') && + hasOwn($sysEvent, 'detail')) { + const proxy = instance.proxy; + const $ownerInstance = proxy.$gcd(proxy, true); + if ($ownerInstance) { + args.push($ownerInstance); + } + } + return args; +} function normalizeEmitsOptions(comp, appContext, asMixin = false) { const cache = appContext.emitsCache; const cached = cache.get(comp);