Authored by huangyi

有赚兼容小程序

... ... @@ -15,14 +15,14 @@
<span class="people">获得优惠券</span>
</div>
<div class="eps">
<div class="accede-btn"><a href="{{url}}">了解详情</a></div>
<div class="accede-btn" data-url="{{url}}">了解详情</div>
</div>
{{else}}
<div class="eps">
邀请好友购物返现金
</div>
<div class="eps">
<div class="accede-btn"><a href="{{url}}">立即加入</a></div>
<div class="accede-btn" data-url="{{url}}">立即加入</div>
</div>
{{/if}}
</div>
... ...
... ... @@ -8,6 +8,7 @@ import yoho from 'js/yoho-app';
import parse from 'yoho-qs/parse';
import Clipboard from 'clipboard';
import cookie from 'yoho-cookie';
import linkTo from '../../../utils/linkTo';
class HaveGainApplyPage extends Page {
constructor() {
... ... @@ -200,7 +201,20 @@ class HaveGainApplyPage extends Page {
$event.hasClass('activate') ? $event.removeClass('activate') : $event.addClass('activate');
}
clickFun() {
let env = linkTo.getEnv();
if (env === 'miniprogram') {
window.wx.miniProgram.switchTab({url: '/pages/index/index'});
} else {
let btn = !!document.getElementById('yoho-verify');
if (!btn) {
btn = linkTo.createLinkButton('http://m.yohobuy.com/activity/have-gain/verify', 'yoho-verify');
}
btn.click();
}
}
apply() {
let errStatus = this.changeBtnStatus();
let socialMediaList = [];
... ... @@ -270,11 +284,7 @@ class HaveGainApplyPage extends Page {
leftBtnText: '取消',
rightBtnText: '确定'
}
}, function() {
window.location.href = '//m.yohobuy.com/activity/have-gain/verify';
}, function() {
window.location.href = '//m.yohobuy.com/activity/have-gain/verify';
});
}, this.clickFun, this.clickFun);
}).catch(() => {
this.selector.isFlag = false;
});
... ...
import 'scss/activity/have-gain-index.page.scss';
import linkTo from '../../../utils/linkTo';
import $ from 'yoho-jquery';
import Page from 'js/yoho-page';
class HaveGainIndexyPage extends Page {
constructor() {
super();
this.selector = {
$accedeBtn: $('.accede-btn'),
};
this.init();
}
init() {
this.selector.$accedeBtn.click(function() {
const $this = $(this);
let url = $this.data('url');
if (linkTo.getEnv() === 'miniprogram') {
linkTo.linkToMiniApp(url);
} else {
let btn = !!document.getElementById('yoho-apply');
if (!btn) {
btn = linkTo.createLinkButton(url, 'yoho-apply');
}
btn.click();
}
});
}
}
$(() => {
new HaveGainIndexyPage();
});
... ...
const getQueryObj = function(link) {
let loc = decodeURIComponent(document.location.href);
if (link) {
loc = decodeURIComponent(link);
}
let letiables = '';
let letiableArr = [];
let finalArr = [];
if (loc.indexOf('?') > 0) {
letiables = loc.split('?')[1];
}
if (letiables.length > 0) {
letiableArr = letiables.split('#')[0].split('&');
}
for (let i = 0; i < letiableArr.length; i++) {
let obj = {};
obj.name = letiableArr[i].split('=')[0];
obj.value = letiableArr[i].split('=')[1];
if (letiableArr[i].split('=').length > 2) {
for (let j = 2; j < letiableArr[i].split('=').length; j++) {
obj.value += '=' + letiableArr[i].split('=')[j];
}
}
finalArr.push(obj);
}
let query_obj = {};
for (let i = 0; i < finalArr.length; i++) {
query_obj[finalArr[i].name] = finalArr[i].value;
}
return query_obj;
};
const linkToMiniApp = function(goUrl, type) {
let url = goUrl || '';
if (url && url.indexOf('http') < 0 && type === 'other') {
url = document.location.protocol + '//' + document.location.host + url;
}
if (url) {
let scene;
if (type === 'product' || type === 'brand') {
scene = url;
} else {
let base_url = decodeURIComponent(url).split('?')[0];
let params = getQueryObj(url);
let paramStr = '';
Object.keys(params).forEach(function(key) {
paramStr += paramStr === '' ? '?' + key + '=' + params[key] : '&' + key + '=' + params[key];
});
scene = '/pages/webview/webview?url=' + base_url + encodeURIComponent(paramStr);
}
window.wx.miniProgram.navigateTo({url: scene});
return false;
} else {
return true;
}
};
const 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 = '';
const getEnv = function() {
let envFlag = window.__wxjs_environment;
if (!envFlag && navigator.userAgent.match(/yohobuy/i)) {
env = 'app';
document.addEventListener('deviceready', function() {
});
} else if ((!envFlag && navigator.userAgent.match(/miniProgram/i)) || (envFlag === 'miniprogram')) {
env = 'miniprogram';
} else if (location.origin === 'https://www.yohobuy.com') {
env = 'pc';
} else {
env = 'h5';
}
return env;
};
module.exports = {
linkToMiniApp,
createLinkButton,
getEnv
};
... ...