提交 3d1a3b5c 编写于 作者: d-u-a's avatar d-u-a

update: runtime web-view 支持nvue

上级 91934a6e
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e=e||self).uni=n()}(this,function(){"use strict";function i(e,n){var i={options:{timestamp:+new Date},name:e,arg:n};if(!window.plus)return window.parent.postMessage({type:s,data:i,pageId:""},"*");if(0===d.length){var t=plus.webview.currentWebview();if(!t)throw new Error("plus.webview.currentWebview() is undefined");var a=t.parent(),r="";r=a?a.id:t.id,d.push(r)}var o=JSON.stringify(i);plus.webview.getWebviewById(u)?plus.webview.postMessageToUniNView({type:s,args:{data:i,webviewIds:d}},u):plus.webview.getLaunchWebview().evalJS('UniPlusBridge.subscribeHandler("'.concat(s,'",').concat(o,",").concat(JSON.stringify(d),");"))}var d=[],u="__uniapp__service",s="WEB_INVOKE_APPSERVICE",n={navigateTo:function(e){var n=(0<arguments.length&&void 0!==e?e:{}).url;i("navigateTo",{url:encodeURI(n)})},navigateBack:function(e){var n=(0<arguments.length&&void 0!==e?e:{}).delta;i("navigateBack",{delta:parseInt(n)||1})},switchTab:function(e){var n=(0<arguments.length&&void 0!==e?e:{}).url;i("switchTab",{url:encodeURI(n)})},reLaunch:function(e){var n=(0<arguments.length&&void 0!==e?e:{}).url;i("reLaunch",{url:encodeURI(n)})},redirectTo:function(e){var n=(0<arguments.length&&void 0!==e?e:{}).url;i("redirectTo",{url:encodeURI(n)})},getEnv:function(e){window.plus?e({plus:!0}):e({h5:!0})},postMessage:function(e){i("postMessage",(0<arguments.length&&void 0!==e?e:{}).data||{})}},t=/uni-app/i.test(navigator.userAgent),a=/complete|loaded|interactive/;var r=window.my&&-1<navigator.userAgent.indexOf("AlipayClient");var o=window.swan&&window.swan.webView&&/swan/i.test(navigator.userAgent);var w=window.qq&&window.qq.miniProgram&&/QQ/i.test(navigator.userAgent)&&/miniProgram/i.test(navigator.userAgent);var g=window.tt&&window.tt.miniProgram&&/toutiaomicroapp/i.test(navigator.userAgent);var c=window.wx&&window.wx.miniProgram&&/micromessenger/i.test(navigator.userAgent)&&/miniProgram/i.test(navigator.userAgent);for(var e,v=function(){window.UniAppJSBridge=!0,document.dispatchEvent(new CustomEvent("UniAppJSBridgeReady",{bubbles:!0,cancelable:!0}))},m=[function(e){if(t)return window.plus&&a.test(document.readyState)?setTimeout(e,0):document.addEventListener("plusready",e),n},function(e){if(c)return window.WeixinJSBridge&&window.WeixinJSBridge.invoke?setTimeout(e,0):document.addEventListener("WeixinJSBridgeReady",e),window.wx.miniProgram},function(e){if(w)return window.QQJSBridge&&window.QQJSBridge.invoke?setTimeout(e,0):document.addEventListener("QQJSBridgeReady",e),window.qq.miniProgram},function(e){if(r){document.addEventListener("DOMContentLoaded",e);var n=window.my;return{navigateTo:n.navigateTo,navigateBack:n.navigateBack,switchTab:n.switchTab,reLaunch:n.reLaunch,redirectTo:n.redirectTo,postMessage:n.postMessage,getEnv:n.getEnv}}},function(e){if(o)return document.addEventListener("DOMContentLoaded",e),window.swan.webView},function(e){if(g)return document.addEventListener("DOMContentLoaded",e),window.tt.miniProgram},function(e){return document.addEventListener("DOMContentLoaded",e),n}],p=0;p<m.length&&!(e=m[p](v));p++);e=e||{};var f="undefined"!=typeof uni?uni:{};return f.navigateTo?f.miniProgram=e:Object.assign(f,e,{miniProgram:e}),f});
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e=e||self).uni=n()}(this,function(){"use strict";function i(e,n){var i={options:{timestamp:+new Date},name:e,arg:n};if(window.__dcloud_weex_postMessage||window.__dcloud_weex_){if("postMessage"===e){var t={data:[n]};return window.__dcloud_weex_postMessage?window.__dcloud_weex_postMessage(t):window.__dcloud_weex_.postMessage(JSON.stringify(t))}var o={type:c,args:{data:i,webviewIds:w}};window.__dcloud_weex_postMessage?window.__dcloud_weex_postMessageToService(o):window.__dcloud_weex_.postMessageToService(JSON.stringify(o))}if(!window.plus)return window.parent.postMessage({type:c,data:i,pageId:""},"*");if(0===w.length){var a=plus.webview.currentWebview();if(!a)throw new Error("plus.webview.currentWebview() is undefined");var d=a.parent(),r="";r=d?d.id:a.id,w.push(r)}if(plus.webview.getWebviewById(u))plus.webview.postMessageToUniNView({type:c,args:{data:i,webviewIds:w}},u);else{var s=JSON.stringify(i);plus.webview.getLaunchWebview().evalJS('UniPlusBridge.subscribeHandler("'.concat(c,'",').concat(s,",").concat(JSON.stringify(w),");"))}}var w=[],u="__uniapp__service",c="WEB_INVOKE_APPSERVICE",n={navigateTo:function(e){var n=(0<arguments.length&&void 0!==e?e:{}).url;i("navigateTo",{url:encodeURI(n)})},navigateBack:function(e){var n=(0<arguments.length&&void 0!==e?e:{}).delta;i("navigateBack",{delta:parseInt(n)||1})},switchTab:function(e){var n=(0<arguments.length&&void 0!==e?e:{}).url;i("switchTab",{url:encodeURI(n)})},reLaunch:function(e){var n=(0<arguments.length&&void 0!==e?e:{}).url;i("reLaunch",{url:encodeURI(n)})},redirectTo:function(e){var n=(0<arguments.length&&void 0!==e?e:{}).url;i("redirectTo",{url:encodeURI(n)})},getEnv:function(e){window.plus?e({plus:!0}):e({h5:!0})},postMessage:function(e){i("postMessage",(0<arguments.length&&void 0!==e?e:{}).data||{})}},t=/uni-app/i.test(navigator.userAgent),o=/complete|loaded|interactive/;var a=window.my&&-1<navigator.userAgent.indexOf("AlipayClient");var d=window.swan&&window.swan.webView&&/swan/i.test(navigator.userAgent);var r=window.qq&&window.qq.miniProgram&&/QQ/i.test(navigator.userAgent)&&/miniProgram/i.test(navigator.userAgent);var s=window.tt&&window.tt.miniProgram&&/toutiaomicroapp/i.test(navigator.userAgent);var g=window.wx&&window.wx.miniProgram&&/micromessenger/i.test(navigator.userAgent)&&/miniProgram/i.test(navigator.userAgent);for(var e,v=function(){window.UniAppJSBridge=!0,document.dispatchEvent(new CustomEvent("UniAppJSBridgeReady",{bubbles:!0,cancelable:!0}))},p=[function(e){if(t)return window.__dcloud_weex_postMessage||window.__dcloud_weex_?document.addEventListener("DOMContentLoaded",e):window.plus&&o.test(document.readyState)?setTimeout(e,0):document.addEventListener("plusready",e),n},function(e){if(g)return window.WeixinJSBridge&&window.WeixinJSBridge.invoke?setTimeout(e,0):document.addEventListener("WeixinJSBridgeReady",e),window.wx.miniProgram},function(e){if(r)return window.QQJSBridge&&window.QQJSBridge.invoke?setTimeout(e,0):document.addEventListener("QQJSBridgeReady",e),window.qq.miniProgram},function(e){if(a){document.addEventListener("DOMContentLoaded",e);var n=window.my;return{navigateTo:n.navigateTo,navigateBack:n.navigateBack,switchTab:n.switchTab,reLaunch:n.reLaunch,redirectTo:n.redirectTo,postMessage:n.postMessage,getEnv:n.getEnv}}},function(e){if(d)return document.addEventListener("DOMContentLoaded",e),window.swan.webView},function(e){if(s)return document.addEventListener("DOMContentLoaded",e),window.tt.miniProgram},function(e){return document.addEventListener("DOMContentLoaded",e),n}],l=0;l<p.length&&!(e=p[l](v));l++);e=e||{};var f="undefined"!=typeof uni?uni:{};return f.navigateTo?f.webView=e:Object.assign(f,e,{webView:e}),f});
......@@ -10,14 +10,43 @@ const publish = function (method, params) {
},
name: method,
arg: params
}
const isNvue = window.__dcloud_weex_postMessage || window.__dcloud_weex_
if (isNvue) { // nvue web-view
if (method === 'postMessage') {
const message = {
data: [params]
}
if (window.__dcloud_weex_postMessage) {
return window.__dcloud_weex_postMessage(message)
} else {
return window.__dcloud_weex_.postMessage(JSON.stringify(message))
}
}
const serviceMessage = {
type: WEB_INVOKE_APPSERVICE,
args: {
data: paramsObj,
webviewIds
}
}
if (window.__dcloud_weex_postMessage) {
window.__dcloud_weex_postMessageToService(serviceMessage)
} else {
window.__dcloud_weex_.postMessageToService(JSON.stringify(serviceMessage))
}
}
if (!window.plus) { // h5
if (!window.plus) { // h5 web-view
return window.parent.postMessage({
type: WEB_INVOKE_APPSERVICE,
data: paramsObj,
pageId: ''
}, '*')
}
// app-plus
if (webviewIds.length === 0) {
const currentWebview = plus.webview.currentWebview()
......@@ -34,7 +63,6 @@ const publish = function (method, params) {
}
webviewIds.push(webviewId)
}
const paramsString = JSON.stringify(paramsObj)
if (plus.webview.getWebviewById(UNIAPP_SERVICE_NVUE_ID)) {
plus.webview.postMessageToUniNView({
type: WEB_INVOKE_APPSERVICE,
......@@ -44,6 +72,7 @@ const publish = function (method, params) {
}
}, UNIAPP_SERVICE_NVUE_ID)
} else {
const paramsString = JSON.stringify(paramsObj)
plus.webview.getLaunchWebview().evalJS(
`UniPlusBridge.subscribeHandler("${WEB_INVOKE_APPSERVICE}",${paramsString},${JSON.stringify(webviewIds)});`
)
......
......@@ -7,11 +7,13 @@ const readyRE = /complete|loaded|interactive/
export function initWebviewApi (readyCallback) {
if (!isAppPlus) {
return
}
if (window.plus && readyRE.test(document.readyState)) {
setTimeout(readyCallback, 0)
} else {
document.addEventListener('plusready', readyCallback)
}
if (window.__dcloud_weex_postMessage || window.__dcloud_weex_) { // nvue web-view
document.addEventListener('DOMContentLoaded', readyCallback)
} else if (window.plus && readyRE.test(document.readyState)) {
setTimeout(readyCallback, 0)
} else {
document.addEventListener('plusready', readyCallback)
}
return api
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册