product/sale product/new brands
Showing
11 changed files
with
131 additions
and
15 deletions
@@ -9,6 +9,7 @@ | @@ -9,6 +9,7 @@ | ||
9 | const headerModel = require('../../../doraemon/models/header'); // 头部model | 9 | const headerModel = require('../../../doraemon/models/header'); // 头部model |
10 | const footerModel = require('../../../doraemon/models/footer_tab'); // 底部tab | 10 | const footerModel = require('../../../doraemon/models/footer_tab'); // 底部tab |
11 | const indexModel = require('../models/brand'); | 11 | const indexModel = require('../models/brand'); |
12 | +const typeLib = require('../../../config/type-lib'); | ||
12 | 13 | ||
13 | /** | 14 | /** |
14 | * 品牌一览 | 15 | * 品牌一览 |
@@ -17,7 +18,6 @@ const indexModel = require('../models/brand'); | @@ -17,7 +18,6 @@ const indexModel = require('../models/brand'); | ||
17 | * @param int channel 1表示男生频道, 2表示女生频道, 3表示潮童频道, 4表示创意生活频道 | 18 | * @param int channel 1表示男生频道, 2表示女生频道, 3表示潮童频道, 4表示创意生活频道 |
18 | */ | 19 | */ |
19 | let index = (req, res, next) => { | 20 | let index = (req, res, next) => { |
20 | - | ||
21 | let responseData = { | 21 | let responseData = { |
22 | module: 'channel', | 22 | module: 'channel', |
23 | page: 'brand', | 23 | page: 'brand', |
@@ -26,14 +26,36 @@ let index = (req, res, next) => { | @@ -26,14 +26,36 @@ let index = (req, res, next) => { | ||
26 | // title: '品牌一览 | Yoho!Buy有货 | 潮流购物逛不停', | 26 | // title: '品牌一览 | Yoho!Buy有货 | 潮流购物逛不停', |
27 | showFooterTab: footerModel.getUrlData('category') | 27 | showFooterTab: footerModel.getUrlData('category') |
28 | }; | 28 | }; |
29 | + let channel, | ||
30 | + gender; | ||
31 | + | ||
32 | + if (!req.query.channel) { | ||
33 | + channel = '1'; | ||
34 | + } else if (!typeLib.channels[req.query.channel]) { | ||
35 | + channel = req.query.channel; | ||
36 | + } else { | ||
37 | + channel = typeLib.channels[req.query.channel] + ''; | ||
38 | + } | ||
39 | + if (!req.query.gender) { | ||
40 | + gender = '1,3'; | ||
41 | + } else if (!typeLib.gender[gender]) { | ||
42 | + gender = req.query.gender; | ||
43 | + } else { | ||
44 | + gender = typeLib.gender[gender]; | ||
45 | + } | ||
29 | 46 | ||
30 | let param = { | 47 | let param = { |
31 | - channel: req.query.channel || '1', | ||
32 | - gender: req.query.gender || '1,3' | 48 | + channel, |
49 | + gender | ||
33 | }; | 50 | }; |
34 | 51 | ||
35 | indexModel.getBrandByChannel(param.channel).then(result => { | 52 | indexModel.getBrandByChannel(param.channel).then(result => { |
36 | - res.render('brand/index', Object.assign(responseData, result)); | 53 | + console.log(result.channel.channels) |
54 | + res.render('brand/index', Object.assign(responseData, result, { | ||
55 | + params: { | ||
56 | + yhChannel: channel | ||
57 | + } | ||
58 | + })); | ||
37 | }).catch(next); | 59 | }).catch(next); |
38 | }; | 60 | }; |
39 | 61 |
@@ -84,13 +84,17 @@ const getBrandByChannel = (channel) => { | @@ -84,13 +84,17 @@ const getBrandByChannel = (channel) => { | ||
84 | let resu = { | 84 | let resu = { |
85 | channel: { | 85 | channel: { |
86 | channels: [{ | 86 | channels: [{ |
87 | - name: 'Boy' | 87 | + name: 'Boy', |
88 | + channelName: 'boys' | ||
88 | }, { | 89 | }, { |
89 | - name: 'Girl' | 90 | + name: 'Girl', |
91 | + channelName: 'girls' | ||
90 | }, { | 92 | }, { |
91 | - name: 'Kid' | 93 | + name: 'Kid', |
94 | + channelName: 'kids' | ||
92 | }, { | 95 | }, { |
93 | - name: 'Lifestyle' | 96 | + name: 'Lifestyle', |
97 | + channelName: 'lifestyle' | ||
94 | }], | 98 | }], |
95 | topData: { | 99 | topData: { |
96 | bannerTop: {}, | 100 | bannerTop: {}, |
@@ -12,6 +12,7 @@ const channel = require(cRoot); | @@ -12,6 +12,7 @@ const channel = require(cRoot); | ||
12 | const cate = require(cRoot + '/cate'); | 12 | const cate = require(cRoot + '/cate'); |
13 | const brandController = require(`${cRoot}/brand`); | 13 | const brandController = require(`${cRoot}/brand`); |
14 | const custom = require(`${cRoot}/custom`); | 14 | const custom = require(`${cRoot}/custom`); |
15 | +const rewrite = require('../../doraemon/middleware/rewrite'); | ||
15 | 16 | ||
16 | const router = express.Router(); // eslint-disable-line | 17 | const router = express.Router(); // eslint-disable-line |
17 | 18 | ||
@@ -26,6 +27,7 @@ router.get('/(:channel)/bottomBanner', channel.bottomBanner); | @@ -26,6 +27,7 @@ router.get('/(:channel)/bottomBanner', channel.bottomBanner); | ||
26 | 27 | ||
27 | router.get('/cate', cate.index); | 28 | router.get('/cate', cate.index); |
28 | router.get('/brands', brandController.index); // 品牌首页 | 29 | router.get('/brands', brandController.index); // 品牌首页 |
30 | +router.get(/^\/([a-zA-Z]+)-brands/, rewrite.channel, brandController.index); // 品牌首页 SEO优化 | ||
29 | router.get('/brands/search', brandController.search); // 品牌搜索页 | 31 | router.get('/brands/search', brandController.search); // 品牌搜索页 |
30 | router.get('/brands/getBrandList', brandController.brandList); // 获取品牌列表 | 32 | router.get('/brands/getBrandList', brandController.brandList); // 获取品牌列表 |
31 | router.post('/brands/searchAsync', brandController.searchAsync); // 品牌搜索异步数据 | 33 | router.post('/brands/searchAsync', brandController.searchAsync); // 品牌搜索异步数据 |
@@ -4,7 +4,7 @@ | @@ -4,7 +4,7 @@ | ||
4 | <div class="genderNav"> | 4 | <div class="genderNav"> |
5 | <ul> | 5 | <ul> |
6 | {{# channels}} | 6 | {{# channels}} |
7 | - <li {{#if active}}class="active"{{/if}} data-id="{{@index}}"> | 7 | + <li {{#if active}}class="active"{{/if}} data-id="{{@index}}" data-name="{{channelName}}"> |
8 | <span>{{name}}</span> | 8 | <span>{{name}}</span> |
9 | <span class="split-border"></span> | 9 | <span class="split-border"></span> |
10 | </li> | 10 | </li> |
@@ -56,4 +56,7 @@ | @@ -56,4 +56,7 @@ | ||
56 | </div> | 56 | </div> |
57 | {{/channel}} | 57 | {{/channel}} |
58 | </div> | 58 | </div> |
59 | -{{> footer-tab}} | ||
59 | +{{> footer-tab}} | ||
60 | +{{# params}} | ||
61 | +{{> common/query-param}} | ||
62 | +{{/params}} |
@@ -11,6 +11,7 @@ const cRoot = './controllers'; | @@ -11,6 +11,7 @@ const cRoot = './controllers'; | ||
11 | const star = require(cRoot + '/star'); | 11 | const star = require(cRoot + '/star'); |
12 | const homeController = require(`${cRoot}/index`); | 12 | const homeController = require(`${cRoot}/index`); |
13 | const plusstar = require(cRoot + '/plusstar'); | 13 | const plusstar = require(cRoot + '/plusstar'); |
14 | +const rewrite = require('../../doraemon/middleware/rewrite'); | ||
14 | 15 | ||
15 | const index = require(cRoot + '/index'); | 16 | const index = require(cRoot + '/index'); |
16 | const opt = require(cRoot + '/opt'); | 17 | const opt = require(cRoot + '/opt'); |
@@ -32,6 +33,7 @@ router.post('/star/setFavorite', star.setFavorite); // 收藏文章 | @@ -32,6 +33,7 @@ router.post('/star/setFavorite', star.setFavorite); // 收藏文章 | ||
32 | router.get('/', homeController.index); // 逛首页 | 33 | router.get('/', homeController.index); // 逛首页 |
33 | 34 | ||
34 | router.get('/plusstar', plusstar.index); // 潮流优选 | 35 | router.get('/plusstar', plusstar.index); // 潮流优选 |
36 | +router.get(/^\/([a-zA-Z]+)-plusstar/, rewrite.gender, plusstar.index); // 潮流优选 SEO优化 | ||
35 | router.post('/plusstar/userSkn', plusstar.userSkn); // 用户推荐skn | 37 | router.post('/plusstar/userSkn', plusstar.userSkn); // 用户推荐skn |
36 | router.get('/plusstar/resources-template', plusstar.resourcesTemplate); // 潮流优选首页-资源位 | 38 | router.get('/plusstar/resources-template', plusstar.resourcesTemplate); // 潮流优选首页-资源位 |
37 | router.post('/plusstar/resources-goodsList', plusstar.resourcesGoodsList); // 潮流优选首页-资源位-商品列表 | 39 | router.post('/plusstar/resources-goodsList', plusstar.resourcesGoodsList); // 潮流优选首页-资源位-商品列表 |
@@ -10,6 +10,8 @@ const router = require('express').Router(); // eslint-disable-line | @@ -10,6 +10,8 @@ const router = require('express').Router(); // eslint-disable-line | ||
10 | 10 | ||
11 | const auth = require('../../doraemon/middleware/auth'); | 11 | const auth = require('../../doraemon/middleware/auth'); |
12 | 12 | ||
13 | +const rewrite = require('../../doraemon/middleware/rewrite'); | ||
14 | + | ||
13 | const cRoot = './controllers'; | 15 | const cRoot = './controllers'; |
14 | 16 | ||
15 | // 商品详情controller | 17 | // 商品详情controller |
@@ -86,6 +88,8 @@ router.post('/detail/consultupvote', detail.consultUpvoteOrUseful); // 商品咨 | @@ -86,6 +88,8 @@ router.post('/detail/consultupvote', detail.consultUpvoteOrUseful); // 商品咨 | ||
86 | router.post('/detail/consultuseful', detail.consultUpvoteOrUseful); // 商品咨询提交接口 | 88 | router.post('/detail/consultuseful', detail.consultUpvoteOrUseful); // 商品咨询提交接口 |
87 | 89 | ||
88 | router.get('/sale', sale.index); | 90 | router.get('/sale', sale.index); |
91 | +router.get(/^\/([a-zA-Z]+)-sale/, rewrite.channel, sale.index); // 折扣专区 SEO优化 | ||
92 | + | ||
89 | router.get('/sale/discount', sale.discount); | 93 | router.get('/sale/discount', sale.discount); |
90 | router.get('/sale/discount/detail', sale.discountDetail); | 94 | router.get('/sale/discount/detail', sale.discountDetail); |
91 | router.get('/sale/breakingYards', sale.breakingYards); | 95 | router.get('/sale/breakingYards', sale.breakingYards); |
@@ -157,6 +161,10 @@ router.get('/opt/favoriteBrand', list.favoriteBrand); | @@ -157,6 +161,10 @@ router.get('/opt/favoriteBrand', list.favoriteBrand); | ||
157 | 161 | ||
158 | // 新品到着 | 162 | // 新品到着 |
159 | router.get('/new', news.newGoods); | 163 | router.get('/new', news.newGoods); |
164 | + | ||
165 | +// 新品到着 SEO优化 | ||
166 | +router.get(/^\/([a-zA-Z]+)-new/, rewrite.channel, news.newGoods); | ||
167 | + | ||
160 | router.get('/list/new', news.newGoods); // 兼容 PC 的链接 | 168 | router.get('/list/new', news.newGoods); // 兼容 PC 的链接 |
161 | router.get('/new/selectNewSale', news.selectNewSale); | 169 | router.get('/new/selectNewSale', news.selectNewSale); |
162 | router.get('/new/filter', news.filter); | 170 | router.get('/new/filter', news.filter); |
config/type-lib.js
0 → 100644
1 | +/** | ||
2 | + * 类型映射配置 | ||
3 | + * @author: chenfeng<feng.chen@yoho.cn> | ||
4 | + * @date: 2017/02/20 | ||
5 | + */ | ||
6 | + | ||
7 | +'use strict'; | ||
8 | + | ||
9 | +const channels = { | ||
10 | + boys: 1, | ||
11 | + girl: 2, | ||
12 | + girls: 2, | ||
13 | + kids: 3, | ||
14 | + lifestyle: 4 | ||
15 | +}; | ||
16 | + | ||
17 | +let gender = { | ||
18 | + boys: '1,3', | ||
19 | + girl: '2,3', | ||
20 | + girls: '2,3', | ||
21 | + kids: '3,3', | ||
22 | + lifestyle: '4' | ||
23 | +}; | ||
24 | + | ||
25 | +module.exports = { | ||
26 | + channels, | ||
27 | + gender | ||
28 | +}; |
doraemon/middleware/rewrite.js
0 → 100644
1 | +/** | ||
2 | + * 路由重写 | ||
3 | + * @author: chenfeng<feng.chen@yoho.cn> | ||
4 | + * @date: 2017/2/20 | ||
5 | + */ | ||
6 | +'use strict'; | ||
7 | + | ||
8 | +const typeLib = require('../../config/type-lib'); | ||
9 | + | ||
10 | +const gender = (req, res, next) => { | ||
11 | + let genderName = req.params[0]; | ||
12 | + | ||
13 | + if (!genderName || !typeLib.gender[genderName]) { | ||
14 | + return next(); | ||
15 | + } | ||
16 | + req.query.gender = typeLib.gender[genderName]; | ||
17 | + return next(); | ||
18 | +}; | ||
19 | + | ||
20 | +const channel = (req, res, next) => { | ||
21 | + let channelName = req.params[0]; | ||
22 | + | ||
23 | + if (!channelName) { | ||
24 | + return next(); | ||
25 | + } | ||
26 | + req.query.channel = channelName; | ||
27 | + req.yoho.channel = channelName; | ||
28 | + res.locals.channel = channelName; | ||
29 | + req.yoho.pageChannel = {[channelName]: true}; | ||
30 | + if (typeLib.channels[channelName] <= 2) { | ||
31 | + req.query.gender = typeLib.gender[channelName]; | ||
32 | + } | ||
33 | + return next(); | ||
34 | +}; | ||
35 | + | ||
36 | +module.exports = { | ||
37 | + gender, | ||
38 | + channel | ||
39 | +}; |
@@ -45,7 +45,7 @@ function getBrandList() { | @@ -45,7 +45,7 @@ function getBrandList() { | ||
45 | $.ajax({ | 45 | $.ajax({ |
46 | url: '/brands/getBrandList', | 46 | url: '/brands/getBrandList', |
47 | data: { | 47 | data: { |
48 | - channel: window.queryString.channel | 48 | + channel: window.queryString.channel || $('.query-param[data-attr="yhChannel"]').val() |
49 | }, | 49 | }, |
50 | success: function(data) { | 50 | success: function(data) { |
51 | $('#placeholder-brandlist').replaceWith(listHbs(data)); | 51 | $('#placeholder-brandlist').replaceWith(listHbs(data)); |
@@ -284,8 +284,15 @@ function searchResult() { | @@ -284,8 +284,15 @@ function searchResult() { | ||
284 | }); | 284 | }); |
285 | 285 | ||
286 | $genderItem.on('touchstart', function() { | 286 | $genderItem.on('touchstart', function() { |
287 | - var index = $(this).data('id') + 1; | ||
288 | - window.location.search = 'channel=' + index; | 287 | + if (window.queryString.channel) { |
288 | + var index = $(this).data('id') + 1; | ||
289 | + window.location.search = 'channel=' + index; | ||
290 | + } else { | ||
291 | + let name = $(this).data('name').toLowerCase(); | ||
292 | + | ||
293 | + window.location.href = `/${name}-brands`; | ||
294 | + } | ||
295 | + | ||
289 | }); | 296 | }); |
290 | 297 | ||
291 | $brandItem.on('click', function() { | 298 | $brandItem.on('click', function() { |
@@ -13,6 +13,7 @@ var $ = require('yoho-jquery'), | @@ -13,6 +13,7 @@ var $ = require('yoho-jquery'), | ||
13 | lazyload = require('yoho-jquery-lazyload'); | 13 | lazyload = require('yoho-jquery-lazyload'); |
14 | 14 | ||
15 | var search = require('./sale/search'); | 15 | var search = require('./sale/search'); |
16 | +var defaultOpt = require('../common/query-param'); | ||
16 | 17 | ||
17 | require('../common'); | 18 | require('../common'); |
18 | 19 | ||
@@ -52,7 +53,7 @@ $(function() { | @@ -52,7 +53,7 @@ $(function() { | ||
52 | $.ajax({ | 53 | $.ajax({ |
53 | url: '/product/sale/search', | 54 | url: '/product/sale/search', |
54 | data: { | 55 | data: { |
55 | - yh_channel: window.queryString.channel || 'boys', | 56 | + yh_channel: window.queryString.channel || defaultOpt.channel || 'boys', |
56 | saleType: '2', | 57 | saleType: '2', |
57 | productPool: $vipFloor.data('id'), | 58 | productPool: $vipFloor.data('id'), |
58 | limit: '4' | 59 | limit: '4' |
@@ -106,7 +106,7 @@ if ($('.sale-vip-page').length > 0) { | @@ -106,7 +106,7 @@ if ($('.sale-vip-page').length > 0) { | ||
106 | 106 | ||
107 | // 获取频道 | 107 | // 获取频道 |
108 | $.extend(defaultOpt, { | 108 | $.extend(defaultOpt, { |
109 | - yh_channel: getUrlParam('channel') || 'all' | 109 | + yh_channel: getUrlParam('channel') || defaultOpt.channel || 'all' |
110 | }); | 110 | }); |
111 | 111 | ||
112 | // 判断导航类型 | 112 | // 判断导航类型 |
-
Please register or login to post a comment