提交 4dfdc712 编写于 作者: fxy060608's avatar fxy060608

feat(mp-alipay): refactor map,form

上级 cac55db1
...@@ -1283,23 +1283,28 @@ function initRelation$1 (detail) { ...@@ -1283,23 +1283,28 @@ function initRelation$1 (detail) {
this.props.onVueInit(detail); this.props.onVueInit(detail);
} }
const SPECIAL_EVENTS = [ function initSpecialMethods (mpInstance) {
'formReset', if (!mpInstance.$vm) {
'markerTap',
'calloutTap',
'controlTap',
'regionChange'
];
function initSpecialEvents (mpMethods, vueMethods) {
if (!vueMethods) {
return return
} }
SPECIAL_EVENTS.forEach((name) => { let path = mpInstance.is || mpInstance.route;
if (vueMethods[name]) { if (!path) {
mpMethods[name] = vueMethods[name]; 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) { function initChildVues (mpInstance) {
...@@ -1323,6 +1328,8 @@ function initChildVues (mpInstance) { ...@@ -1323,6 +1328,8 @@ function initChildVues (mpInstance) {
childMPInstance.$vm = new VueComponent(vueOptions); childMPInstance.$vm = new VueComponent(vueOptions);
initSpecialMethods(childMPInstance);
handleRef.call(vueOptions.parent.$scope, childMPInstance); handleRef.call(vueOptions.parent.$scope, childMPInstance);
childMPInstance.$vm.$mount(); childMPInstance.$vm.$mount();
...@@ -1473,6 +1480,8 @@ function parsePage (vuePageOptions) { ...@@ -1473,6 +1480,8 @@ function parsePage (vuePageOptions) {
// 初始化 vue 实例 // 初始化 vue 实例
this.$vm = new VueComponent(options); this.$vm = new VueComponent(options);
initSpecialMethods(this);
// 触发首次 setData // 触发首次 setData
this.$vm.$mount(); this.$vm.$mount();
...@@ -1497,8 +1506,6 @@ function parsePage (vuePageOptions) { ...@@ -1497,8 +1506,6 @@ function parsePage (vuePageOptions) {
initHooks(pageOptions, hooks$1); initHooks(pageOptions, hooks$1);
initSpecialEvents(pageOptions, vueOptions.methods);
return pageOptions return pageOptions
} }
...@@ -1578,8 +1585,11 @@ function parseComponent (vueComponentOptions) { ...@@ -1578,8 +1585,11 @@ function parseComponent (vueComponentOptions) {
mixins: initBehaviors(vueOptions, initBehavior$1), mixins: initBehaviors(vueOptions, initBehavior$1),
data: initData(vueOptions, Vue.prototype), data: initData(vueOptions, Vue.prototype),
props, props,
didMount () { didMount () {
initVm.call(this, VueComponent); initVm.call(this, VueComponent);
initSpecialMethods(this);
if (isComponent2) { if (isComponent2) {
this.$vm._isMounted = true; this.$vm._isMounted = true;
this.$vm.__call_hook('mounted'); this.$vm.__call_hook('mounted');
...@@ -1606,8 +1616,6 @@ function parseComponent (vueComponentOptions) { ...@@ -1606,8 +1616,6 @@ function parseComponent (vueComponentOptions) {
componentOptions.didUpdate = createObserver$1(true); componentOptions.didUpdate = createObserver$1(true);
} }
initSpecialEvents(componentOptions.methods, vueOptions.methods);
return componentOptions return componentOptions
} }
......
{ {
"name": "@dcloudio/uni-mp-alipay", "name": "@dcloudio/uni-mp-alipay",
"version": "0.0.807", "version": "0.0.808",
"description": "uni-app mp-alipay", "description": "uni-app mp-alipay",
"main": "dist/index.js", "main": "dist/index.js",
"scripts": { "scripts": {
......
...@@ -18,7 +18,7 @@ import { ...@@ -18,7 +18,7 @@ import {
createObserver, createObserver,
isComponent2, isComponent2,
initChildVues, initChildVues,
initSpecialEvents initSpecialMethods
} from './util' } from './util'
function initVm (VueComponent) { function initVm (VueComponent) {
...@@ -91,8 +91,11 @@ export default function parseComponent (vueComponentOptions) { ...@@ -91,8 +91,11 @@ export default function parseComponent (vueComponentOptions) {
mixins: initBehaviors(vueOptions, initBehavior), mixins: initBehaviors(vueOptions, initBehavior),
data: initData(vueOptions, Vue.prototype), data: initData(vueOptions, Vue.prototype),
props, props,
didMount () { didMount () {
initVm.call(this, VueComponent) initVm.call(this, VueComponent)
initSpecialMethods(this)
if (isComponent2) { if (isComponent2) {
this.$vm._isMounted = true this.$vm._isMounted = true
this.$vm.__call_hook('mounted') this.$vm.__call_hook('mounted')
...@@ -119,7 +122,5 @@ export default function parseComponent (vueComponentOptions) { ...@@ -119,7 +122,5 @@ export default function parseComponent (vueComponentOptions) {
componentOptions.didUpdate = createObserver(true) componentOptions.didUpdate = createObserver(true)
} }
initSpecialEvents(componentOptions.methods, vueOptions.methods)
return componentOptions return componentOptions
} }
...@@ -14,7 +14,7 @@ import { ...@@ -14,7 +14,7 @@ import {
handleLink, handleLink,
initBehavior, initBehavior,
initChildVues, initChildVues,
initSpecialEvents initSpecialMethods
} from './util' } from './util'
const hooks = [ const hooks = [
...@@ -46,6 +46,8 @@ export default function parsePage (vuePageOptions) { ...@@ -46,6 +46,8 @@ export default function parsePage (vuePageOptions) {
// 初始化 vue 实例 // 初始化 vue 实例
this.$vm = new VueComponent(options) this.$vm = new VueComponent(options)
initSpecialMethods(this)
// 触发首次 setData // 触发首次 setData
this.$vm.$mount() this.$vm.$mount()
...@@ -70,7 +72,5 @@ export default function parsePage (vuePageOptions) { ...@@ -70,7 +72,5 @@ export default function parsePage (vuePageOptions) {
initHooks(pageOptions, hooks) initHooks(pageOptions, hooks)
initSpecialEvents(pageOptions, vueOptions.methods)
return pageOptions return pageOptions
} }
...@@ -42,23 +42,28 @@ export function initRelation (detail) { ...@@ -42,23 +42,28 @@ export function initRelation (detail) {
this.props.onVueInit(detail) this.props.onVueInit(detail)
} }
const SPECIAL_EVENTS = [ export function initSpecialMethods (mpInstance) {
'formReset', if (!mpInstance.$vm) {
'markerTap',
'calloutTap',
'controlTap',
'regionChange'
]
export function initSpecialEvents (mpMethods, vueMethods) {
if (!vueMethods) {
return return
} }
SPECIAL_EVENTS.forEach((name) => { let path = mpInstance.is || mpInstance.route
if (vueMethods[name]) { if (!path) {
mpMethods[name] = vueMethods[name] 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) { export function initChildVues (mpInstance) {
...@@ -82,6 +87,8 @@ export function initChildVues (mpInstance) { ...@@ -82,6 +87,8 @@ export function initChildVues (mpInstance) {
childMPInstance.$vm = new VueComponent(vueOptions) childMPInstance.$vm = new VueComponent(vueOptions)
initSpecialMethods(childMPInstance)
handleRef.call(vueOptions.parent.$scope, childMPInstance) handleRef.call(vueOptions.parent.$scope, childMPInstance)
childMPInstance.$vm.$mount() childMPInstance.$vm.$mount()
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册