weex-nuke
Version:
基于 Rax 、Weex 的高性能组件体系 ~~
41 lines (37 loc) • 1.35 kB
JavaScript
/**
* bridge for call h5 page
* @return {[type]} [description]
*/
import { isQNWeb , appInfo} from 'nuke-env';
const HYBRID_PROTOCOL = 'qap:';
// qap:///application/request/tmda21db31?query={"event":"itemList","biz":{"itemStatus":"onsale"}}
function generateURL(src) {
let parameter = {
url: src,
// appkey:'123123'
};
return HYBRID_PROTOCOL + '///' + 'navigator' + '/' + 'push' + '/' + uuid() + '?query=' + encodeURIComponent(JSON.stringify(parameter));
// return 'tbsellerplatform:// ?session_event=event_protocol&apiName=' + event + '&biz=' + encodeURIComponent(JSON.stringify(parameter));
// return url;
}
function uuid() {
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
var r = Math.random() * 16 | 0;
var v = c == 'x' ? r : (r&0x3|0x8);
return v.toString(16);
});
}
export default function bridge(src){
src = generateURL(src);
if( isQNWeb && appInfo && appInfo.platform === 'android'){
prompt(src);
}else if( isQNWeb && appInfo && appInfo.platform === 'iOS'){
let iframe = document.createElement('iframe');
iframe.setAttribute('frameborder', 0);
iframe.style.cssText = 'display:none';
iframe.src = src;
document.body.appendChild(iframe);
}else{
// do nothing
}
}