From cb83dea998974a712cd1d245e5a5fb944074a102 Mon Sep 17 00:00:00 2001 From: qiang Date: Sat, 15 Jan 2022 18:14:31 +0800 Subject: [PATCH] =?UTF-8?q?fix(mp-alipay):=20=E6=94=AF=E4=BB=98=E5=AE=9D?= =?UTF-8?q?=E5=B0=8F=E7=A8=8B=E5=BA=8F=E7=BB=84=E4=BB=B6=E4=BA=8B=E4=BB=B6?= =?UTF-8?q?=E7=9B=91=E5=90=AC=20#2273?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../__tests__/compiler-mp-alipay.spec.js | 8 ++++---- packages/uni-template-compiler/lib/constants.js | 1 + .../lib/script/traverse/data/index.js | 17 ++++++++++++++++- src/platforms/mp-alipay/runtime/wrapper/util.js | 7 ++++--- 4 files changed, 25 insertions(+), 8 deletions(-) diff --git a/packages/uni-template-compiler/__tests__/compiler-mp-alipay.spec.js b/packages/uni-template-compiler/__tests__/compiler-mp-alipay.spec.js index f178bf23f..72e063b39 100644 --- a/packages/uni-template-compiler/__tests__/compiler-mp-alipay.spec.js +++ b/packages/uni-template-compiler/__tests__/compiler-mp-alipay.spec.js @@ -46,8 +46,8 @@ describe('mp:compiler-mp-alipay', () => { '' ) assertCodegen( - 'text', - 'text', + 'text', + 'text', undefined, undefined, { @@ -55,8 +55,8 @@ describe('mp:compiler-mp-alipay', () => { } ) assertCodegen( - 'text', - 'text', + 'text', + 'text', undefined, undefined, { diff --git a/packages/uni-template-compiler/lib/constants.js b/packages/uni-template-compiler/lib/constants.js index bc38a000a..9cd51b9c6 100644 --- a/packages/uni-template-compiler/lib/constants.js +++ b/packages/uni-template-compiler/lib/constants.js @@ -63,6 +63,7 @@ module.exports = { ATTR_DATA_EVENT_OPTS: 'data-event-opts', ATTR_DATA_COM_TYPE: 'data-com-type', ATTR_DATA_EVENT_PARAMS: 'data-event-params', + ATTR_DATA_EVENT_LIST: 'data-event-list', ATTE_DATA_CUSTOM_HIDDEN: 'data-custom-hidden', INTERNAL_GET_ORIG, INTERNAL_GET_CLASS, diff --git a/packages/uni-template-compiler/lib/script/traverse/data/index.js b/packages/uni-template-compiler/lib/script/traverse/data/index.js index f19362168..16996f7bf 100644 --- a/packages/uni-template-compiler/lib/script/traverse/data/index.js +++ b/packages/uni-template-compiler/lib/script/traverse/data/index.js @@ -1,7 +1,8 @@ const t = require('@babel/types') const { - ATTR_DATA_COM_TYPE + ATTR_DATA_COM_TYPE, + ATTR_DATA_EVENT_LIST } = require('../../../constants') const processRef = require('./ref') @@ -51,6 +52,20 @@ module.exports = function traverseData (path, state, tagName) { t.stringLiteral('__r') ) ) + const properties = path.node.properties.find(prop => prop.key.name === 'on').value.properties + const list = [] + for (let index = 0; index < properties.length; index++) { + const element = properties[index] + if (element.value.value === '__e') { + list.push(element.key.value) + } + } + addAttrProperties.push( + t.objectProperty( + t.stringLiteral(ATTR_DATA_EVENT_LIST), + t.stringLiteral(list.join(',')) + ) + ) } } diff --git a/src/platforms/mp-alipay/runtime/wrapper/util.js b/src/platforms/mp-alipay/runtime/wrapper/util.js index 01e9a52f6..cae35cd61 100644 --- a/src/platforms/mp-alipay/runtime/wrapper/util.js +++ b/src/platforms/mp-alipay/runtime/wrapper/util.js @@ -115,11 +115,12 @@ export function handleRef (ref) { if (ref.props['data-com-type'] === 'wx') { const eventProps = {} let refProps = ref.props + let 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) -- GitLab