From 43965c0c3d63a7ec6da88acb925f53627c374f9c Mon Sep 17 00:00:00 2001 From: qiang Date: Fri, 22 Nov 2019 13:58:54 +0800 Subject: [PATCH] fix: v3-app picker --- .../app-plus/view/components/picker/page.js | 29 ++++++++++++++----- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/src/platforms/app-plus/view/components/picker/page.js b/src/platforms/app-plus/view/components/picker/page.js index 8cc0cf937..7e5734703 100644 --- a/src/platforms/app-plus/view/components/picker/page.js +++ b/src/platforms/app-plus/view/components/picker/page.js @@ -1,4 +1,5 @@ let plus_ +let weex_ let BroadcastChannel_ function getRuntime () { @@ -10,6 +11,7 @@ function getPageId () { } let channel +let globalEvent const callbacks = {} function onPlusMessage (res) { @@ -27,9 +29,14 @@ function onPlusMessage (res) { function addEventListener (pageId, callback) { if (getRuntime() === 'v8') { - channel && channel.close() - channel = new BroadcastChannel_(getPageId()) - channel.onmessage = onPlusMessage + if (BroadcastChannel_) { + channel && channel.close() + channel = new BroadcastChannel_(getPageId()) + channel.onmessage = onPlusMessage + } else if (!globalEvent) { + globalEvent = weex_.requireModule('globalEvent') + globalEvent.addEventListener('plusMessage', onPlusMessage) + } } else { window.__plusMessage = onPlusMessage } @@ -46,8 +53,13 @@ class Page { data } } - const channel = new BroadcastChannel_(this.webview.id) - channel.postMessage(message) + const id = this.webview.id + if (BroadcastChannel_) { + const channel = new BroadcastChannel_(id) + channel.postMessage(message) + } else { + plus_.webview.postMessageToUniNView(message, id) + } } close () { this.webview.close() @@ -65,7 +77,9 @@ export function showPage ({ // eslint-disable-next-line plus_ = context.plus || plus // eslint-disable-next-line - BroadcastChannel_ = context.BroadcastChannel || BroadcastChannel + weex_ = context.weex || (typeof weex === 'object' ? weex : null) + // eslint-disable-next-line + BroadcastChannel_ = context.BroadcastChannel || (typeof BroadcastChannel === 'object' ? BroadcastChannel : null) const titleNView = { autoBackButton: true, titleSize: '17px' @@ -94,7 +108,8 @@ export function showPage ({ extras: { from: getPageId(), runtime: getRuntime(), - data + data, + useGlobalEvent: !BroadcastChannel_ } }) page.addEventListener('close', onClose) -- GitLab