publish-handler.js 743 字节
Newer Older
fxy060608's avatar
fxy060608 已提交
1
export function publishHandler (eventType, args, pageIds) {
fxy060608's avatar
fxy060608 已提交
2
  args = JSON.stringify(args)
fxy060608's avatar
init v3  
fxy060608 已提交
3 4 5 6 7 8 9
  if (process.env.NODE_ENV !== 'production') {
    console.log(`UNIAPP[publishHandler]:[${+new Date()}]`, eventType, args, pageIds)
  }
  if (!Array.isArray(pageIds)) {
    pageIds = [pageIds]
  }
  const evalJSCode =
fxy060608's avatar
fxy060608 已提交
10
    `typeof UniViewJSBridge !== 'undefined' && UniViewJSBridge.subscribeHandler("${eventType}",${args},__PAGE_ID__)`
fxy060608's avatar
fxy060608 已提交
11 12 13
  if (process.env.NODE_ENV !== 'production') {
    console.log(`UNIAPP[publishHandler]:[${+new Date()}]`, 'length', evalJSCode.length)
  }
fxy060608's avatar
init v3  
fxy060608 已提交
14 15
  pageIds.forEach(id => {
    const webview = plus.webview.getWebviewById(String(id))
fxy060608's avatar
fxy060608 已提交
16
    webview && webview.evalJS(evalJSCode.replace('__PAGE_ID__', id))
fxy060608's avatar
init v3  
fxy060608 已提交
17
  })
fxy060608's avatar
fxy060608 已提交
18
}