...
|
...
|
@@ -3,6 +3,8 @@ |
|
|
*/
|
|
|
const qs = require('yoho-qs');
|
|
|
const cookie = require('yoho-cookie');
|
|
|
const dialog = require('js/plugin/dialog');
|
|
|
const yoho = require('js/yoho-app');
|
|
|
|
|
|
const u = navigator.userAgent;
|
|
|
const isFromYOHO = /m\.yohobuy\.com/i.test(document.referrer);
|
...
|
...
|
@@ -49,7 +51,7 @@ const getMktcBySeo = function() { |
|
|
};
|
|
|
|
|
|
const getMktc = () => {
|
|
|
return qs.mkt_code || qs.union_type || getMktcBySeo() || '100000000000349';
|
|
|
return qs.mkt_code || qs.union_type || cookie.get('unionTypeYas') || getMktcBySeo() || '100000000000349';
|
|
|
};
|
|
|
|
|
|
const canOpenApp = () => {
|
...
|
...
|
@@ -76,36 +78,117 @@ const getAppPath = () => { |
|
|
};
|
|
|
|
|
|
|
|
|
if (canOpenApp()) {
|
|
|
setTimeout(function() {
|
|
|
// if (window._yas && window._yas.sendCustomInfo) {
|
|
|
// window._yas.sendCustomInfo({
|
|
|
// op: 'YB_H5_AWAKE_APP',
|
|
|
// param: JSON.stringify({
|
|
|
// PAGE_NAME: encodeURIComponent(document.title),
|
|
|
// PAGE_URL: encodeURIComponent(location.href)
|
|
|
// })
|
|
|
// }, true);
|
|
|
// }
|
|
|
window._getMktCode = getMktc;
|
|
|
|
|
|
if (window._hmt && window._hmt.push) {
|
|
|
window._hmt.push(['_trackEvent', 'H5唤起APP', isiOS ? 'Apple' : 'Android', document.title, location.href]);
|
|
|
const getIOSVersion = () => {
|
|
|
const verion = navigator.appVersion.match(/OS (\d+)_(\d+)_?(\d+)?/);
|
|
|
|
|
|
return parseInt(verion[1], 10);
|
|
|
};
|
|
|
const ua = navigator.userAgent;
|
|
|
const isOriginalChrome = /chrome\/[\d.]+ Mobile Safari\/[\d.]+/i.test(ua) &&
|
|
|
yoho.isAndroid &&
|
|
|
ua.indexOf('Version') < 0;
|
|
|
|
|
|
|
|
|
const getFallUrl = (schemeUrl) => {
|
|
|
let clientId = cookie.get('_yasvd');
|
|
|
let unionTypeYas = cookie.get('unionTypeYas');
|
|
|
const appPath = (schemeUrl || '').replace('yohobuy://yohobuy.com/goapp?', '') || 'openby:yohobuy={"action":"go.home","params":{"gender":"1","channel":"2"}}';
|
|
|
|
|
|
return `https://union.yoho.cn/union/app-downloads.html?union_type=${unionTypeYas}&client_id=${clientId}&${appPath}`;
|
|
|
};
|
|
|
|
|
|
const checkOpenFall = (url, callFunc, noFall) => {
|
|
|
let time = Date.now();
|
|
|
|
|
|
callFunc();
|
|
|
|
|
|
const fallUrl = getFallUrl(url);
|
|
|
|
|
|
if (noFall) {
|
|
|
return;
|
|
|
}
|
|
|
window.setTimeout(function() {
|
|
|
if (Date.now() - time < 1200) {
|
|
|
window.location.href = fallUrl;
|
|
|
}
|
|
|
}, 1000);
|
|
|
};
|
|
|
|
|
|
setTimeout(function() {
|
|
|
let appPath = getAppPath();
|
|
|
let ifr;
|
|
|
const callIframe = (url, noFall) => {
|
|
|
checkOpenFall(url, () => {
|
|
|
const ifr = document.createElement('iframe');
|
|
|
|
|
|
if (isiOS) {
|
|
|
window.location.href = appPath;
|
|
|
} else {
|
|
|
ifr = document.createElement('iframe');
|
|
|
ifr.src = appPath;
|
|
|
ifr.src = url;
|
|
|
ifr.style.display = 'none';
|
|
|
document.body.appendChild(ifr);
|
|
|
}, noFall);
|
|
|
};
|
|
|
|
|
|
const callUrl = (url, noFall) => {
|
|
|
checkOpenFall(url, () => {
|
|
|
window.location.href = url;
|
|
|
}, noFall);
|
|
|
};
|
|
|
|
|
|
const callA = (url, noFall) => {
|
|
|
checkOpenFall(url, () => {
|
|
|
const ca = document.createElement('a');
|
|
|
|
|
|
ca.setAttribute('href', url);
|
|
|
ca.style.display = 'none';
|
|
|
document.body.appendChild(ca);
|
|
|
|
|
|
ca.click();
|
|
|
}, noFall);
|
|
|
};
|
|
|
|
|
|
|
|
|
export const toAppPage = (appUrl, noFall) => {
|
|
|
if (isOriginalChrome) {
|
|
|
callA(appUrl, noFall);
|
|
|
} else if (yoho.isiOS) {
|
|
|
if (getIOSVersion() < 9) {
|
|
|
callIframe(appUrl, noFall);
|
|
|
} else {
|
|
|
callUrl(appUrl, noFall);
|
|
|
}
|
|
|
} else {
|
|
|
callIframe(appUrl, noFall);
|
|
|
}
|
|
|
};
|
|
|
|
|
|
export const toAppPageDialog = (options) => {
|
|
|
dialog.showDialog({
|
|
|
dialogText: options.title,
|
|
|
hasFooter: {
|
|
|
rightBtnText: '打开Yoho!Buy有货APP'
|
|
|
}
|
|
|
}, function() {
|
|
|
toAppPage(options.appUrl);
|
|
|
}, null, true);
|
|
|
};
|
|
|
|
|
|
|
|
|
export const openApp = () => {
|
|
|
if (canOpenApp()) {
|
|
|
setTimeout(function() {
|
|
|
if (window._hmt && window._hmt.push) {
|
|
|
window._hmt.push(['_trackEvent',
|
|
|
'H5唤起APP',
|
|
|
isiOS ? 'Apple' : 'Android',
|
|
|
document.title,
|
|
|
location.href]);
|
|
|
}
|
|
|
}, 1000);
|
|
|
|
|
|
setTimeout(function() {
|
|
|
let appPath = getAppPath();
|
|
|
|
|
|
toAppPage(appPath, true);
|
|
|
}, 2000);
|
|
|
}
|
|
|
}
|
|
|
};
|
|
|
|
|
|
window._getMktCode = getMktc; |
|
|
openApp(); |
...
|
...
|
|