Merge branch 'release/wap-optim4' into 'master'
Release/wap optim4 See merge request !44
Showing
5 changed files
with
22 additions
and
13 deletions
@@ -43,17 +43,18 @@ const praiseArticle = (req, res, next) => { | @@ -43,17 +43,18 @@ const praiseArticle = (req, res, next) => { | ||
43 | * 资讯文章收藏 (APP里显示收藏) | 43 | * 资讯文章收藏 (APP里显示收藏) |
44 | */ | 44 | */ |
45 | const collectArticle = (req, res, next) => { | 45 | const collectArticle = (req, res, next) => { |
46 | + let allowOrigin = _.get(req, 'headers.origin', null) ? | ||
47 | + req.headers.origin : req.protocol + '://' + req.headers.host; | ||
48 | + | ||
49 | + res.setHeader('Access-Control-Allow-Origin', allowOrigin); | ||
50 | + res.setHeader('Access-Control-Allow-Credentials', 'true'); | ||
51 | + | ||
46 | let result = { | 52 | let result = { |
47 | code: 400, | 53 | code: 400, |
48 | message: '您未登录,无法收藏或者取消收藏。请先登录!', | 54 | message: '您未登录,无法收藏或者取消收藏。请先登录!', |
49 | data: '' | 55 | data: '' |
50 | }; | 56 | }; |
51 | 57 | ||
52 | - /* 判断是不是AJAX请求 */ | ||
53 | - if (!req.xhr) { | ||
54 | - res.json(result); | ||
55 | - return; | ||
56 | - } | ||
57 | 58 | ||
58 | /* 判断参数是否有效 */ | 59 | /* 判断参数是否有效 */ |
59 | /* 判断用户是否登录 */ | 60 | /* 判断用户是否登录 */ |
@@ -61,6 +62,12 @@ const collectArticle = (req, res, next) => { | @@ -61,6 +62,12 @@ const collectArticle = (req, res, next) => { | ||
61 | opt = req.body.opt || 'ok', | 62 | opt = req.body.opt || 'ok', |
62 | uid = req.body.uid; | 63 | uid = req.body.uid; |
63 | 64 | ||
65 | + /* 判断是不是登录成功 */ | ||
66 | + if (!uid) { | ||
67 | + res.json(result); | ||
68 | + return; | ||
69 | + } | ||
70 | + | ||
64 | if (!stringProcess.isNumeric(id) || !stringProcess.isNumeric(uid)) { | 71 | if (!stringProcess.isNumeric(id) || !stringProcess.isNumeric(uid)) { |
65 | res.json(result); | 72 | res.json(result); |
66 | return; | 73 | return; |
@@ -9,9 +9,7 @@ | @@ -9,9 +9,7 @@ | ||
9 | <span class="like-count">{{count}}</span> | 9 | <span class="like-count">{{count}}</span> |
10 | {{/ like}} | 10 | {{/ like}} |
11 | {{# collect}} | 11 | {{# collect}} |
12 | - <a href={{url}}> | ||
13 | - <i class="iconfont collect-btn{{#isCollected}} collected{{/isCollected}}"></i> | ||
14 | - </a> | 12 | + <i class="iconfont collect-btn{{#isCollected}} collected{{/isCollected}}"></i> |
15 | {{/ collect}} | 13 | {{/ collect}} |
16 | {{# share}} | 14 | {{# share}} |
17 | <a href="{{.}}" class="iconfont share-btn"></a> | 15 | <a href="{{.}}" class="iconfont share-btn"></a> |
@@ -9,9 +9,7 @@ | @@ -9,9 +9,7 @@ | ||
9 | <span class="like-count">{{count}}</span> | 9 | <span class="like-count">{{count}}</span> |
10 | {{/ like}} | 10 | {{/ like}} |
11 | {{# collect}} | 11 | {{# collect}} |
12 | - <a href={{url}}> | ||
13 | - <i class="iconfont collect-btn{{#isCollected}} collected{{/isCollected}}"></i> | ||
14 | - </a> | 12 | + <i class="iconfont collect-btn{{#isCollected}} collected{{/isCollected}}"></i> |
15 | {{/ collect}} | 13 | {{/ collect}} |
16 | {{# share}} | 14 | {{# share}} |
17 | <a href="{{.}}" class="iconfont share-btn"></a> | 15 | <a href="{{.}}" class="iconfont share-btn"></a> |
@@ -164,13 +164,16 @@ function initInfosEvt($container) { | @@ -164,13 +164,16 @@ function initInfosEvt($container) { | ||
164 | 164 | ||
165 | $.ajax({ | 165 | $.ajax({ |
166 | type: 'POST', | 166 | type: 'POST', |
167 | - url: '/guang/opt/collectArticle', | 167 | + url: location.protocol + '//m.yohobuy.com/guang/opt/collectArticle', |
168 | data: { | 168 | data: { |
169 | id: $info.data('id'), | 169 | id: $info.data('id'), |
170 | opt: opt, | 170 | opt: opt, |
171 | yh_channel: yhChannel, | 171 | yh_channel: yhChannel, |
172 | uid: uid | 172 | uid: uid |
173 | }, | 173 | }, |
174 | + xhrFields: { | ||
175 | + withCredentials: true | ||
176 | + }, | ||
174 | success: function(data) { | 177 | success: function(data) { |
175 | if (data.code && data.code === 200) { | 178 | if (data.code && data.code === 200) { |
176 | 179 |
@@ -150,13 +150,16 @@ function initInfosEvt($container) { | @@ -150,13 +150,16 @@ function initInfosEvt($container) { | ||
150 | 150 | ||
151 | $.ajax({ | 151 | $.ajax({ |
152 | type: 'POST', | 152 | type: 'POST', |
153 | - url: '/guang/opt/collectArticle', | 153 | + url: location.protocol + '//m.yohobuy.com/guang/opt/collectArticle', |
154 | data: { | 154 | data: { |
155 | id: $info.data('id'), | 155 | id: $info.data('id'), |
156 | opt: opt, | 156 | opt: opt, |
157 | yh_channel: yhChannel, | 157 | yh_channel: yhChannel, |
158 | uid: getUrlParam('uid') | 158 | uid: getUrlParam('uid') |
159 | }, | 159 | }, |
160 | + xhrFields: { | ||
161 | + withCredentials: true | ||
162 | + }, | ||
160 | success: function(data) { | 163 | success: function(data) { |
161 | if (data.code && data.code === 200) { | 164 | if (data.code && data.code === 200) { |
162 | // 切换收藏状态 | 165 | // 切换收藏状态 |
-
Please register or login to post a comment