setupWebViewJavascriptBridge (name, data, callback) {
// 这里若是bridge存在则直接调用native方法并且return
if (window.bridge) {
window.bridge.callHandler(name, data)
return
}
if (window.WebViewJavascriptBridge) {
return callback(window.WebViewJavascriptBridge)
}
if (window.WVJBCallbacks) {
return window.WVJBCallbacks.push(callback)
}
window.WVJBCallbacks = [callback]
let WVJBIframe = document.createElement('iframe')
WVJBIframe.style.display = 'none'
WVJBIframe.src = 'https://__BRIDGE_LOADED__'
document.documentElement.appendChild(WVJBIframe)
setTimeout(() => {
document.documentElement.removeChild(WVJBIframe)
}, 0)
},
androidNavHandler (url) {
/**
* 调用原生的方法跳转页面
*
* Android 机器在政策周报列表的时候 跳转到展示pdf页面的时候 无法给导航加上箭头 他们说是监听不到 故提供此方法 我们这边传入要跳转的路径就好了
*/
const UA = window.navigator.userAgent
const isIpad = /(iPad).*OS\s([\d_]+)/.test(UA)
const isIpod = /(iPod)(.*OS\s([\d_]+))?/.test(UA)
const isIphone = !isIpad && /(iPhone\sOS)\s([\d_]+)/.test(UA)
const isIos = isIpad || isIpod || isIphone
const isAndroid = /(Android);?[\s\/]+([\d.]+)?/.test(UA)
try {
if (isAndroid) {
this.setupWebViewJavascriptBridge('lookNewsDetails', {url}, function (bridge) {
if (!window.bridge) window.bridge = bridge
window.bridge.callHandler('lookShopDetails', {url})
})
return false
}
} catch (e) {
console.log(e.message || e);
}
window.location = url;
},
h5点击跳转
getContentDetail(content) {
/**
* 调用原生的方法跳转页面
*
* Android 机器在政策周报列表的时候 跳转到展示pdf页面的时候 无法给导航加上箭头 他们说是监听不到 故提供此方法 我们这边传入要跳转的路径就好了
*/
//跳转到
let token=this.$route.query.token || this.$route.query.accessToken
//地址是 域名(测试的192...)加端口号+路由+参数+token
let sourceurl=PATH_IMG+'/contentDetail?&announceId='+content.announceId+'&columnCode='+content.belongColumnCode+'§ionCode='+content.belongSectionCode+'&source='+this.$route.query.source+'&token='+token
this.androidNavHandler(sourceurl)
}
网友评论