Authored by TaoHuang

feat(captcha): add captcha width send coupon

... ... @@ -11,8 +11,11 @@
<div id="coupon1" class="yoho-conpon" data-token="wangdachui233" data-type="ufo">
<a href="javascript:;">点我领取UFO优惠券</a>
</div>
<div class="yoho-tencentCaptcha" data-appid="2008945059" data-on="1">
<div>
<script src="https://cdn.staticfile.org/jquery/3.3.1/jquery.min.js"></script>
<script src="//cdn.yoho.cn/js-sdk/1.3.15/jssdk.js"></script>
<script src="../dist/js-sdk/1.3.26-beta1/jssdk.js"></script>
<script>
function onChange(e) {
$('#coupon1').data('token', e.target.value)
... ...
{
"name": "yoho-js-sdk",
"version": "1.3.24",
"version": "1.3.26-beta1",
"description": "YOHO!前端js的功能封装包,主要用于在活动页面中,对主要功能的封装。",
"keywords": [
"YOHO!",
... ...
... ... @@ -23,7 +23,10 @@
</head>
<body>
<h1>测试 Token </h1>
<a class="auth yoho-conpon" href="javascript:;" data-token="50f033ab37c3">
<div class="yoho-tencentCaptcha" data-appid="2008945059" data-open="1">
<div>
<a class="yoho-conpon yoho-captcha" href="javascript:;" data-token="50f033ab37c3" data-type="1">
<h1>50f033ab37c3</h1>
</a>
<hr>
... ... @@ -203,6 +206,6 @@
</div>
</div>
<script src="//cdn.bootcss.com/jquery/1.8.3/jquery.min.js"></script>
<script src="../dist/js-sdk/1.3.13/jssdk.js"></script>
<script src="../dist/js-sdk/1.3.26-beta1/jssdk.js"></script>
</body>
</html>
... ...
import $ from 'jquery';
const url = 'https://ssl.captcha.qq.com/TCaptcha.js';
function _initScript() {
return $.getScript(url);
}
const store = {
appId: '',
open: 0
};
export default {
init() {
let $tencentCaptcha = $('.yoho-tencentCaptcha');
store.appId = $tencentCaptcha.data('appid');
store.open = Number($tencentCaptcha.data('open'));
if (store.appId) {
return _initScript();
}
return $.Deferred().resolve();
},
isOn() {
return store.open;
},
getInstance(cb) {
console.log(store);
return new TencentCaptcha(store.appId+'', cb, {});
}
};
... ...
... ... @@ -7,13 +7,16 @@ import share from './share';
import openapp from './openapp';
import promotion from './promotion';
import individuation from './individuation';
import captcha from './captcha';
$(function() {
openapp.init();
user.init().then(uid => {
individuation.init(uid); // 个性化推荐
captcha.init().then(() => {
promotion.init(uid); // 促销
});
user.auth(); // 权限验证
share.init(); // 分享
utils.init();
... ...
... ... @@ -7,6 +7,7 @@ import utils from './utils';
import user from './user';
import cookies from './cookies';
import jsonp from './jsonp';
import captcha from './captcha';
const miniAppEntrance = '/pages/common/webback';
... ... @@ -269,30 +270,56 @@ let _initCoupon = function(uid) {
if (uid) {
let conpontoken = cookies.cookie('yoho-conpon-token');
let coupontype = cookies.cookie('yoho-conpon-type');
let couponCaptcha = Number(cookies.cookie('yoho-conpon-captcha'));
if (conpontoken) {
if (couponCaptcha || captcha.isOn()) {
let captchaInstance = captcha.getInstance((result) => {
if (result.ret === 0) {
_getCoupon({
token: conpontoken,
uid: uid,
coupontype
coupontype,
ticket: result.ticket,
randstr: result.randstr
});
}
});
captchaInstance.show();
}
cookies.setCookie('yoho-conpon-token', '');
cookies.setCookie('yoho-conpon-type', '');
cookies.setCookie('yoho-conpon-captcha', '');
}
}
$('body').on('click', '.yoho-conpon', function() {
let token = $(this).data('token');
let type = $(this).data('type');
let isCaptcha = $(this).hasClass('yoho-captcha') ? 1 : 0;
if (user.uid) {
if (isCaptcha || captcha.isOn()) {
let captchaInstance = captcha.getInstance((result) => {
if (result.ret === 0) {
_getCoupon({
token: token,
uid: user.uid,
coupontype: type
coupontype: type,
ticket: result.ticket,
randstr: result.randstr
});
}
});
captchaInstance.show();
}
} else {
cookies.setCookie('yoho-conpon-token', token);
cookies.setCookie('yoho-conpon-type', type);
cookies.setCookie('yoho-conpon-captcha', isCaptcha);
gotoLogin();
return;
... ...