diff --git a/packages/uni-mp-alipay/dist/index.js b/packages/uni-mp-alipay/dist/index.js index 13dc87310f944dffa81453ab6a6e89e38aedfccd..ce8db8c890e8c9e78688e6fb3c83b3aa4f6535b9 100644 --- a/packages/uni-mp-alipay/dist/index.js +++ b/packages/uni-mp-alipay/dist/index.js @@ -1283,23 +1283,28 @@ function initRelation$1 (detail) { this.props.onVueInit(detail); } -const SPECIAL_EVENTS = [ - 'formReset', - 'markerTap', - 'calloutTap', - 'controlTap', - 'regionChange' -]; - -function initSpecialEvents (mpMethods, vueMethods) { - if (!vueMethods) { +function initSpecialMethods (mpInstance) { + if (!mpInstance.$vm) { return } - SPECIAL_EVENTS.forEach((name) => { - if (vueMethods[name]) { - mpMethods[name] = vueMethods[name]; - } - }); + let path = mpInstance.is || mpInstance.route; + if (!path) { + return + } + if (path.indexOf('/') === 0) { + path = path.substr(1); + } + const specialMethods = my.specialMethods && my.specialMethods[path]; + if (specialMethods) { + specialMethods.forEach(method => { + if (isFn(mpInstance.$vm[method])) { + mpInstance[method] = function (event) { + // TODO normalizeEvent + mpInstance.$vm[method](event); + }; + } + }); + } } function initChildVues (mpInstance) { @@ -1323,6 +1328,8 @@ function initChildVues (mpInstance) { childMPInstance.$vm = new VueComponent(vueOptions); + initSpecialMethods(childMPInstance); + handleRef.call(vueOptions.parent.$scope, childMPInstance); childMPInstance.$vm.$mount(); @@ -1473,6 +1480,8 @@ function parsePage (vuePageOptions) { // 初始化 vue 实例 this.$vm = new VueComponent(options); + + initSpecialMethods(this); // 触发首次 setData this.$vm.$mount(); @@ -1497,8 +1506,6 @@ function parsePage (vuePageOptions) { initHooks(pageOptions, hooks$1); - initSpecialEvents(pageOptions, vueOptions.methods); - return pageOptions } @@ -1578,8 +1585,11 @@ function parseComponent (vueComponentOptions) { mixins: initBehaviors(vueOptions, initBehavior$1), data: initData(vueOptions, Vue.prototype), props, - didMount () { + didMount () { initVm.call(this, VueComponent); + + initSpecialMethods(this); + if (isComponent2) { this.$vm._isMounted = true; this.$vm.__call_hook('mounted'); @@ -1606,8 +1616,6 @@ function parseComponent (vueComponentOptions) { componentOptions.didUpdate = createObserver$1(true); } - initSpecialEvents(componentOptions.methods, vueOptions.methods); - return componentOptions } diff --git a/packages/uni-mp-alipay/package.json b/packages/uni-mp-alipay/package.json index 1843fc29990bc702367ffb73630bd3ec0e5ea752..b519e75d2d8d2e4ffa0f6ebfef07d0157a7faa06 100644 --- a/packages/uni-mp-alipay/package.json +++ b/packages/uni-mp-alipay/package.json @@ -1,6 +1,6 @@ { "name": "@dcloudio/uni-mp-alipay", - "version": "0.0.807", + "version": "0.0.808", "description": "uni-app mp-alipay", "main": "dist/index.js", "scripts": { diff --git a/src/platforms/mp-alipay/runtime/wrapper/component-parser.js b/src/platforms/mp-alipay/runtime/wrapper/component-parser.js index ce598b5e405fbd225f6e282b06fd0ebbfbf8b905..e589887c494a7544fb951b2174e3eb09695bf625 100644 --- a/src/platforms/mp-alipay/runtime/wrapper/component-parser.js +++ b/src/platforms/mp-alipay/runtime/wrapper/component-parser.js @@ -18,7 +18,7 @@ import { createObserver, isComponent2, initChildVues, - initSpecialEvents + initSpecialMethods } from './util' function initVm (VueComponent) { @@ -91,8 +91,11 @@ export default function parseComponent (vueComponentOptions) { mixins: initBehaviors(vueOptions, initBehavior), data: initData(vueOptions, Vue.prototype), props, - didMount () { + didMount () { initVm.call(this, VueComponent) + + initSpecialMethods(this) + if (isComponent2) { this.$vm._isMounted = true this.$vm.__call_hook('mounted') @@ -119,7 +122,5 @@ export default function parseComponent (vueComponentOptions) { componentOptions.didUpdate = createObserver(true) } - initSpecialEvents(componentOptions.methods, vueOptions.methods) - return componentOptions } diff --git a/src/platforms/mp-alipay/runtime/wrapper/page-parser.js b/src/platforms/mp-alipay/runtime/wrapper/page-parser.js index 45c574153edddae00d54d32cdee1f57035bc65e4..0613e0d4d495ea061d1f1fed8836f9e17235eff4 100644 --- a/src/platforms/mp-alipay/runtime/wrapper/page-parser.js +++ b/src/platforms/mp-alipay/runtime/wrapper/page-parser.js @@ -14,7 +14,7 @@ import { handleLink, initBehavior, initChildVues, - initSpecialEvents + initSpecialMethods } from './util' const hooks = [ @@ -46,6 +46,8 @@ export default function parsePage (vuePageOptions) { // 初始化 vue 实例 this.$vm = new VueComponent(options) + + initSpecialMethods(this) // 触发首次 setData this.$vm.$mount() @@ -70,7 +72,5 @@ export default function parsePage (vuePageOptions) { initHooks(pageOptions, hooks) - initSpecialEvents(pageOptions, vueOptions.methods) - return pageOptions } diff --git a/src/platforms/mp-alipay/runtime/wrapper/util.js b/src/platforms/mp-alipay/runtime/wrapper/util.js index 2a424892813ea5c98f584cc496cf7d50e0b98599..30ea330bc336d6e36b5b5837f6dc6bb12155f09d 100644 --- a/src/platforms/mp-alipay/runtime/wrapper/util.js +++ b/src/platforms/mp-alipay/runtime/wrapper/util.js @@ -42,23 +42,28 @@ export function initRelation (detail) { this.props.onVueInit(detail) } -const SPECIAL_EVENTS = [ - 'formReset', - 'markerTap', - 'calloutTap', - 'controlTap', - 'regionChange' -] - -export function initSpecialEvents (mpMethods, vueMethods) { - if (!vueMethods) { +export function initSpecialMethods (mpInstance) { + if (!mpInstance.$vm) { return } - SPECIAL_EVENTS.forEach((name) => { - if (vueMethods[name]) { - mpMethods[name] = vueMethods[name] - } - }) + let path = mpInstance.is || mpInstance.route + if (!path) { + return + } + if (path.indexOf('/') === 0) { + path = path.substr(1) + } + const specialMethods = my.specialMethods && my.specialMethods[path] + if (specialMethods) { + specialMethods.forEach(method => { + if (isFn(mpInstance.$vm[method])) { + mpInstance[method] = function (event) { + // TODO normalizeEvent + mpInstance.$vm[method](event) + } + } + }) + } } export function initChildVues (mpInstance) { @@ -82,6 +87,8 @@ export function initChildVues (mpInstance) { childMPInstance.$vm = new VueComponent(vueOptions) + initSpecialMethods(childMPInstance) + handleRef.call(vueOptions.parent.$scope, childMPInstance) childMPInstance.$vm.$mount()