Authored by 邱骏

修改分享逻辑

1 <!--活动模板分享领券组件--> 1 <!--活动模板分享领券组件-->
2 <div class="web-share"> 2 <div class="web-share">
3 - {{log .}}  
4 {{#webShare}} 3 {{#webShare}}
5 <a href="javascript:void(0)" class="web-share-button" data-stid="{{../share_template_id}}" data-scoupon="{{../share_condition}}" 4 <a href="javascript:void(0)" class="web-share-button" data-stid="{{../share_template_id}}" data-scoupon="{{../share_condition}}"
6 data-spic="{{pic}}" data-sdesc="{{content}}" data-stitle="{{title}}" data-surl="{{url}}"></a> 5 data-spic="{{pic}}" data-sdesc="{{content}}" data-stitle="{{title}}" data-surl="{{url}}"></a>
@@ -207,7 +207,42 @@ function goLogin(shareData) { // 跳转登录判断 @@ -207,7 +207,42 @@ function goLogin(shareData) { // 跳转登录判断
207 } 207 }
208 } 208 }
209 209
  210 +
  211 +function initWxShare(data) {
  212 + let shareData = {
  213 + title: data.title,
  214 + imgUrl: data.imgUrl,
  215 + desc: data.desc,
  216 + link: data.link,
  217 + success: function() {
  218 + setTimeout(getCoupon, 500);
  219 + }
  220 + };
  221 +
  222 + yo_sdk.wxShare(shareData);
  223 +}
  224 +
210 function initWebShareButtons(env = '') { // 初始化分享按钮事件 225 function initWebShareButtons(env = '') { // 初始化分享按钮事件
  226 + let webShareData = {
  227 + title: $('#shareTitle').val(),
  228 + desc: $('#shareImg').val(),
  229 + imgUrl: $('#shareDesc').val(),
  230 + link: $('#shareLink').val()
  231 + };
  232 +
  233 + if ($('.web-share-button')[0]) {
  234 + let webShareButton = $('.web-share-button');
  235 +
  236 + webShareData = {
  237 + title: webShareButton.data('stitle'),
  238 + desc: webShareButton.data('sdesc'),
  239 + imgUrl: webShareButton.data('spic'),
  240 + link: webShareButton.data('surl').replace('https://activity.yoho.cn', 'http://m.yohobuy.com/activity')
  241 + };
  242 + }
  243 +
  244 + initWxShare(webShareData);
  245 +
211 $('.web-share-button').each(function() { 246 $('.web-share-button').each(function() {
212 let webShareButton = $(this); 247 let webShareButton = $(this);
213 248
@@ -217,13 +252,18 @@ function initWebShareButtons(env = '') { // 初始化分享按钮事件 @@ -217,13 +252,18 @@ function initWebShareButtons(env = '') { // 初始化分享按钮事件
217 return; 252 return;
218 } 253 }
219 getParams(); 254 getParams();
220 - let webShareData = { 255 + webShareData = {
221 title: webShareButton.data('stitle'), 256 title: webShareButton.data('stitle'),
222 desc: webShareButton.data('sdesc'), 257 desc: webShareButton.data('sdesc'),
223 imgUrl: webShareButton.data('spic'), 258 imgUrl: webShareButton.data('spic'),
224 link: webShareButton.data('surl').replace('https://activity.yoho.cn', 'http://m.yohobuy.com/activity') 259 link: webShareButton.data('surl').replace('https://activity.yoho.cn', 'http://m.yohobuy.com/activity')
225 }; 260 };
226 261
  262 + $('#shareTitle').val(webShareData.title);
  263 + $('#shareImg').val(webShareData.desc);
  264 + $('#shareDesc').val(webShareData.imgUrl);
  265 + $('#shareLink').val(webShareData.link);
  266 +
227 if (isApp) { 267 if (isApp) {
228 Object.assign(webShareData, { 268 Object.assign(webShareData, {
229 hideType: ['4', '5', '6', '7', '8', '9'], 269 hideType: ['4', '5', '6', '7', '8', '9'],
@@ -243,20 +283,6 @@ function initWebShareButtons(env = '') { // 初始化分享按钮事件 @@ -243,20 +283,6 @@ function initWebShareButtons(env = '') { // 初始化分享按钮事件
243 $('.web-share-img-wrapper').on('click', hideShare); 283 $('.web-share-img-wrapper').on('click', hideShare);
244 } 284 }
245 285
246 -function initWxShare() {  
247 - let shareData = {  
248 - title: $('#shareTitle').val(),  
249 - imgUrl: $('#shareImg').val(),  
250 - desc: $('#shareDesc').val(),  
251 - link: $('#shareLink').val(),  
252 - success: function() {  
253 - setTimeout(getCoupon, 500);  
254 - }  
255 - };  
256 -  
257 - yo_sdk.wxShare(shareData);  
258 -}  
259 -  
260 // 分享领券模板功能初始化 286 // 分享领券模板功能初始化
261 function initWebShare() { 287 function initWebShare() {
262 getParams(); 288 getParams();
@@ -272,7 +298,6 @@ function initWebShare() { @@ -272,7 +298,6 @@ function initWebShare() {
272 $('.web-share-buttons-container .button-download').hide(); 298 $('.web-share-buttons-container .button-download').hide();
273 initWebShareButtons('miniprogram'); 299 initWebShareButtons('miniprogram');
274 } else if (isWechat) { 300 } else if (isWechat) {
275 - initWxShare();  
276 initWebShareButtons('wechat'); 301 initWebShareButtons('wechat');
277 } else { 302 } else {
278 initWebShareButtons(); 303 initWebShareButtons();