Showing
8 changed files
with
104 additions
and
13 deletions
@@ -7,6 +7,8 @@ | @@ -7,6 +7,8 @@ | ||
7 | const _ = require('lodash'); | 7 | const _ = require('lodash'); |
8 | const channelModel = require('../models/channel'); | 8 | const channelModel = require('../models/channel'); |
9 | const helpers = require('../../../library/helpers'); | 9 | const helpers = require('../../../library/helpers'); |
10 | +const log = require('../../../library/logger'); | ||
11 | +const cookie = require('../../../library/cookie'); | ||
10 | 12 | ||
11 | const mod = 'channel'; | 13 | const mod = 'channel'; |
12 | let footerTab = { | 14 | let footerTab = { |
@@ -17,6 +19,10 @@ let footerTab = { | @@ -17,6 +19,10 @@ let footerTab = { | ||
17 | mineUrl: helpers.url('/home') // 个人中心 | 19 | mineUrl: helpers.url('/home') // 个人中心 |
18 | }; | 20 | }; |
19 | 21 | ||
22 | +const channelLogger = (err) => { | ||
23 | + log.error(err); | ||
24 | +}; | ||
25 | + | ||
20 | /** | 26 | /** |
21 | * 频道选择 | 27 | * 频道选择 |
22 | * @param {object} req | 28 | * @param {object} req |
@@ -43,7 +49,7 @@ exports.switchChannel = (req, res, next) => { | @@ -43,7 +49,7 @@ exports.switchChannel = (req, res, next) => { | ||
43 | exports.boys = (req, res) => { | 49 | exports.boys = (req, res) => { |
44 | channelModel.getChannelDate({ | 50 | channelModel.getChannelDate({ |
45 | gender: 'boys', | 51 | gender: 'boys', |
46 | - uid: 123 | 52 | + uid: cookie.getUid(req) |
47 | }).then(result => { | 53 | }).then(result => { |
48 | res.render('channel', Object.assign({ | 54 | res.render('channel', Object.assign({ |
49 | module: mod, | 55 | module: mod, |
@@ -57,7 +63,67 @@ exports.boys = (req, res) => { | @@ -57,7 +63,67 @@ exports.boys = (req, res) => { | ||
57 | showFooterTab: footerTab, | 63 | showFooterTab: footerTab, |
58 | pageFooter: true | 64 | pageFooter: true |
59 | }, result)); | 65 | }, result)); |
60 | - }).catch(console.trace); | 66 | + }).catch(channelLogger); |
67 | +}; | ||
68 | + | ||
69 | +exports.girls = (req, res) => { | ||
70 | + channelModel.getChannelDate({ | ||
71 | + gender: 'girls', | ||
72 | + uid: cookie.getUid(req) | ||
73 | + }).then(result => { | ||
74 | + res.render('channel', Object.assign({ | ||
75 | + module: mod, | ||
76 | + page: 'home', | ||
77 | + title: '女生首页', | ||
78 | + girlsHomePage: true, | ||
79 | + homeHeader: { | ||
80 | + searchUrl: helpers.url('/search', null, 'search') | ||
81 | + }, | ||
82 | + maybeLike: true, | ||
83 | + showFooterTab: footerTab, | ||
84 | + pageFooter: true | ||
85 | + }, result)); | ||
86 | + }).catch(channelLogger); | ||
87 | +}; | ||
88 | + | ||
89 | +exports.kids = (req, res) => { | ||
90 | + channelModel.getChannelDate({ | ||
91 | + gender: 'kids', | ||
92 | + uid: cookie.getUid(req) | ||
93 | + }).then(result => { | ||
94 | + res.render('channel', Object.assign({ | ||
95 | + module: mod, | ||
96 | + page: 'home', | ||
97 | + title: '潮童首页', | ||
98 | + kidsHomePage: true, | ||
99 | + homeHeader: { | ||
100 | + searchUrl: helpers.url('/search', null, 'search') | ||
101 | + }, | ||
102 | + maybeLike: true, | ||
103 | + showFooterTab: footerTab, | ||
104 | + pageFooter: true | ||
105 | + }, result)); | ||
106 | + }).catch(channelLogger); | ||
107 | +}; | ||
108 | + | ||
109 | +exports.lifestyle = (req, res) => { | ||
110 | + channelModel.getChannelDate({ | ||
111 | + gender: 'lifestyle', | ||
112 | + uid: cookie.getUid(req) | ||
113 | + }).then(result => { | ||
114 | + res.render('channel', Object.assign({ | ||
115 | + module: mod, | ||
116 | + page: 'home', | ||
117 | + title: '创意生活首页', | ||
118 | + lifestyleHomePage: true, | ||
119 | + homeHeader: { | ||
120 | + searchUrl: helpers.url('/search', null, 'search') | ||
121 | + }, | ||
122 | + maybeLike: true, | ||
123 | + showFooterTab: footerTab, | ||
124 | + pageFooter: true | ||
125 | + }, result)); | ||
126 | + }).catch(channelLogger); | ||
61 | }; | 127 | }; |
62 | 128 | ||
63 | exports.bottomBanner = (req, res) => { | 129 | exports.bottomBanner = (req, res) => { |
@@ -5,7 +5,7 @@ | @@ -5,7 +5,7 @@ | ||
5 | */ | 5 | */ |
6 | 'use strict'; | 6 | 'use strict'; |
7 | const _ = require('lodash'); | 7 | const _ = require('lodash'); |
8 | -const API = require('../../../library/api').API; | 8 | +const API = require('../../../library/api').ServiceAPI; |
9 | const sign = require('../../../library/sign'); | 9 | const sign = require('../../../library/sign'); |
10 | const camelCase = require('../../../library/camel-case'); | 10 | const camelCase = require('../../../library/camel-case'); |
11 | 11 | ||
@@ -128,7 +128,7 @@ const getChannelResource = (params) => { | @@ -128,7 +128,7 @@ const getChannelResource = (params) => { | ||
128 | } | 128 | } |
129 | 129 | ||
130 | return api.get('operations/api/v5/resource/home', sign.apiSign(params)).then(result => { | 130 | return api.get('operations/api/v5/resource/home', sign.apiSign(params)).then(result => { |
131 | - if (result.code === 200) { | 131 | + if (result && result.code === 200) { |
132 | return processFloor(result.data.list); | 132 | return processFloor(result.data.list); |
133 | } else { | 133 | } else { |
134 | return result; | 134 | return result; |
@@ -145,7 +145,7 @@ const getLeftNav = (choosed) => { | @@ -145,7 +145,7 @@ const getLeftNav = (choosed) => { | ||
145 | choosed = choosed || 'all'; | 145 | choosed = choosed || 'all'; |
146 | 146 | ||
147 | return api.get('operations/api/v6/category/getCategory', sign.apiSign({})).then(result => { | 147 | return api.get('operations/api/v6/category/getCategory', sign.apiSign({})).then(result => { |
148 | - if (result.code === 200) { | 148 | + if (result && result.code === 200) { |
149 | return processSideBar(result.data, choosed); | 149 | return processSideBar(result.data, choosed); |
150 | } else { | 150 | } else { |
151 | return result; | 151 | return result; |
@@ -13,10 +13,10 @@ const channel = require(cRoot); | @@ -13,10 +13,10 @@ const channel = require(cRoot); | ||
13 | const router = express.Router(); // eslint-disable-line | 13 | const router = express.Router(); // eslint-disable-line |
14 | 14 | ||
15 | router.get('/boys', channel.switchChannel, channel.boys); | 15 | router.get('/boys', channel.switchChannel, channel.boys); |
16 | +router.get('/girls', channel.switchChannel, channel.girls); | ||
17 | +router.get('/kids', channel.switchChannel, channel.kids); | ||
18 | +router.get('/lifestyle', channel.switchChannel, channel.lifestyle); | ||
16 | 19 | ||
17 | -// router.get('/girls', channel.switchChannel, channel.girls); | ||
18 | -// router.get('/kids', channel.switchChannel, channel.kids); | ||
19 | -// router.get('/lifestyle', channel.switchChannel, channel.lifestyle); | ||
20 | router.get('/channel/bottomBanner', channel.bottomBanner); | 20 | router.get('/channel/bottomBanner', channel.bottomBanner); |
21 | 21 | ||
22 | module.exports = router; | 22 | module.exports = router; |
@@ -6,7 +6,7 @@ | @@ -6,7 +6,7 @@ | ||
6 | */ | 6 | */ |
7 | 7 | ||
8 | module.exports = { | 8 | module.exports = { |
9 | - siteUrl: 'http://www.yohobuy.com', | 9 | + siteUrl: 'http://m.yohobuy.com', |
10 | domains: { | 10 | domains: { |
11 | api: 'http://testapi.yoho.cn:28078/', | 11 | api: 'http://testapi.yoho.cn:28078/', |
12 | service: 'http://testservice.yoho.cn:28077/' | 12 | service: 'http://testservice.yoho.cn:28077/' |
@@ -36,7 +36,7 @@ | @@ -36,7 +36,7 @@ | ||
36 | {{> footer}} | 36 | {{> footer}} |
37 | 37 | ||
38 | {{#if devEnv}} | 38 | {{#if devEnv}} |
39 | - <script src="//localhost:5001{{module}}.{{page}}.js"></script> | 39 | + <script src="//localhost:5001/{{module}}.{{page}}.js"></script> |
40 | {{^}} | 40 | {{^}} |
41 | <script src="//cdn.yoho.cn/m-yohobuy-node/{{version}}/{{module}}.{{page}}.js"></script> | 41 | <script src="//cdn.yoho.cn/m-yohobuy-node/{{version}}/{{module}}.{{page}}.js"></script> |
42 | {{/if}} | 42 | {{/if}} |
@@ -60,7 +60,8 @@ class API { | @@ -60,7 +60,8 @@ class API { | ||
60 | _.forEach(urls, function(el) { | 60 | _.forEach(urls, function(el) { |
61 | rps.push(rp({ | 61 | rps.push(rp({ |
62 | url: `${ApiUrl}${el.url}`, | 62 | url: `${ApiUrl}${el.url}`, |
63 | - qs: el.data | 63 | + qs: el.data, |
64 | + json: true | ||
64 | })); | 65 | })); |
65 | }); | 66 | }); |
66 | 67 | ||
@@ -78,7 +79,8 @@ class API { | @@ -78,7 +79,8 @@ class API { | ||
78 | return rp({ | 79 | return rp({ |
79 | url: `${ApiUrl}${url}`, | 80 | url: `${ApiUrl}${url}`, |
80 | method: 'post', | 81 | method: 'post', |
81 | - form: data | 82 | + form: data, |
83 | + json: true | ||
82 | }); | 84 | }); |
83 | } | 85 | } |
84 | } | 86 | } |
library/cookie.js
0 → 100644
1 | +/** | ||
2 | + * 获取 UID | ||
3 | + * @param {[object]} req | ||
4 | + * @return {[string]} | ||
5 | + */ | ||
6 | +exports.getUid = (req) => { | ||
7 | + var _uid = 0, | ||
8 | + cookie = req.cookies._UID, | ||
9 | + cookieList; | ||
10 | + | ||
11 | + if (req.isApp) { | ||
12 | + return req.query.uid || 0; | ||
13 | + } | ||
14 | + | ||
15 | + if (cookie) { | ||
16 | + cookieList = cookie.split('::'); | ||
17 | + if (cookieList[1] && !isNaN(cookieList[1])) { | ||
18 | + _uid = cookieList[1]; | ||
19 | + } | ||
20 | + } | ||
21 | + | ||
22 | + return _uid; | ||
23 | +}; |
@@ -193,7 +193,7 @@ gulp.task('webpack-dev-server', () => { | @@ -193,7 +193,7 @@ gulp.task('webpack-dev-server', () => { | ||
193 | 193 | ||
194 | new WebpackDevServer(webpack(devConfig), { | 194 | new WebpackDevServer(webpack(devConfig), { |
195 | contentBase: '.', | 195 | contentBase: '.', |
196 | - publicPath: '//localhost:5001', | 196 | + publicPath: '//localhost:5001/', |
197 | hot: true, | 197 | hot: true, |
198 | stats: { | 198 | stats: { |
199 | colors: true | 199 | colors: true |
-
Please register or login to post a comment