Authored by 邱骏

重写login方法,防止与原有SDK冲突

... ... @@ -541,6 +541,30 @@ class featureModel extends global.yoho.BaseModel {
});
}
/**
* 领取活动模板分享的优惠券
* @param activityId
* @param templateId
* @param uid
*/
couponSendWebShare(activityId, templateId, uid) {
let data = {
method: 'app.coupons.sendNewUserShareCoupon',
uid: uid,
activityId: activityId,
templateId: templateId
};
return this.get({data}).then(result => {
if (!result) {
result.code = 404;
result.message = '出错啦~';
}
return result;
});
}
getProductBySkns(skns) {
let obj = {defaultSkns: skns};
... ...
... ... @@ -8,7 +8,7 @@ const cookie = require('yoho-cookie');
const shopTmpl = require('hbs/activity/feature/shop-group.hbs');
const seckillTabTpl = require('hbs/activity/feature/seckill-tab.hbs');
const seckillProductTpl = require('hbs/activity/feature/seckill-product.hbs');
const yo_sdk = require('yoho-activity-sdk');
const yo_sdk = require('./feature/yo-sdk');
require('scss/feature.scss');
... ... @@ -169,6 +169,7 @@ function checkShare(shareData) {
setTimeout(getCoupon, 5000);
}
} else {
getCoupon();
showShare();
if (isWechatMiniProgram) {
setTimeout(getCoupon, 6000);
... ... @@ -237,10 +238,6 @@ function initWxShare(data) {
});
}
}
// yo_sdk.wxShare(shareData);
}
function initWebShareButtons(env = '') { // 初始化分享按钮事件
... ... @@ -404,6 +401,7 @@ function ceXuanFuInit() {
$('#sidebar').load(href + pageid + '.html', function() {
$('.sidebar-img').click(function() {
$('.sidebar').show();
$('.sidebar').show();
});
$('.sidebar').click(function(e) {
var $cur = $(e.target);
... ...
/**
* Created by qiujun on 2019/7/19.
*/
/* global wx */
let enviroment = '';
let parseUrl = function(url) {
let 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('=');
query[hash[0]] = hash[1];
}
}
return {
path: url[0],
query: query
};
};
let createLinkButton = function(url, id) {
let a = document.createElement('a');
a.style.position = 'fixed';
a.style.top = 0;
a.style.left = 0;
a.style.border = 'none';
a.style.outline = 'none';
a.style.resize = 'none';
a.style.background = 'transparent';
a.style.color = 'transparent';
a.setAttribute('id', id);
a.setAttribute('href', url);
document.body.appendChild(a);
return a;
};
let env = function() {
let envFlag = window.__wxjs_environment;
if (!envFlag && navigator.userAgent.match(/yohobuy/i)) {
enviroment = 'app';
document.addEventListener('deviceready', function() {
});
} else if ((!envFlag && navigator.userAgent.match(/miniProgram/i)) || (envFlag === 'miniprogram')) {
enviroment = 'miniprogram';
} else if (location.origin === 'https://www.yohobuy.com') {
enviroment = 'pc';
} else {
enviroment = 'h5';
}
return enviroment;
};
let loginUrl = function() {
let url, refer = location.href;
if (env === 'app') {
url = 'http://m.yohobuy.com/signin.html?refer=' + encodeURIComponent(refer);
refer = parseUrl(refer);
if (/Android/i.test(navigator.userAgent || '')) {
if (url.indexOf('?') < 0) {
url += '?appLogin=1';
}
if (location.href.indexOf('&openby') >= 0) {
url = url.substring(0, url.indexOf('&openby'));
}
url += '&';
} else {
if (location.href.indexOf('#openby') >= 0) {
url = url.substring(0, url.indexOf('#openby'));
}
url += '#';
}
url += 'openby:yohobuy=' + JSON.stringify({
action: 'go.weblogin',
params: {
priority: 'N',
jumpurl: {
url: refer.path,
param: refer.query
},
needlogout: 'Y'
}
});
} else if (env === 'pc') {
url = 'https://www.yoho/signin.html?refer=' + encodeURIComponent(location.href);
} else if (env === 'miniprogram') {
url = '/pages/userCenter/userCenter';
} else {
if (refer.indexOf('?') < 0) {
refer += '?skcall=1';
} else {
refer += '&skcall=1';
}
url = 'http://m.yohobuy.com/signin.html?refer=' + encodeURIComponent(refer);
}
return url;
};
let Login = function(obj) {
let _this = this;
_this.env = obj.env;
_this.url = obj.loginUrl;
_this.goLogin = function(url) {
url = url || _this.url;
if (_this.env === 'miniprogram') {
wx.miniProgram.switchTab({url: url});
} else if (_this.env === 'app') {
let loginButton = document.getElementById('yosdk-login');
if (!loginButton) {
loginButton = createLinkButton(url, 'yosdk-login');
}
loginButton.click();
} else {
window.location.href = url;
}
return false;
};
_this.auth = function(nodeList, user) {
if (!user.uid) {
[].forEach.call(nodeList, function(value) {
value.onclick = function(event) {
event.preventDefault();
_this.goLogin();
};
});
return true;
}
};
};
let login = new Login({loginUrl: loginUrl(), env: env()});
module.exports = {
goLogin: login.goLogin.bind(login)
};
... ...