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

fix(mp): alipay parent,children

上级 c2cfb8e6
......@@ -40,7 +40,7 @@ const camelize = cached((str) => {
return str.replace(camelizeRE, (_, c) => c ? c.toUpperCase() : '')
});
const SYNC_API_RE = /subNVue|requireNativePlugin|upx2px|hideKeyboard|canIUse|^create|Sync$|Manager$/;
const SYNC_API_RE = /subNVue|requireNativePlugin|upx2px|hideKeyboard|canIUse|^create|Sync$|Manager$|base64ToArrayBuffer|arrayBufferToBase64/;
const CONTEXT_API_RE = /^create|Manager$/;
......@@ -88,17 +88,17 @@ function promisify (name, api) {
success: resolve,
fail: reject
}), ...params);
/* eslint-disable no-extend-native */
if (!Promise.prototype.finally) {
Promise.prototype.finally = function (callback) {
const promise = this.constructor;
return this.then(
value => promise.resolve(callback()).then(() => value),
reason => promise.resolve(callback()).then(() => {
throw reason
})
)
};
/* eslint-disable no-extend-native */
if (!Promise.prototype.finally) {
Promise.prototype.finally = function (callback) {
const promise = this.constructor;
return this.then(
value => promise.resolve(callback()).then(() => value),
reason => promise.resolve(callback()).then(() => {
throw reason
})
)
};
}
}))
}
......@@ -1271,12 +1271,16 @@ function initRelation$1 (detail) {
}
function initChildVues (mpInstance) {
// 此时需保证当前 mpInstance 已经存在 $vm
if (!mpInstance.$vm) {
return
}
mpInstance._$childVues && mpInstance._$childVues.forEach(({
vuePid,
vueOptions,
VueComponent,
mpInstance: childMPInstance
}) => {
}) => {
// 父子关系
handleLink.call(mpInstance, {
detail: {
......@@ -1285,12 +1289,15 @@ function initChildVues (mpInstance) {
}
});
childMPInstance.$vm = new VueComponent(vueOptions);
childMPInstance.$vm = new VueComponent(vueOptions);
handleRef.call(vueOptions.parent.$scope, childMPInstance);
childMPInstance.$vm.$mount();
childMPInstance.$vm.$mount();
initChildVues(childMPInstance);
console.log(childMPInstance.is, 'mounted');
childMPInstance.$vm._isMounted = true;
childMPInstance.$vm.__call_hook('mounted');
childMPInstance.$vm.__call_hook('onReady');
......@@ -1364,7 +1371,7 @@ const handleLink$1 = (function () {
}
}
return function handleLink$$1 (detail) {
if (this.$vm) { // 父已初始化
if (this.$vm && this.$vm._isMounted) { // 父已初始化
return handleLink.call(this, {
detail: {
vuePid: detail.vuePid,
......@@ -1443,7 +1450,8 @@ function parsePage (vuePageOptions) {
this.$vm.__call_hook('onLoad', args);
},
onReady () {
initChildVues(this);
initChildVues(this);
console.log(this.route, 'mounted');
this.$vm._isMounted = true;
this.$vm.__call_hook('mounted');
this.$vm.__call_hook('onReady');
......@@ -1494,22 +1502,25 @@ function initVm (VueComponent) {
// 触发首次 setData
this.$vm.$mount();
} else {
initChildVues(this);
} else {
// 处理父子关系
initRelation$1.call(this, {
vuePid: this._$vuePid,
vueOptions: options,
VueComponent,
mpInstance: this
});
if (options.parent) { // 父组件已经初始化,直接初始化子,否则放到父组件的 didMount 中处理
});
if (options.parent) { // 父组件已经初始化,直接初始化子,否则放到父组件的 didMount 中处理
// 初始化 vue 实例
this.$vm = new VueComponent(options);
handleRef.call(options.parent.$scope, this);
// 触发首次 setData
this.$vm.$mount();
this.$vm.$mount();
initChildVues(this);
console.log(this.is, 'mounted');
this.$vm._isMounted = true;
this.$vm.__call_hook('mounted');
this.$vm.__call_hook('onReady');
......
function wrapper (webview) {
webview.$processed = true
webview.postMessage = function (data) {
plus.webview.postMessageToUniNView({
type: 'UniAppSubNVue',
data,
options: {
id: webview.id
}
}, webview.id)
}
let callbacks = []
webview.onMessage = function (callback) {
callbacks.push(callback)
}
webview.$consumeMessage = function (e) {
callbacks.forEach(callback => callback(e))
}
if (!webview.__uniapp_mask_id) {
return
}
......@@ -32,22 +50,6 @@ function wrapper (webview) {
callbacks = []
return oldClose.apply(webview, args)
}
webview.postMessage = function (data) {
plus.webview.postMessageToUniNView({
type: 'UniAppSubNVue',
data,
options: {
id: webview.id
}
}, webview.id)
}
let callbacks = []
webview.onMessage = function (callback) {
callbacks.push(callback)
}
webview.$consumeMessage = function (e) {
callbacks.forEach(callback => callback(e))
}
}
export const subNVue = {
......
......@@ -46,22 +46,25 @@ function initVm (VueComponent) {
// 触发首次 setData
this.$vm.$mount()
} else {
initChildVues(this)
} else {
// 处理父子关系
initRelation.call(this, {
vuePid: this._$vuePid,
vueOptions: options,
VueComponent,
mpInstance: this
})
if (options.parent) { // 父组件已经初始化,直接初始化子,否则放到父组件的 didMount 中处理
})
if (options.parent) { // 父组件已经初始化,直接初始化子,否则放到父组件的 didMount 中处理
// 初始化 vue 实例
this.$vm = new VueComponent(options)
handleRef.call(options.parent.$scope, this)
// 触发首次 setData
this.$vm.$mount()
this.$vm.$mount()
initChildVues(this)
console.log(this.is, 'mounted')
this.$vm._isMounted = true
this.$vm.__call_hook('mounted')
this.$vm.__call_hook('onReady')
......
......@@ -53,7 +53,8 @@ export default function parsePage (vuePageOptions) {
this.$vm.__call_hook('onLoad', args)
},
onReady () {
initChildVues(this)
initChildVues(this)
console.log(this.route, 'mounted')
this.$vm._isMounted = true
this.$vm.__call_hook('mounted')
this.$vm.__call_hook('onReady')
......
......@@ -43,12 +43,16 @@ export function initRelation (detail) {
}
export function initChildVues (mpInstance) {
// 此时需保证当前 mpInstance 已经存在 $vm
if (!mpInstance.$vm) {
return
}
mpInstance._$childVues && mpInstance._$childVues.forEach(({
vuePid,
vueOptions,
VueComponent,
mpInstance: childMPInstance
}) => {
}) => {
// 父子关系
handleBaseLink.call(mpInstance, {
detail: {
......@@ -57,12 +61,15 @@ export function initChildVues (mpInstance) {
}
})
childMPInstance.$vm = new VueComponent(vueOptions)
childMPInstance.$vm = new VueComponent(vueOptions)
handleRef.call(vueOptions.parent.$scope, childMPInstance)
childMPInstance.$vm.$mount()
childMPInstance.$vm.$mount()
initChildVues(childMPInstance)
console.log(childMPInstance.is, 'mounted')
childMPInstance.$vm._isMounted = true
childMPInstance.$vm.__call_hook('mounted')
childMPInstance.$vm.__call_hook('onReady')
......@@ -136,7 +143,7 @@ export const handleLink = (function () {
}
}
return function handleLink (detail) {
if (this.$vm) { // 父已初始化
if (this.$vm && this.$vm._isMounted) { // 父已初始化
return handleBaseLink.call(this, {
detail: {
vuePid: detail.vuePid,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册