...
|
...
|
@@ -8,6 +8,7 @@ |
|
|
*
|
|
|
* 希望能与 微信 JS-SDK 一样方便
|
|
|
*/
|
|
|
var $ = require('yoho-jquery');
|
|
|
var tip = require('./plugin/tip');
|
|
|
|
|
|
/* 空方法 */
|
...
|
...
|
@@ -16,11 +17,22 @@ var emptyFn = function() { }; |
|
|
/* 提示信息 */
|
|
|
var tipInfo = '暂不支持,请在YOHO!BUY应用中打开';
|
|
|
|
|
|
var yoho = {
|
|
|
var qs = window.queryString;
|
|
|
|
|
|
var yoho, $appLink;
|
|
|
|
|
|
$appLink = $('#yoho-app-link');
|
|
|
|
|
|
if (!$appLink.length) {
|
|
|
$('body').append('<a id="yoho-app-link" href="javascript:;" style="display:none !important;"></a>');
|
|
|
$appLink = $('#yoho-app-link');
|
|
|
}
|
|
|
|
|
|
yoho = {
|
|
|
/**
|
|
|
* 判断是否是 APP
|
|
|
*/
|
|
|
isApp: /YohoBuy/i.test(navigator.userAgent || ''),
|
|
|
isApp: /YohoBuy/i.test(navigator.userAgent || '') || qs.app_version,
|
|
|
isiOS: /\(i[^;]+;( U;)? CPU.+Mac OS X/i.test(navigator.userAgent || ''),
|
|
|
isAndroid: /Android/i.test(navigator.userAgent || ''),
|
|
|
|
...
|
...
|
@@ -73,12 +85,85 @@ var yoho = { |
|
|
}, 500);
|
|
|
},
|
|
|
|
|
|
parseUrl: function(url) {
|
|
|
var query = {},
|
|
|
hashs,
|
|
|
hash,
|
|
|
i;
|
|
|
|
|
|
url = (url || '').split('?');
|
|
|
hashs = url[1].split('&');
|
|
|
|
|
|
if (hashs && hashs.length) {
|
|
|
for (i = 0; i < hashs.length; i++) {
|
|
|
hash = hashs[i].split('=');
|
|
|
console.log(hashs[i]);
|
|
|
query[hash[0]] = hash[1];
|
|
|
}
|
|
|
}
|
|
|
|
|
|
return {
|
|
|
path: url[0],
|
|
|
query: query
|
|
|
};
|
|
|
},
|
|
|
|
|
|
getUid: function() {
|
|
|
if (window.queryString.app_version) {
|
|
|
return window.queryString.uid || 0;
|
|
|
if (yoho.isApp) {
|
|
|
return qs.uid;
|
|
|
}
|
|
|
|
|
|
return window.gitUid();
|
|
|
},
|
|
|
|
|
|
goLogin: function(refer, data) {
|
|
|
var url;
|
|
|
|
|
|
url = 'http://m.yohobuy.com/signin.html?refer=' + encodeURIComponent(refer);
|
|
|
refer = yoho.parseUrl(refer || location.href);
|
|
|
|
|
|
if (yoho.isApp) {
|
|
|
url = url + '&openby:yohobuy=' + (data || JSON.stringify({
|
|
|
action: 'go.weblogin',
|
|
|
params: {
|
|
|
priority: 'N',
|
|
|
jumpurl: {
|
|
|
url: refer.path,
|
|
|
param: refer.query
|
|
|
}
|
|
|
}
|
|
|
}));
|
|
|
}
|
|
|
|
|
|
$appLink.attr('href', url);
|
|
|
$appLink[0].click();
|
|
|
return false;
|
|
|
},
|
|
|
|
|
|
goH5: function(link, data) {
|
|
|
var url = link;
|
|
|
|
|
|
if (!link) {
|
|
|
return;
|
|
|
}
|
|
|
link = yoho.parseUrl(link || location.href);
|
|
|
|
|
|
if (yoho.isApp) {
|
|
|
url = url + '&openby:yohobuy=' + (data || JSON.stringify({
|
|
|
action: 'go.h5',
|
|
|
params: {
|
|
|
islogin: 'N',
|
|
|
type: 0,
|
|
|
updateflag: Date.now() + '',
|
|
|
url: link.path,
|
|
|
param: link.query
|
|
|
}
|
|
|
}));
|
|
|
}
|
|
|
|
|
|
return window.getUid() || 0;
|
|
|
$appLink.attr('href', url);
|
|
|
$appLink[0].click();
|
|
|
return false;
|
|
|
}
|
|
|
};
|
|
|
|
...
|
...
|
|