Showing
4 changed files
with
162 additions
and
7 deletions
@@ -15,14 +15,14 @@ | @@ -15,14 +15,14 @@ | ||
15 | <span class="people">获得优惠券</span> | 15 | <span class="people">获得优惠券</span> |
16 | </div> | 16 | </div> |
17 | <div class="eps"> | 17 | <div class="eps"> |
18 | - <div class="accede-btn"><a href="{{url}}">了解详情</a></div> | 18 | + <div class="accede-btn" data-url="{{url}}">了解详情</div> |
19 | </div> | 19 | </div> |
20 | {{else}} | 20 | {{else}} |
21 | <div class="eps"> | 21 | <div class="eps"> |
22 | 邀请好友购物返现金 | 22 | 邀请好友购物返现金 |
23 | </div> | 23 | </div> |
24 | <div class="eps"> | 24 | <div class="eps"> |
25 | - <div class="accede-btn"><a href="{{url}}">立即加入</a></div> | 25 | + <div class="accede-btn" data-url="{{url}}">立即加入</div> |
26 | </div> | 26 | </div> |
27 | {{/if}} | 27 | {{/if}} |
28 | </div> | 28 | </div> |
@@ -8,6 +8,7 @@ import yoho from 'js/yoho-app'; | @@ -8,6 +8,7 @@ import yoho from 'js/yoho-app'; | ||
8 | import parse from 'yoho-qs/parse'; | 8 | import parse from 'yoho-qs/parse'; |
9 | import Clipboard from 'clipboard'; | 9 | import Clipboard from 'clipboard'; |
10 | import cookie from 'yoho-cookie'; | 10 | import cookie from 'yoho-cookie'; |
11 | +import linkTo from '../../../utils/linkTo'; | ||
11 | 12 | ||
12 | class HaveGainApplyPage extends Page { | 13 | class HaveGainApplyPage extends Page { |
13 | constructor() { | 14 | constructor() { |
@@ -200,7 +201,20 @@ class HaveGainApplyPage extends Page { | @@ -200,7 +201,20 @@ class HaveGainApplyPage extends Page { | ||
200 | 201 | ||
201 | $event.hasClass('activate') ? $event.removeClass('activate') : $event.addClass('activate'); | 202 | $event.hasClass('activate') ? $event.removeClass('activate') : $event.addClass('activate'); |
202 | } | 203 | } |
204 | + clickFun() { | ||
205 | + let env = linkTo.getEnv(); | ||
203 | 206 | ||
207 | + if (env === 'miniprogram') { | ||
208 | + window.wx.miniProgram.switchTab({url: '/pages/index/index'}); | ||
209 | + } else { | ||
210 | + let btn = !!document.getElementById('yoho-verify'); | ||
211 | + | ||
212 | + if (!btn) { | ||
213 | + btn = linkTo.createLinkButton('http://m.yohobuy.com/activity/have-gain/verify', 'yoho-verify'); | ||
214 | + } | ||
215 | + btn.click(); | ||
216 | + } | ||
217 | + } | ||
204 | apply() { | 218 | apply() { |
205 | let errStatus = this.changeBtnStatus(); | 219 | let errStatus = this.changeBtnStatus(); |
206 | let socialMediaList = []; | 220 | let socialMediaList = []; |
@@ -270,11 +284,7 @@ class HaveGainApplyPage extends Page { | @@ -270,11 +284,7 @@ class HaveGainApplyPage extends Page { | ||
270 | leftBtnText: '取消', | 284 | leftBtnText: '取消', |
271 | rightBtnText: '确定' | 285 | rightBtnText: '确定' |
272 | } | 286 | } |
273 | - }, function() { | ||
274 | - window.location.href = '//m.yohobuy.com/activity/have-gain/verify'; | ||
275 | - }, function() { | ||
276 | - window.location.href = '//m.yohobuy.com/activity/have-gain/verify'; | ||
277 | - }); | 287 | + }, this.clickFun, this.clickFun); |
278 | }).catch(() => { | 288 | }).catch(() => { |
279 | this.selector.isFlag = false; | 289 | this.selector.isFlag = false; |
280 | }); | 290 | }); |
1 | import 'scss/activity/have-gain-index.page.scss'; | 1 | import 'scss/activity/have-gain-index.page.scss'; |
2 | +import linkTo from '../../../utils/linkTo'; | ||
3 | +import $ from 'yoho-jquery'; | ||
4 | +import Page from 'js/yoho-page'; | ||
5 | + | ||
6 | +class HaveGainIndexyPage extends Page { | ||
7 | + constructor() { | ||
8 | + super(); | ||
9 | + this.selector = { | ||
10 | + $accedeBtn: $('.accede-btn'), | ||
11 | + }; | ||
12 | + this.init(); | ||
13 | + } | ||
14 | + | ||
15 | + init() { | ||
16 | + this.selector.$accedeBtn.click(function() { | ||
17 | + const $this = $(this); | ||
18 | + let url = $this.data('url'); | ||
19 | + | ||
20 | + if (linkTo.getEnv() === 'miniprogram') { | ||
21 | + linkTo.linkToMiniApp(url); | ||
22 | + } else { | ||
23 | + let btn = !!document.getElementById('yoho-apply'); | ||
24 | + | ||
25 | + if (!btn) { | ||
26 | + btn = linkTo.createLinkButton(url, 'yoho-apply'); | ||
27 | + } | ||
28 | + btn.click(); | ||
29 | + | ||
30 | + } | ||
31 | + }); | ||
32 | + } | ||
33 | +} | ||
34 | + | ||
35 | +$(() => { | ||
36 | + new HaveGainIndexyPage(); | ||
37 | +}); |
utils/linkTo.js
0 → 100644
1 | + | ||
2 | +const getQueryObj = function(link) { | ||
3 | + let loc = decodeURIComponent(document.location.href); | ||
4 | + | ||
5 | + if (link) { | ||
6 | + loc = decodeURIComponent(link); | ||
7 | + } | ||
8 | + let letiables = ''; | ||
9 | + let letiableArr = []; | ||
10 | + let finalArr = []; | ||
11 | + | ||
12 | + if (loc.indexOf('?') > 0) { | ||
13 | + letiables = loc.split('?')[1]; | ||
14 | + } | ||
15 | + | ||
16 | + if (letiables.length > 0) { | ||
17 | + letiableArr = letiables.split('#')[0].split('&'); | ||
18 | + } | ||
19 | + | ||
20 | + for (let i = 0; i < letiableArr.length; i++) { | ||
21 | + let obj = {}; | ||
22 | + | ||
23 | + obj.name = letiableArr[i].split('=')[0]; | ||
24 | + obj.value = letiableArr[i].split('=')[1]; | ||
25 | + if (letiableArr[i].split('=').length > 2) { | ||
26 | + for (let j = 2; j < letiableArr[i].split('=').length; j++) { | ||
27 | + obj.value += '=' + letiableArr[i].split('=')[j]; | ||
28 | + } | ||
29 | + } | ||
30 | + finalArr.push(obj); | ||
31 | + } | ||
32 | + | ||
33 | + let query_obj = {}; | ||
34 | + | ||
35 | + for (let i = 0; i < finalArr.length; i++) { | ||
36 | + query_obj[finalArr[i].name] = finalArr[i].value; | ||
37 | + } | ||
38 | + | ||
39 | + return query_obj; | ||
40 | +}; | ||
41 | + | ||
42 | +const linkToMiniApp = function(goUrl, type) { | ||
43 | + | ||
44 | + let url = goUrl || ''; | ||
45 | + | ||
46 | + if (url && url.indexOf('http') < 0 && type === 'other') { | ||
47 | + url = document.location.protocol + '//' + document.location.host + url; | ||
48 | + } | ||
49 | + if (url) { | ||
50 | + let scene; | ||
51 | + | ||
52 | + if (type === 'product' || type === 'brand') { | ||
53 | + scene = url; | ||
54 | + } else { | ||
55 | + let base_url = decodeURIComponent(url).split('?')[0]; | ||
56 | + let params = getQueryObj(url); | ||
57 | + let paramStr = ''; | ||
58 | + | ||
59 | + Object.keys(params).forEach(function(key) { | ||
60 | + paramStr += paramStr === '' ? '?' + key + '=' + params[key] : '&' + key + '=' + params[key]; | ||
61 | + }); | ||
62 | + scene = '/pages/webview/webview?url=' + base_url + encodeURIComponent(paramStr); | ||
63 | + } | ||
64 | + window.wx.miniProgram.navigateTo({url: scene}); | ||
65 | + return false; | ||
66 | + } else { | ||
67 | + return true; | ||
68 | + } | ||
69 | +}; | ||
70 | + | ||
71 | +const createLinkButton = function(url, id) { | ||
72 | + let a = document.createElement('a'); | ||
73 | + | ||
74 | + a.style.position = 'fixed'; | ||
75 | + a.style.top = 0; | ||
76 | + a.style.left = 0; | ||
77 | + a.style.border = 'none'; | ||
78 | + a.style.outline = 'none'; | ||
79 | + a.style.resize = 'none'; | ||
80 | + a.style.background = 'transparent'; | ||
81 | + a.style.color = 'transparent'; | ||
82 | + a.setAttribute('id', id); | ||
83 | + a.setAttribute('href', url); | ||
84 | + document.body.appendChild(a); | ||
85 | + return a; | ||
86 | +}; | ||
87 | +let env = ''; | ||
88 | +const getEnv = function() { | ||
89 | + let envFlag = window.__wxjs_environment; | ||
90 | + | ||
91 | + if (!envFlag && navigator.userAgent.match(/yohobuy/i)) { | ||
92 | + env = 'app'; | ||
93 | + document.addEventListener('deviceready', function() { | ||
94 | + }); | ||
95 | + } else if ((!envFlag && navigator.userAgent.match(/miniProgram/i)) || (envFlag === 'miniprogram')) { | ||
96 | + env = 'miniprogram'; | ||
97 | + } else if (location.origin === 'https://www.yohobuy.com') { | ||
98 | + env = 'pc'; | ||
99 | + } else { | ||
100 | + env = 'h5'; | ||
101 | + } | ||
102 | + return env; | ||
103 | +}; | ||
104 | + | ||
105 | +module.exports = { | ||
106 | + linkToMiniApp, | ||
107 | + createLinkButton, | ||
108 | + getEnv | ||
109 | +}; |
-
Please register or login to post a comment