From f7130646a26ef12821e72ccc5c49b72fd04e2af8 Mon Sep 17 00:00:00 2001 From: qiang Date: Tue, 18 Jan 2022 17:01:51 +0800 Subject: [PATCH] chore: build mp --- packages/uni-mp-alipay/dist/index.js | 43 ++++++++++++++++++++-------- 1 file changed, 31 insertions(+), 12 deletions(-) diff --git a/packages/uni-mp-alipay/dist/index.js b/packages/uni-mp-alipay/dist/index.js index bcb0d824c..e61a008d2 100644 --- a/packages/uni-mp-alipay/dist/index.js +++ b/packages/uni-mp-alipay/dist/index.js @@ -2478,11 +2478,12 @@ function handleRef (ref) { if (ref.props['data-com-type'] === 'wx') { const eventProps = {}; let refProps = ref.props; + const eventList = refProps['data-event-list'].split(','); // 初始化支付宝小程序组件事件 Object.keys(refProps).forEach(key => { - const handler = refProps[key]; - const res = key.match(/^on([A-Z])(\S*)/); - if (res && typeof handler === 'function' && handler.name === 'bound handleEvent') { + if (eventList.includes(key)) { + const handler = refProps[key]; + const res = key.match(/^on([A-Z])(\S*)/); const event = res && (res[1].toLowerCase() + res[2]); refProps[key] = eventProps[key] = function () { const props = Object.assign({}, refProps); @@ -2581,7 +2582,23 @@ const handleLink$1 = (function () { // 支付宝通过 didMount 来实现,先子后父,故等父 ready 之后,统一初始化 (this._$childVues || (this._$childVues = [])).unshift(detail); } -})(); +})(); + +const handleWrap = function (mp, destory) { + const vueId = mp.props.vueId; + const list = mp.props['data-event-list'].split(','); + list.forEach(eventName => { + const key = `${eventName}${vueId}`; + if (destory) { + delete this[key]; + } else { + // TODO remove handleRef + this[key] = function () { + mp.props[eventName].apply(this, arguments); + }; + } + }); +}; function parseApp (vm) { Object.defineProperty(Vue.prototype, '$slots', { @@ -2744,6 +2761,7 @@ function parsePage (vuePageOptions) { __r: handleRef, __e: handleEvent, __l: handleLink$1, + __w: handleWrap, triggerEvent }; @@ -2860,6 +2878,7 @@ function parseComponent (vueComponentOptions) { __r: handleRef, __e: handleEvent, __l: handleLink$1, + __w: handleWrap, triggerEvent } }; @@ -2871,14 +2890,14 @@ function parseComponent (vueComponentOptions) { componentOptions.deriveDataFromProps = createObserver$1(); } else { componentOptions.didUpdate = createObserver$1(true); - } - - if (Array.isArray(vueOptions.wxsCallMethods)) { - vueOptions.wxsCallMethods.forEach(callMethod => { - componentOptions.methods[callMethod] = function (args) { - return this.$vm[callMethod](args) - }; - }); + } + + if (Array.isArray(vueOptions.wxsCallMethods)) { + vueOptions.wxsCallMethods.forEach(callMethod => { + componentOptions.methods[callMethod] = function (args) { + return this.$vm[callMethod](args) + }; + }); } return componentOptions -- GitLab