提交 6055212a 编写于 作者: Q qiang

fix: update template

上级 c6c6f3bc
let plus_ let plus_
let weex_
let BroadcastChannel_ let BroadcastChannel_
function getRuntime () { function getRuntime () {
...@@ -10,6 +11,7 @@ function getPageId () { ...@@ -10,6 +11,7 @@ function getPageId () {
} }
let channel let channel
let globalEvent
const callbacks = {} const callbacks = {}
function onPlusMessage (res) { function onPlusMessage (res) {
...@@ -27,9 +29,15 @@ function onPlusMessage (res) { ...@@ -27,9 +29,15 @@ function onPlusMessage (res) {
function addEventListener (pageId, callback) { function addEventListener (pageId, callback) {
if (getRuntime() === 'v8') { if (getRuntime() === 'v8') {
channel && channel.close() if (BroadcastChannel_) {
channel = new BroadcastChannel_(getPageId()) channel && channel.close()
channel.onmessage = onPlusMessage channel = new BroadcastChannel_(getPageId())
channel.onmessage = onPlusMessage
} else {
globalEvent && globalEvent.removeEventListener('plusMessage', onPlusMessage)
globalEvent = weex_.requireModule('globalEvent')
globalEvent.addEventListener('plusMessage', onPlusMessage)
}
} else { } else {
window.__plusMessage = onPlusMessage window.__plusMessage = onPlusMessage
} }
...@@ -46,8 +54,13 @@ class Page { ...@@ -46,8 +54,13 @@ class Page {
data data
} }
} }
const channel = new BroadcastChannel_(this.webview.id) const id = this.webview.id
channel.postMessage(message) if (BroadcastChannel_) {
const channel = new BroadcastChannel_(id)
channel.postMessage(message)
} else {
plus_.webview.postMessageToUniNView(message, id)
}
} }
close () { close () {
this.webview.close() this.webview.close()
...@@ -65,7 +78,9 @@ export function showPage ({ ...@@ -65,7 +78,9 @@ export function showPage ({
// eslint-disable-next-line // eslint-disable-next-line
plus_ = context.plus || plus plus_ = context.plus || plus
// eslint-disable-next-line // eslint-disable-next-line
BroadcastChannel_ = context.BroadcastChannel || BroadcastChannel weex_ = context.weex || weex
// eslint-disable-next-line
BroadcastChannel_ = context.BroadcastChannel || (typeof BroadcastChannel === 'object' ? BroadcastChannel : null)
const titleNView = { const titleNView = {
autoBackButton: true, autoBackButton: true,
titleSize: '17px' titleSize: '17px'
...@@ -94,7 +109,8 @@ export function showPage ({ ...@@ -94,7 +109,8 @@ export function showPage ({
extras: { extras: {
from: getPageId(), from: getPageId(),
runtime: getRuntime(), runtime: getRuntime(),
data data,
useGlobalEvent: !BroadcastChannel_
} }
}) })
page.addEventListener('close', onClose) page.addEventListener('close', onClose)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册