Showing
7 changed files
with
104 additions
and
67 deletions
@@ -6,10 +6,8 @@ | @@ -6,10 +6,8 @@ | ||
6 | 'use strict'; | 6 | 'use strict'; |
7 | 7 | ||
8 | const mRoot = '../models'; | 8 | const mRoot = '../models'; |
9 | -const library = '../../../library'; | ||
10 | const _ = require('lodash'); | 9 | const _ = require('lodash'); |
11 | const starModel = require(`${mRoot}/star`); | 10 | const starModel = require(`${mRoot}/star`); |
12 | -const helpers = require(`${library}/helpers`); | ||
13 | 11 | ||
14 | // const headerModel = require('../../../doraemon/models/header'); | 12 | // const headerModel = require('../../../doraemon/models/header'); |
15 | 13 | ||
@@ -54,20 +52,35 @@ const processPublicData = (req, title) => { | @@ -54,20 +52,35 @@ const processPublicData = (req, title) => { | ||
54 | * @param {[object]} res | 52 | * @param {[object]} res |
55 | * @return {[type]} | 53 | * @return {[type]} |
56 | */ | 54 | */ |
57 | -exports.index = (req, res) => { | 55 | +exports.index = (req, res, next) => { |
58 | const pageHeadTab = _.cloneDeep(headTab); | 56 | const pageHeadTab = _.cloneDeep(headTab); |
59 | 57 | ||
60 | pageHeadTab[0].cur = true; | 58 | pageHeadTab[0].cur = true; |
61 | pageHeadTab[2].url += (req.query.uid || 0); | 59 | pageHeadTab[2].url += (req.query.uid || 0); |
62 | - res.render('star/index', _.assign({ | ||
63 | - page: 'star', | ||
64 | - isStarIndexPage: true, | ||
65 | - headTab: pageHeadTab | ||
66 | - }, processPublicData(req, '星潮教室'))); | 60 | + |
61 | + // res.render('star/index', _.assign({ | ||
62 | + // page: 'star', | ||
63 | + // isStarIndexPage: true, | ||
64 | + // headTab: pageHeadTab | ||
65 | + // }, processPublicData(req, '星潮教室'))); | ||
66 | + | ||
67 | + starModel.getIndexData((req.query.uid || 0)).then((result) => { | ||
68 | + res.render('star/index', _.assign({ | ||
69 | + page: 'star', | ||
70 | + isStarIndexPage: true, | ||
71 | + headTab: pageHeadTab, | ||
72 | + content: { | ||
73 | + focus: true, | ||
74 | + data: result.ads | ||
75 | + }, | ||
76 | + starAvatar: result.starAvatar.concat(result.starAvatar).concat(result.starAvatar), // 需要优化,数组重复三次 | ||
77 | + articles: result.articles | ||
78 | + }, processPublicData(req, '星潮教室'))); | ||
79 | + }).catch(next); | ||
67 | }; | 80 | }; |
68 | 81 | ||
69 | exports.getIndexHtml = (req, res, next) => { | 82 | exports.getIndexHtml = (req, res, next) => { |
70 | - starModel.getIndexData().then((result) => { | 83 | + starModel.getIndexData((req.query.uid || 0)).then((result) => { |
71 | res.render('star/index-html', _.assign({ | 84 | res.render('star/index-html', _.assign({ |
72 | layout: false, | 85 | layout: false, |
73 | content: { | 86 | content: { |
@@ -150,14 +163,24 @@ exports.collocationList = (req, res, next) => { | @@ -150,14 +163,24 @@ exports.collocationList = (req, res, next) => { | ||
150 | * @return {[type]} | 163 | * @return {[type]} |
151 | */ | 164 | */ |
152 | exports.setFavorite = (req, res, next) => { | 165 | exports.setFavorite = (req, res, next) => { |
153 | - let params = req.body; | ||
154 | let uid = req.body.uid || 0; // 客户端访问,不能使用 cookie | 166 | let uid = req.body.uid || 0; // 客户端访问,不能使用 cookie |
155 | - let url = '/guang/star/collocation'; | ||
156 | let urlEncode = ''; | 167 | let urlEncode = ''; |
168 | + let url = ''; | ||
169 | + let params = { | ||
170 | + articleId: req.body.articleId, | ||
171 | + type: req.body.type | ||
172 | + }; | ||
173 | + | ||
174 | + if (req.body.pageType === '1') { | ||
175 | + url = `/guang/star/collocation?uid=${uid}`; | ||
176 | + urlEncode = '\/guang\/star\/collocation'; | ||
177 | + } else { | ||
178 | + url = `/guang/star/detail?tag=${req.body.tag}&uid=${uid}`; | ||
179 | + urlEncode = '\/guang\/star\/detail'; | ||
180 | + } | ||
157 | 181 | ||
158 | starModel.setFavorite(params, uid).then((result) => { | 182 | starModel.setFavorite(params, uid).then((result) => { |
159 | if (result.code === 400) { | 183 | if (result.code === 400) { |
160 | - urlEncode = '\/guang\/star\/collocation'; | ||
161 | result.data = `${url}?openby:yohobuy={"action":"go.weblogin","params":{"jumpurl":{"url":"http:\/\/m.yohobuy.com${urlEncode}","param":{"from":"app"}},"requesturl":{"url":"","param":{}},"priority":"N"}}`; // eslint-disable-line | 184 | result.data = `${url}?openby:yohobuy={"action":"go.weblogin","params":{"jumpurl":{"url":"http:\/\/m.yohobuy.com${urlEncode}","param":{"from":"app"}},"requesturl":{"url":"","param":{}},"priority":"N"}}`; // eslint-disable-line |
162 | } | 185 | } |
163 | res.json(result); | 186 | res.json(result); |
@@ -14,8 +14,6 @@ const logger = require(`${library}/logger`); | @@ -14,8 +14,6 @@ const logger = require(`${library}/logger`); | ||
14 | const camelCase = require(`${library}/camel-case`); | 14 | const camelCase = require(`${library}/camel-case`); |
15 | const helpers = require(`${library}/helpers`); | 15 | const helpers = require(`${library}/helpers`); |
16 | const _ = require('lodash'); | 16 | const _ = require('lodash'); |
17 | -const url = require('url'); | ||
18 | -const qs = require('querystring'); | ||
19 | const serviceAPI = new ServiceAPI(); | 17 | const serviceAPI = new ServiceAPI(); |
20 | const api = new API(); | 18 | const api = new API(); |
21 | 19 | ||
@@ -30,7 +28,8 @@ const contentCode = { | @@ -30,7 +28,8 @@ const contentCode = { | ||
30 | */ | 28 | */ |
31 | const _getResources = (page) => { | 29 | const _getResources = (page) => { |
32 | return serviceAPI.get('operations/api/v5/resource/get', sign.apiSign({ | 30 | return serviceAPI.get('operations/api/v5/resource/get', sign.apiSign({ |
33 | - content_code: contentCode[page] | 31 | + content_code: contentCode[page], |
32 | + client_type: 'iphone' | ||
34 | })).then((result) => { | 33 | })).then((result) => { |
35 | if (result && result.code === 200) { | 34 | if (result && result.code === 200) { |
36 | return resourcesProcess(result.data); | 35 | return resourcesProcess(result.data); |
@@ -46,7 +45,7 @@ const _getResources = (page) => { | @@ -46,7 +45,7 @@ const _getResources = (page) => { | ||
46 | * @param {[array]} list | 45 | * @param {[array]} list |
47 | * @return {[array]} | 46 | * @return {[array]} |
48 | */ | 47 | */ |
49 | -const _processIndexData = (list) => { | 48 | +const _processIndexData = (list, uid) => { |
50 | const formatData = { | 49 | const formatData = { |
51 | ads: [], | 50 | ads: [], |
52 | starAvatar: [], | 51 | starAvatar: [], |
@@ -59,12 +58,9 @@ const _processIndexData = (list) => { | @@ -59,12 +58,9 @@ const _processIndexData = (list) => { | ||
59 | // 首页资源位数据处理 | 58 | // 首页资源位数据处理 |
60 | if (list.ads) { | 59 | if (list.ads) { |
61 | _.forEach(list.ads.data, (data) => { | 60 | _.forEach(list.ads.data, (data) => { |
62 | - let urlObj = url.parse(data.url); | ||
63 | - let appUrl = `&openby:yohobuy={"action":"go.h5","params":{"id":"","share":"","shareparam":{},"islogin":"N","type":0,"updateflag":"N","url":"${ urlObj.protocol + '//' + urlObj.host + urlObj.pathname}","param":${JSON.stringify(qs.parse(urlObj.query))}}}`.replace(/\//g, '\/'); // eslint-disable-line | ||
64 | - | ||
65 | formatData.ads.push({ | 61 | formatData.ads.push({ |
66 | src: data.src, | 62 | src: data.src, |
67 | - url: data.url + appUrl | 63 | + url: data.url |
68 | }); | 64 | }); |
69 | }); | 65 | }); |
70 | } | 66 | } |
@@ -82,18 +78,15 @@ const _processIndexData = (list) => { | @@ -82,18 +78,15 @@ const _processIndexData = (list) => { | ||
82 | 78 | ||
83 | _.forEach(data.ext.tags, (tags) => { | 79 | _.forEach(data.ext.tags, (tags) => { |
84 | avatar.tags.push({ | 80 | avatar.tags.push({ |
85 | - avatarUrl: `/guang/star/detail?tag=${tags.tagName}&openby:yohobuy={"action":"go.h5","params":{"id":"","share":"","shareparam":{},"islogin":"N","type":0,"updateflag":"N","url":"http://m.yohobuy.com/guang/star/detail","param":{"tag":"${tags.tagName}"}}}`, // eslint-disable-line | 81 | + avatarUrl: `/guang/star/detail?tag=${tags.tagName}&uid=${uid}&openby:yohobuy={"action":"go.h5","params":{"id":"","share":"","shareparam":{},"islogin":"N","type":0,"updateflag":"N","url":"http://m.yohobuy.com/guang/star/detail","param":{"tag":"${tags.tagName}"}}}`, // eslint-disable-line |
86 | cover: tags.cover, | 82 | cover: tags.cover, |
87 | tagName: tags.tagName | 83 | tagName: tags.tagName |
88 | }); | 84 | }); |
89 | }); | 85 | }); |
90 | 86 | ||
91 | - let urlObj = url.parse(data.url); | ||
92 | - let appUrl = `&openby:yohobuy={"action":"go.h5","params":{"id":"","share":"","shareparam":{},"islogin":"N","type":0,"updateflag":"N","url":"${ urlObj.protocol + '//' + urlObj.host + urlObj.pathname}","param":${JSON.stringify(qs.parse(urlObj.query))}}}`.replace(/\//g, '\/'); // eslint-disable-line | ||
93 | - | ||
94 | formatData.articles.push(_.merge({ | 87 | formatData.articles.push(_.merge({ |
95 | id: data.id, | 88 | id: data.id, |
96 | - url: data.url + appUrl, | 89 | + url: data.url, |
97 | title: data.title, | 90 | title: data.title, |
98 | articeTxt: data.intro, | 91 | articeTxt: data.intro, |
99 | src: data.src, | 92 | src: data.src, |
@@ -107,7 +100,7 @@ const _processIndexData = (list) => { | @@ -107,7 +100,7 @@ const _processIndexData = (list) => { | ||
107 | // 首页明星头像数据处理 | 100 | // 首页明星头像数据处理 |
108 | if (list.tags) { | 101 | if (list.tags) { |
109 | _.forEach(list.tags, (data) => { | 102 | _.forEach(list.tags, (data) => { |
110 | - let url = `/guang/star/detail?tag=${data.tagName}&openby:yohobuy={"action":"go.h5","params":{"id":"","share":"","shareparam":{},"islogin":"N","type":0,"updateflag":"N","url":"http://m.yohobuy.com/guang/star/detail","param":{"tag":"${data.tagName}"}}}`; // eslint-disable-line | 103 | + let url = `/guang/star/detail?tag=${data.tagName}&uid=${uid}&openby:yohobuy={"action":"go.h5","params":{"id":"","share":"","shareparam":{},"islogin":"N","type":0,"updateflag":"N","url":"http://m.yohobuy.com/guang/star/detail","param":{"tag":"${data.tagName}"}}}`; // eslint-disable-line |
111 | 104 | ||
112 | formatData.starAvatar.push({ | 105 | formatData.starAvatar.push({ |
113 | url: url, | 106 | url: url, |
@@ -140,11 +133,6 @@ const _processDetailData = (list) => { | @@ -140,11 +133,6 @@ const _processDetailData = (list) => { | ||
140 | data.share.url = _processShareUrl(data); | 133 | data.share.url = _processShareUrl(data); |
141 | } | 134 | } |
142 | 135 | ||
143 | - let urlObj = url.parse(data.url); | ||
144 | - let qsObj = qs.parse(urlObj.query); | ||
145 | - let appUrl = `&openby:yohobuy={"action":"go.h5","params":{"shareparam":{"id":"${qsObj.id}"},"share":"/guang/api/v1/share/guang","id":"${qsObj.id}","islogin":"N","type":1,"updateflag":"N","url":"${ urlObj.protocol + '//' + urlObj.host + urlObj.pathname}","param":${JSON.stringify(qs.parse(urlObj.query))}}}`.replace(/\//g, '\/'); // eslint-disable-line | ||
146 | - data.url += appUrl; | ||
147 | - | ||
148 | if (key < 4) { | 136 | if (key < 4) { |
149 | data.islazy = true; | 137 | data.islazy = true; |
150 | } | 138 | } |
@@ -183,13 +171,14 @@ const _processCollocationData = (list) => { | @@ -183,13 +171,14 @@ const _processCollocationData = (list) => { | ||
183 | /** | 171 | /** |
184 | * 星潮首页 | 172 | * 星潮首页 |
185 | */ | 173 | */ |
186 | -const getIndexData = () => { | 174 | +const getIndexData = (uid) => { |
187 | return api.get('', sign.apiSign({ | 175 | return api.get('', sign.apiSign({ |
188 | method: 'app.starClass.index', | 176 | method: 'app.starClass.index', |
189 | - code: '8adc27fcf5676f356602889afcfd2a8e' | 177 | + code: '8adc27fcf5676f356602889afcfd2a8e', |
178 | + client_type: 'iphone' | ||
190 | })).then((result) => { | 179 | })).then((result) => { |
191 | if (result && result.code === 200) { | 180 | if (result && result.code === 200) { |
192 | - return _processIndexData(result.data); | 181 | + return _processIndexData(result.data, uid); |
193 | } else { | 182 | } else { |
194 | logger.error('星潮教室首页数据返回 code 不是 200'); | 183 | logger.error('星潮教室首页数据返回 code 不是 200'); |
195 | return {}; | 184 | return {}; |
@@ -205,7 +194,8 @@ const getDetailData = (params) => { | @@ -205,7 +194,8 @@ const getDetailData = (params) => { | ||
205 | method: 'app.starClass.lastTagArticle', | 194 | method: 'app.starClass.lastTagArticle', |
206 | tag: params.tag, | 195 | tag: params.tag, |
207 | page: params.page || 1, | 196 | page: params.page || 1, |
208 | - size: 10 | 197 | + size: 10, |
198 | + client_type: 'iphone' | ||
209 | })).then((result) => { | 199 | })).then((result) => { |
210 | if (result && result.code === 200) { | 200 | if (result && result.code === 200) { |
211 | if (params.page > result.data.totalPage) { | 201 | if (params.page > result.data.totalPage) { |
@@ -10,11 +10,11 @@ var $ = require('yoho-jquery'), | @@ -10,11 +10,11 @@ var $ = require('yoho-jquery'), | ||
10 | require('../common'); | 10 | require('../common'); |
11 | 11 | ||
12 | // 星搭配收藏请求 | 12 | // 星搭配收藏请求 |
13 | -$('.collocation-list').on('click', '.collection', function() { | 13 | +$('.collocation-list,.detail-list').on('click', '.collection', function() { |
14 | var $that = $(this), | 14 | var $that = $(this), |
15 | $icon = $that.find('.collected-ico'); | 15 | $icon = $that.find('.collected-ico'); |
16 | 16 | ||
17 | - var type; | 17 | + var type, pageType, tag; |
18 | 18 | ||
19 | if ($icon.hasClass('collected')) { | 19 | if ($icon.hasClass('collected')) { |
20 | type = 'del'; | 20 | type = 'del'; |
@@ -22,13 +22,23 @@ $('.collocation-list').on('click', '.collection', function() { | @@ -22,13 +22,23 @@ $('.collocation-list').on('click', '.collection', function() { | ||
22 | type = 'fav'; | 22 | type = 'fav'; |
23 | } | 23 | } |
24 | 24 | ||
25 | + if ($(this).parents('.collocation-list').length > 0) { | ||
26 | + pageType = '1'; | ||
27 | + tag = ''; | ||
28 | + } else { | ||
29 | + pageType = '2'; | ||
30 | + tag = $('.detail-list').data('name'); | ||
31 | + } | ||
32 | + | ||
25 | $.ajax({ | 33 | $.ajax({ |
26 | type: 'POST', | 34 | type: 'POST', |
27 | url: '/guang/star/setFavorite', | 35 | url: '/guang/star/setFavorite', |
28 | data: { | 36 | data: { |
29 | articleId: $that.parents('li').attr('articleId'), | 37 | articleId: $that.parents('li').attr('articleId'), |
30 | type: type, | 38 | type: type, |
31 | - uid: window.queryString.uid | 39 | + uid: window.queryString.uid, |
40 | + pageType: pageType, | ||
41 | + tag: tag | ||
32 | }, | 42 | }, |
33 | success: function(data) { | 43 | success: function(data) { |
34 | var code = data.code; | 44 | var code = data.code; |
@@ -13,7 +13,8 @@ var $ = require('yoho-jquery'), | @@ -13,7 +13,8 @@ var $ = require('yoho-jquery'), | ||
13 | PullRefresh = require('../plugin/pull-refresh'); | 13 | PullRefresh = require('../plugin/pull-refresh'); |
14 | 14 | ||
15 | var $window = $(window), | 15 | var $window = $(window), |
16 | - stopLoading = false; | 16 | + stopLoading = false, |
17 | + $starMain = $('.star-main'); | ||
17 | 18 | ||
18 | /* | 19 | /* |
19 | $headTab = $('.head-tab'), | 20 | $headTab = $('.head-tab'), |
@@ -228,11 +229,34 @@ function setIndexAction() { | @@ -228,11 +229,34 @@ function setIndexAction() { | ||
228 | }); | 229 | }); |
229 | } | 230 | } |
230 | 231 | ||
232 | +function initAction() { | ||
233 | + $avatar = $('.avatar'); | ||
234 | + $starArticle = $('.star-article'); | ||
235 | + bannerLen = $avatar.find('.swiper-slide').length; | ||
236 | + | ||
237 | + if ($avatarClone) { | ||
238 | + $avatarClone.remove(); | ||
239 | + } | ||
240 | + | ||
241 | + $starMain.before($('.avatar-swiper').clone().addClass('avatar-clone').hide()); | ||
242 | + | ||
243 | + $avatarClone = $('.avatar-clone'); | ||
244 | + | ||
245 | + // 限制标题字数 | ||
246 | + $('.cont-area').each(function() { | ||
247 | + txtLimit($(this), '.title', '.cont-txt'); | ||
248 | + }); | ||
249 | + | ||
250 | + lazyLoad($('img.lazy')); | ||
251 | + | ||
252 | + setTimeout(function() { | ||
253 | + setIndexAction(); | ||
254 | + }, 100); | ||
255 | +} | ||
256 | + | ||
231 | 257 | ||
232 | // 首页数据请求 | 258 | // 首页数据请求 |
233 | getIndexHtml = function() { | 259 | getIndexHtml = function() { |
234 | - var $starMain = $('.star-main'); | ||
235 | - | ||
236 | loading.showLoadingMask(); | 260 | loading.showLoadingMask(); |
237 | $.ajax({ | 261 | $.ajax({ |
238 | url: '/guang/star/getIndexHtml', | 262 | url: '/guang/star/getIndexHtml', |
@@ -246,38 +270,18 @@ getIndexHtml = function() { | @@ -246,38 +270,18 @@ getIndexHtml = function() { | ||
246 | } | 270 | } |
247 | 271 | ||
248 | $starMain.html(data); | 272 | $starMain.html(data); |
249 | - $avatar = $('.avatar'); | ||
250 | - $starArticle = $('.star-article'); | ||
251 | - bannerLen = $avatar.find('.swiper-slide').length; | ||
252 | - | ||
253 | - if ($avatarClone) { | ||
254 | - $avatarClone.remove(); | ||
255 | - } | ||
256 | - | ||
257 | - $starMain.before($('.avatar-swiper').clone().addClass('avatar-clone').hide()); | ||
258 | - | ||
259 | - $avatarClone = $('.avatar-clone'); | ||
260 | - | ||
261 | - // 限制标题字数 | ||
262 | - $('.cont-area').each(function() { | ||
263 | - txtLimit($(this), '.title', '.cont-txt'); | ||
264 | - }); | ||
265 | - | ||
266 | - lazyLoad($('img.lazy')); | ||
267 | - | ||
268 | - setTimeout(function() { | ||
269 | - setIndexAction(); | ||
270 | - loading.hideLoadingMask(); | ||
271 | - }, 100); | ||
272 | 273 | ||
274 | + initAction(); | ||
275 | + loading.hideLoadingMask(); | ||
273 | }, | 276 | }, |
274 | error: function() { | 277 | error: function() { |
275 | tip.show('网络断开连接了~'); | 278 | tip.show('网络断开连接了~'); |
276 | } | 279 | } |
277 | }); | 280 | }); |
278 | }; | 281 | }; |
282 | +initAction(); | ||
279 | 283 | ||
280 | -getIndexHtml(); | 284 | +// getIndexHtml(); |
281 | 285 | ||
282 | // 明星动态文章图片相关操作 | 286 | // 明星动态文章图片相关操作 |
283 | /* | 287 | /* |
@@ -23,7 +23,8 @@ | @@ -23,7 +23,8 @@ | ||
23 | } | 23 | } |
24 | 24 | ||
25 | .head-tab { | 25 | .head-tab { |
26 | - position: relative; | 26 | + position: fixed; |
27 | + top: 0; | ||
27 | width: 100%; | 28 | width: 100%; |
28 | height: 88px; | 29 | height: 88px; |
29 | background: #000; | 30 | background: #000; |
@@ -119,6 +120,10 @@ | @@ -119,6 +120,10 @@ | ||
119 | height: 180px; | 120 | height: 180px; |
120 | } | 121 | } |
121 | 122 | ||
123 | + .star-main { | ||
124 | + margin-top: 88px; | ||
125 | + } | ||
126 | + | ||
122 | .avatar-swiper { | 127 | .avatar-swiper { |
123 | overflow: hidden; | 128 | overflow: hidden; |
124 | margin-top: 30px; | 129 | margin-top: 30px; |
@@ -394,7 +399,9 @@ | @@ -394,7 +399,9 @@ | ||
394 | 399 | ||
395 | .swiper-num { | 400 | .swiper-num { |
396 | width: 55px; | 401 | width: 55px; |
397 | - display: none; | 402 | + position: fixed; |
403 | + top: 0; | ||
404 | + z-index: -1; | ||
398 | } | 405 | } |
399 | } | 406 | } |
400 | 407 |
-
Please register or login to post a comment