Authored by 陈峰

优化rewrite

@@ -26,8 +26,7 @@ let index = (req, res, next) => { @@ -26,8 +26,7 @@ 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; 29 + let channel;
31 30
32 if (!req.query.channel) { 31 if (!req.query.channel) {
33 channel = '1'; 32 channel = '1';
@@ -36,17 +35,9 @@ let index = (req, res, next) => { @@ -36,17 +35,9 @@ let index = (req, res, next) => {
36 } else { 35 } else {
37 channel = typeLib.channels[req.query.channel] + ''; 36 channel = typeLib.channels[req.query.channel] + '';
38 } 37 }
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 - }  
46 38
47 let param = { 39 let param = {
48 - channel,  
49 - gender 40 + channel
50 }; 41 };
51 42
52 indexModel.getBrandByChannel(param.channel).then(result => { 43 indexModel.getBrandByChannel(param.channel).then(result => {
@@ -59,10 +50,16 @@ let index = (req, res, next) => { @@ -59,10 +50,16 @@ let index = (req, res, next) => {
59 }; 50 };
60 51
61 // 301到新路由 52 // 301到新路由
62 -let indexRedirect = (req, res, next) => {  
63 - let channel = typeLib.channelNames[req.query.channel || 1];  
64 - res.redirect(`/${channel || 'boys'}-brands`);  
65 -} 53 +let indexRedirect = (req, res) => {
  54 + let channel;
  55 +
  56 + if (req.query.channel >= 0) {
  57 + channel = typeLib.channelNames[req.query.channel];
  58 + } else {
  59 + channel = req.query.channel || req.yoho.channel;
  60 + }
  61 + res.redirect(`${channel}-brands`);
  62 +};
66 63
67 let brandList = (req, res, next) => { 64 let brandList = (req, res, next) => {
68 var channel = req.query.channel || '1'; 65 var channel = req.query.channel || '1';
@@ -27,7 +27,7 @@ router.get('/(:channel)/bottomBanner', channel.bottomBanner); @@ -27,7 +27,7 @@ router.get('/(:channel)/bottomBanner', channel.bottomBanner);
27 27
28 router.get('/cate', cate.index); 28 router.get('/cate', cate.index);
29 router.get('/brands', brandController.indexRedirect); // 品牌首页 29 router.get('/brands', brandController.indexRedirect); // 品牌首页
30 -router.get(/^\/([a-zA-Z]+)-brands/, rewrite.channel, brandController.index); // 品牌首页 SEO优化 30 +router.get(/^\/(.*?)-brands/, rewrite.resolve, brandController.index); // 品牌首页 SEO优化
31 router.get('/brands/search', brandController.search); // 品牌搜索页 31 router.get('/brands/search', brandController.search); // 品牌搜索页
32 router.get('/brands/getBrandList', brandController.brandList); // 获取品牌列表 32 router.get('/brands/getBrandList', brandController.brandList); // 获取品牌列表
33 router.post('/brands/searchAsync', brandController.searchAsync); // 品牌搜索异步数据 33 router.post('/brands/searchAsync', brandController.searchAsync); // 品牌搜索异步数据
@@ -6,6 +6,7 @@ @@ -6,6 +6,7 @@
6 'use strict'; 6 'use strict';
7 7
8 const mRoot = '../models'; 8 const mRoot = '../models';
  9 +const typeLib = require('../../../config/type-lib');
9 const indexModel = require(`${mRoot}/index`); 10 const indexModel = require(`${mRoot}/index`);
10 const headerModel = require('../../../doraemon/models/header'); // 头部model 11 const headerModel = require('../../../doraemon/models/header'); // 头部model
11 const footerModel = require('../../../doraemon/models/footer_tab'); // 底部tab 12 const footerModel = require('../../../doraemon/models/footer_tab'); // 底部tab
@@ -29,7 +30,7 @@ const editor = (req, res, next) => { @@ -29,7 +30,7 @@ const editor = (req, res, next) => {
29 title = '编辑简介', 30 title = '编辑简介',
30 parameter = {}, 31 parameter = {},
31 isApp = req.yoho.isApp, 32 isApp = req.yoho.isApp,
32 - gender = req.query.gender || req.cookies._Channel && channels[req.cookies._Channel] || 1; 33 + gender = req.query.gender || req.query.channel && typeLib.channels[req.query.channel] || req.cookies._Channel && channels[req.cookies._Channel] || 1;
33 34
34 if (isApp) { 35 if (isApp) {
35 uid = req.query.uid; 36 uid = req.query.uid;
@@ -40,7 +41,6 @@ const editor = (req, res, next) => { @@ -40,7 +41,6 @@ const editor = (req, res, next) => {
40 }) 41 })
41 }; 42 };
42 } 43 }
43 -  
44 return Promise.all([indexModel.getAuthor(id), indexModel.getArticleList(gender, 0, uid, udid, 1, null, id)]).then(datas => { 44 return Promise.all([indexModel.getAuthor(id), indexModel.getArticleList(gender, 0, uid, udid, 1, null, id)]).then(datas => {
45 let authorData = datas[0], 45 let authorData = datas[0],
46 articleListData = datas[1]; 46 articleListData = datas[1];
@@ -80,6 +80,15 @@ const editor = (req, res, next) => { @@ -80,6 +80,15 @@ const editor = (req, res, next) => {
80 80
81 }; 81 };
82 82
  83 +// 301到新路由
  84 +const editorRedirect = (req, res, next) => {
  85 + if (req.query.id) {
  86 + res.redirect(`${req.query.id}`);
  87 + } else {
  88 + return next();
  89 + }
  90 +};
  91 +
83 /** 92 /**
84 * [逛列表页面的资讯分页] 93 * [逛列表页面的资讯分页]
85 * @param {[type]} req [description] 94 * @param {[type]} req [description]
@@ -275,5 +284,6 @@ module.exports = { @@ -275,5 +284,6 @@ module.exports = {
275 index, 284 index,
276 tag, 285 tag,
277 listDynamicData, 286 listDynamicData,
278 - detailDynamicData 287 + detailDynamicData,
  288 + editorRedirect
279 }; 289 };
@@ -6,6 +6,7 @@ @@ -6,6 +6,7 @@
6 'use strict'; 6 'use strict';
7 const helpers = global.yoho.helpers; 7 const helpers = global.yoho.helpers;
8 const mRoot = '../models'; 8 const mRoot = '../models';
  9 +const typeLib = require('../../../config/type-lib');
9 const _ = require('lodash'); 10 const _ = require('lodash');
10 const infoModel = require(`${mRoot}/info`); 11 const infoModel = require(`${mRoot}/info`);
11 const stringProcess = require(`${global.utils}/string-process`); 12 const stringProcess = require(`${global.utils}/string-process`);
@@ -284,13 +285,14 @@ const _shareInfo = (id, getArticle) => { @@ -284,13 +285,14 @@ const _shareInfo = (id, getArticle) => {
284 * [逛资讯详情页] 285 * [逛资讯详情页]
285 */ 286 */
286 const index = (req, res, next) => { 287 const index = (req, res, next) => {
  288 + console.log(req.query)
287 let id = req.query.id || req.params[0] || req.params.id, 289 let id = req.query.id || req.params[0] || req.params.id,
288 - gender = req.query.gender || req.cookies._Channel && channels[req.cookies._Channel] || 1, 290 + gender = req.query.gender || req.query.channel && typeLib.channels[req.query.channel] || req.cookies._Channel && channels[req.cookies._Channel] || 1,
289 isApp = req.query.app_version || req.query.appVersion || false, // 标识是不是APP访问的 291 isApp = req.query.app_version || req.query.appVersion || false, // 标识是不是APP访问的
290 parameter = {}, 292 parameter = {},
291 title = '逛', 293 title = '逛',
292 isWeixin = req.yoho.isWechat, 294 isWeixin = req.yoho.isWechat,
293 - channel = req.cookies._Channel, 295 + channel = req.query.channel || req.cookies._Channel,
294 isqq = req.yoho.isqq, 296 isqq = req.yoho.isqq,
295 isWeibo = req.yoho.isWeibo, 297 isWeibo = req.yoho.isWeibo,
296 isShare; 298 isShare;
@@ -427,6 +429,15 @@ const index = (req, res, next) => { @@ -427,6 +429,15 @@ const index = (req, res, next) => {
427 }).catch(next); 429 }).catch(next);
428 }; 430 };
429 431
  432 +// 301到新路由
  433 +const indexRedirect = (req, res, next) => {
  434 + if (req.query.id) {
  435 + res.redirect(`${req.query.id}`);
  436 + } else {
  437 + return next();
  438 + }
  439 +};
  440 +
430 /** 441 /**
431 * [逛mini内容页] 442 * [逛mini内容页]
432 */ 443 */
@@ -567,5 +578,6 @@ const foryoho = (req, res, next) => { @@ -567,5 +578,6 @@ const foryoho = (req, res, next) => {
567 module.exports = { 578 module.exports = {
568 index, 579 index,
569 mini, 580 mini,
570 - foryoho 581 + foryoho,
  582 + indexRedirect
571 }; 583 };
@@ -24,7 +24,7 @@ exports.index = (req, res, next) => { @@ -24,7 +24,7 @@ exports.index = (req, res, next) => {
24 let isApp = req.query.app_version || req.query.appVersion || false; 24 let isApp = req.query.app_version || req.query.appVersion || false;
25 let parameter = {}; 25 let parameter = {};
26 let title = '潮流优选'; 26 let title = '潮流优选';
27 - let gender = req.query.gender || req.cookies._Channel && channels[req.cookies._Channel] || 1; 27 + let gender = req.query.gender || req.query.channel && typeLib.channels[req.query.channel] || req.cookies._Channel && channels[req.cookies._Channel] || 1;
28 28
29 if (isApp === false) { 29 if (isApp === false) {
30 parameter = { 30 parameter = {
@@ -79,12 +79,16 @@ exports.index = (req, res, next) => { @@ -79,12 +79,16 @@ exports.index = (req, res, next) => {
79 }; 79 };
80 80
81 // 301 到新路由 81 // 301 到新路由
82 -exports.indexRedirect = (req, res, next) => { 82 +exports.indexRedirect = (req, res) => {
83 let channel; 83 let channel;
84 - if (req.query.channel) {  
85 - channel = req.query.channel; 84 +
  85 + if (req.query.channel >= 0) {
  86 + channel = typeLib.channelNames[req.query.channel];
  87 + } else if (req.query.channel) {
  88 + channel = req.query.channel;
86 } else if (req.query.gender) { 89 } else if (req.query.gender) {
87 let gender = req.query.gender; 90 let gender = req.query.gender;
  91 +
88 switch (gender) { 92 switch (gender) {
89 case typeLib.gender.boys: 93 case typeLib.gender.boys:
90 gender = 1; 94 gender = 1;
@@ -101,8 +105,9 @@ exports.indexRedirect = (req, res, next) => { @@ -101,8 +105,9 @@ exports.indexRedirect = (req, res, next) => {
101 } 105 }
102 channel = typeLib.channelNames[gender]; 106 channel = typeLib.channelNames[gender];
103 } 107 }
104 - res.redirect(`/guang/${channel || 'boys'}-plusstar`);  
105 -} 108 + channel = channel || req.yoho.channel;
  109 + res.redirect(`${channel}-plusstar`);
  110 +};
106 111
107 exports.userSkn = (req, res, next) => { 112 exports.userSkn = (req, res, next) => {
108 let isApp = req.body.app_version || req.body.appVersion || false; 113 let isApp = req.body.app_version || req.body.appVersion || false;
@@ -33,7 +33,7 @@ router.post('/star/setFavorite', star.setFavorite); // 收藏文章 @@ -33,7 +33,7 @@ router.post('/star/setFavorite', star.setFavorite); // 收藏文章
33 router.get('/', homeController.index); // 逛首页 33 router.get('/', homeController.index); // 逛首页
34 34
35 router.get('/plusstar', plusstar.indexRedirect); // 潮流优选 35 router.get('/plusstar', plusstar.indexRedirect); // 潮流优选
36 -router.get(/^\/([a-zA-Z]+)-plusstar/, rewrite.channel, plusstar.index); // 潮流优选 SEO优化 36 +router.get(/^\/(.*?)-plusstar/, rewrite.resolve, plusstar.index); // 潮流优选 SEO优化
37 router.post('/plusstar/userSkn', plusstar.userSkn); // 用户推荐skn 37 router.post('/plusstar/userSkn', plusstar.userSkn); // 用户推荐skn
38 router.get('/plusstar/resources-template', plusstar.resourcesTemplate); // 潮流优选首页-资源位 38 router.get('/plusstar/resources-template', plusstar.resourcesTemplate); // 潮流优选首页-资源位
39 router.post('/plusstar/resources-goodsList', plusstar.resourcesGoodsList); // 潮流优选首页-资源位-商品列表 39 router.post('/plusstar/resources-goodsList', plusstar.resourcesGoodsList); // 潮流优选首页-资源位-商品列表
@@ -41,7 +41,7 @@ router.get('/', index.index); // 逛首页 @@ -41,7 +41,7 @@ router.get('/', index.index); // 逛首页
41 router.get('/tags/index', index.tag); // 逛标签页 41 router.get('/tags/index', index.tag); // 逛标签页
42 42
43 router.get('/author/index', index.editor); // 编辑简介 43 router.get('/author/index', index.editor); // 编辑简介
44 -router.get(/^\/author\/(\d+)/, index.editor); // 编辑简介 SEO优化 44 +router.get(/^\/author\/([a-zA-Z]+-\d+)/, rewrite.resolve, index.editor); // 编辑简介 SEO优化
45 45
46 router.get('/index/page', index.pageData); // 逛列表页面的资讯分页 46 router.get('/index/page', index.pageData); // 逛列表页面的资讯分页
47 47
@@ -50,7 +50,7 @@ router.post('/opt/collectArticle', opt.collectArticle); // 资讯文章收藏 (H @@ -50,7 +50,7 @@ router.post('/opt/collectArticle', opt.collectArticle); // 资讯文章收藏 (H
50 router.post('/opt/favoriteBrand', opt.favoriteBrand); // 品牌收藏 50 router.post('/opt/favoriteBrand', opt.favoriteBrand); // 品牌收藏
51 51
52 router.get('/info/index', info.index); // 逛详情页 52 router.get('/info/index', info.index); // 逛详情页
53 -router.get(/^\/info\/(\d+)/, info.index); // 逛详情页 SEO优化 53 +router.get(/^\/info\/([a-zA-Z]+-\d+)/, rewrite.resolve, info.index); // 逛详情页 SEO优化
54 router.get('/:id.html', info.index); // 逛详情页(兼容 PC 跳转过来的链接) 54 router.get('/:id.html', info.index); // 逛详情页(兼容 PC 跳转过来的链接)
55 router.get('/info/mini', info.mini); // 逛mini内容页 55 router.get('/info/mini', info.mini); // 逛mini内容页
56 router.get('/info/foryoho', info.foryoho); // 逛foryoho内容页 56 router.get('/info/foryoho', info.foryoho); // 逛foryoho内容页
@@ -13,6 +13,7 @@ const newModel = require(`${mRoot}/new`); @@ -13,6 +13,7 @@ const newModel = require(`${mRoot}/new`);
13 const searchModel = require(`${mRoot}/search`); 13 const searchModel = require(`${mRoot}/search`);
14 const _ = require('lodash'); 14 const _ = require('lodash');
15 const helpers = global.yoho.helpers; 15 const helpers = global.yoho.helpers;
  16 +const typeLib = require('../../../config/type-lib');
16 17
17 // 新品到着(blk) 18 // 新品到着(blk)
18 const blkNewGoods = (req, res, next) => { 19 const blkNewGoods = (req, res, next) => {
@@ -79,10 +80,16 @@ const newGoods = (req, res, next) => { @@ -79,10 +80,16 @@ const newGoods = (req, res, next) => {
79 }; 80 };
80 81
81 // 301到新路由 82 // 301到新路由
82 -const newGoodsRedirect = (req, res, next) => {  
83 - let channel = req.query.channel || 'boys';  
84 - res.redirect(`/product/${channel}-new`);  
85 -} 83 +const newGoodsRedirect = (req, res) => {
  84 + let channel;
  85 +
  86 + if (req.query.channel >= 0) {
  87 + channel = typeLib.channelNames[req.query.channel];
  88 + } else {
  89 + channel = req.query.channel || req.yoho.channel;
  90 + }
  91 + res.redirect(`${channel}-new`);
  92 +};
86 93
87 /** 94 /**
88 * 重构的新品到着页面 95 * 重构的新品到着页面
@@ -10,6 +10,7 @@ const mRoot = '../models'; @@ -10,6 +10,7 @@ const mRoot = '../models';
10 // const cookie = require(`${library}/cookie`); 10 // const cookie = require(`${library}/cookie`);
11 const headerModel = require('../../../doraemon/models/header'); 11 const headerModel = require('../../../doraemon/models/header');
12 const saleModel = require(`${mRoot}/sale`); 12 const saleModel = require(`${mRoot}/sale`);
  13 +const typeLib = require('../../../config/type-lib');
13 14
14 // const queryParam = { 15 // const queryParam = {
15 // brand: '0', 16 // brand: '0',
@@ -68,11 +69,13 @@ let index = (req, res, next) => { @@ -68,11 +69,13 @@ let index = (req, res, next) => {
68 69
69 let params = _processPublicData(req, 'SALE', 'sale', backUrl); 70 let params = _processPublicData(req, 'SALE', 'sale', backUrl);
70 71
  72 + params.channel = req.query.channel || params.channel;
  73 +
71 saleModel.getSaleData(params.channel).then((result) => { 74 saleModel.getSaleData(params.channel).then((result) => {
72 75
73 // 扩展头部频道选择数据 76 // 扩展头部频道选择数据
74 Object.assign(params.renderData.pageHeader, { 77 Object.assign(params.renderData.pageHeader, {
75 - saleNav: saleModel.saleNav(req.yoho.channel, req.params[0] || !req.query.channel) 78 + saleNav: saleModel.saleNav(params.channel, req.params[0] || !req.query.channel)
76 }); 79 });
77 80
78 // 此处 channel 需要读取 cookies 的 channel 81 // 此处 channel 需要读取 cookies 的 channel
@@ -97,10 +100,18 @@ let index = (req, res, next) => { @@ -97,10 +100,18 @@ let index = (req, res, next) => {
97 }; 100 };
98 101
99 // 301到新路由 102 // 301到新路由
100 -let indexRedirect = (req, res, next) => {  
101 - let channel = req.query.channel || 'boys';  
102 - res.redirect(`/product/${channel}-sale`);  
103 -} 103 +let indexRedirect = (req, res) => {
  104 + let channel;
  105 +
  106 + if (req.query.channel >= 0) {
  107 + channel = typeLib.channelNames[req.query.channel];
  108 + } else {
  109 + channel = req.query.channel || req.yoho.channel;
  110 + }
  111 +
  112 + res.redirect(`${channel}-sale`);
  113 +};
  114 +
104 /** 115 /**
105 * 断码区 116 * 断码区
106 * @param {[object]} req 117 * @param {[object]} req
@@ -63,7 +63,7 @@ router.get(/^\/seckill\/pro_([\d]+)_([\d]+)/, seckillDetail.index); // 秒杀商 @@ -63,7 +63,7 @@ router.get(/^\/seckill\/pro_([\d]+)_([\d]+)/, seckillDetail.index); // 秒杀商
63 router.get(/^\/pro_([\d]+)_([\d]+)/, newDetail.index); // 商品详情页 63 router.get(/^\/pro_([\d]+)_([\d]+)/, newDetail.index); // 商品详情页
64 // /show_51047967.html 64 // /show_51047967.html
65 router.get(/^\/show_([\d]+)/, newDetail.index); // 商品详情页 SKN 进入 65 router.get(/^\/show_([\d]+)/, newDetail.index); // 商品详情页 SKN 进入
66 -router.get(/^\/p([\d]+)\.html/, newDetail.index); // 商品详情页 SKN 进入 SEO优化 66 +// router.get(/^\/p([\d]+)\.html/, newDetail.index); // 商品详情页 SKN 进入 SEO优化
67 67
68 router.get('/detail/sknData.json', newDetail.sknData); // 商品咨询,评价,店铺 68 router.get('/detail/sknData.json', newDetail.sknData); // 商品咨询,评价,店铺
69 router.get('/detail/intro/:productskn', detail.intro); // 商品内嵌页 69 router.get('/detail/intro/:productskn', detail.intro); // 商品内嵌页
@@ -89,11 +89,13 @@ router.post('/detail/consultupvote', detail.consultUpvoteOrUseful); // 商品咨 @@ -89,11 +89,13 @@ router.post('/detail/consultupvote', detail.consultUpvoteOrUseful); // 商品咨
89 router.post('/detail/consultuseful', detail.consultUpvoteOrUseful); // 商品咨询提交接口 89 router.post('/detail/consultuseful', detail.consultUpvoteOrUseful); // 商品咨询提交接口
90 90
91 router.get('/sale', sale.indexRedirect); 91 router.get('/sale', sale.indexRedirect);
92 -router.get(/^\/([a-zA-Z]+)-sale/, rewrite.channel, sale.index); // 折扣专区 SEO优化 92 +router.get(/^\/(.*?)-sale\/?$/, rewrite.resolve, sale.index); // 折扣专区 SEO优化
93 93
94 router.get('/sale/discount', sale.discount); 94 router.get('/sale/discount', sale.discount);
  95 +// router.get(/^\/(.*?)-sale\/discount/, rewrite.resolve, sale.discount);
95 router.get('/sale/discount/detail', sale.discountDetail); 96 router.get('/sale/discount/detail', sale.discountDetail);
96 router.get('/sale/breakingYards', sale.breakingYards); 97 router.get('/sale/breakingYards', sale.breakingYards);
  98 +// router.get(/^\/(.*?)-sale\/breakingYards/, rewrite.resolve, sale.breakingYards); // SEO优化
97 router.get('/sale/vip', sale.vip); 99 router.get('/sale/vip', sale.vip);
98 router.get('/sale/discount/getTime', sale.getTime); 100 router.get('/sale/discount/getTime', sale.getTime);
99 101
@@ -164,7 +166,7 @@ router.get('/opt/favoriteBrand', list.favoriteBrand); @@ -164,7 +166,7 @@ router.get('/opt/favoriteBrand', list.favoriteBrand);
164 router.get('/new', news.newGoodsRedirect); 166 router.get('/new', news.newGoodsRedirect);
165 167
166 // 新品到着 SEO优化 168 // 新品到着 SEO优化
167 -router.get(/^\/([a-zA-Z]+)-new/, rewrite.channel, news.newGoods); 169 +router.get(/^\/(.*?)-new/, rewrite.resolve, news.newGoods);
168 170
169 router.get('/list/new', news.newGoods); // 兼容 PC 的链接 171 router.get('/list/new', news.newGoods); // 兼容 PC 的链接
170 router.get('/new/selectNewSale', news.selectNewSale); 172 router.get('/new/selectNewSale', news.selectNewSale);
@@ -15,10 +15,10 @@ const channels = { @@ -15,10 +15,10 @@ const channels = {
15 }; 15 };
16 16
17 const channelNames = { 17 const channelNames = {
18 - '1': 'boys',  
19 - '2': 'girls',  
20 - '3': 'kids',  
21 - '4': 'lifestyle' 18 + [1]: 'boys',
  19 + [2]: 'girls',
  20 + [3]: 'kids',
  21 + [4]: 'lifestyle'
22 }; 22 };
23 23
24 const gender = { 24 const gender = {
@@ -6,34 +6,40 @@ @@ -6,34 +6,40 @@
6 'use strict'; 6 'use strict';
7 7
8 const typeLib = require('../../config/type-lib'); 8 const typeLib = require('../../config/type-lib');
  9 +const _ = require('lodash');
9 10
10 -const gender = (req, res, next) => {  
11 - let genderName = req.params[0]; 11 +const resolve = (req, res, next) => {
  12 + let path = req.params[0],
  13 + params = {
  14 + channel: req.yoho.channel
  15 + };
12 16
13 - if (!genderName || !typeLib.gender[genderName]) { 17 + if (!path) {
14 return next(); 18 return next();
15 } 19 }
16 - req.query.gender = typeLib.gender[genderName];  
17 - return next();  
18 -}; 20 + let conditions = path.replace('.html', '').split('-');
19 21
20 -const channel = (req, res, next) => {  
21 - let channelName = req.params[0]; 22 + _.each(conditions, condition => {
  23 + if (typeLib.channels[condition]) {
  24 + params.channel = condition;
  25 + } else if (condition.indexOf('_') >= 0) {
  26 + let item = condition.split('_');
22 27
23 - if (!channelName) {  
24 - return next();  
25 - }  
26 - req.query.channel = channelName;  
27 - req.yoho.channel = channelName;  
28 - res.locals.channel = channelName;  
29 - res.locals.pageChannel = {[channelName]: true};  
30 - if (typeLib.channels[channelName] <= 2) {  
31 - req.query.gender = typeLib.gender[channelName];  
32 - }  
33 - return next(); 28 + if (item.length === 2) {
  29 + params[item[0]] = item[1];
  30 + }
  31 + } else if (/\d+/.test(condition)) {
  32 + params.id = _.parseInt(condition);
  33 + }
  34 + });
  35 + req.yoho.channel = params.channel;
  36 + res.locals.channel = params.channel;
  37 + res.locals.pageChannel = { [params.channel]: true };
  38 + res.locals.setChannel = true;
  39 + Object.assign(req.query, params);
  40 + next();
34 }; 41 };
35 42
36 module.exports = { 43 module.exports = {
37 - gender,  
38 - channel 44 + resolve
39 }; 45 };
1 {{#pageHeader}} 1 {{#pageHeader}}
2 {{# @root.pageChannel}} 2 {{# @root.pageChannel}}
3 -<header id="yoho-header" class="yoho-header{{#if boys}} boys{{/if}}{{#if girls}} girls{{/if}}{{#if kids}} kids{{/if}}{{#if lifeStyle}} life-style{{/if}}{{#if lifestyle}} life-style{{/if}}"> 3 +<header id="yoho-header" class="yoho-header{{#if @root.setChannel}} set-channel{{/if}}{{#if boys}} boys{{/if}}{{#if girls}} girls{{/if}}{{#if kids}} kids{{/if}}{{#if lifeStyle}} life-style{{/if}}{{#if lifestyle}} life-style{{/if}}">
4 {{^}} 4 {{^}}
5 <header id="yoho-header" class="yoho-header"> 5 <header id="yoho-header" class="yoho-header">
6 {{/ @root.pageChannel}} 6 {{/ @root.pageChannel}}
@@ -47,7 +47,7 @@ @@ -47,7 +47,7 @@
47 {{/if}} 47 {{/if}}
48 {{#navBtn}} 48 {{#navBtn}}
49 {{# @root.pageChannel}} 49 {{# @root.pageChannel}}
50 -<div class="homebuttom hide {{#if boys}} boys{{/if}}{{#if girls}} girls{{/if}}{{#if kids}} kids{{/if}}{{#if lifeStyle}} life-style{{/if}}{{#if lifestyle}} life-style{{/if}}"> 50 +<div class="homebuttom hide{{#if @root.setChannel}} set-channel{{/if}} {{#if boys}} boys{{/if}}{{#if girls}} girls{{/if}}{{#if kids}} kids{{/if}}{{#if lifeStyle}} life-style{{/if}}{{#if lifestyle}} life-style{{/if}}">
51 {{^}} 51 {{^}}
52 <div class="homebuttom hide"> 52 <div class="homebuttom hide">
53 {{/ @root.pageChannel}} 53 {{/ @root.pageChannel}}
@@ -370,36 +370,38 @@ function givePoint(parameter) { @@ -370,36 +370,38 @@ function givePoint(parameter) {
370 var header = $('#yoho-header, .homebuttom'); 370 var header = $('#yoho-header, .homebuttom');
371 var footer = $('.footer-tab .tab-item.current'); 371 var footer = $('.footer-tab .tab-item.current');
372 372
373 - if (!/^\/home/.test(location.pathname)) {  
374 - switch (channel) {  
375 - case 'boys':  
376 - if (!header.hasClass('boys')) {  
377 - header.addClass('boys');  
378 - }  
379 - break;  
380 - case 'girls':  
381 - if (!header.hasClass('girls')) {  
382 - header.addClass('girls');  
383 - }  
384 - break;  
385 - case 'lifestyle':  
386 - if (!header.hasClass('life-style')) {  
387 - header.addClass('life-style');  
388 - }  
389 - break;  
390 - case 'kids':  
391 - if (!header.hasClass('kids')) {  
392 - header.addClass('kids');  
393 - }  
394 - break;  
395 - default:  
396 - if (!header.hasClass('boys')) {  
397 - header.addClass('boys');  
398 - }  
399 - break; 373 + if (!header.hasClass('set-channel')) {
  374 + if (!/^\/home/.test(location.pathname)) {
  375 + switch (channel) {
  376 + case 'boys':
  377 + if (!header.hasClass('boys')) {
  378 + header.addClass('boys');
  379 + }
  380 + break;
  381 + case 'girls':
  382 + if (!header.hasClass('girls')) {
  383 + header.addClass('girls');
  384 + }
  385 + break;
  386 + case 'lifestyle':
  387 + if (!header.hasClass('life-style')) {
  388 + header.addClass('life-style');
  389 + }
  390 + break;
  391 + case 'kids':
  392 + if (!header.hasClass('kids')) {
  393 + header.addClass('kids');
  394 + }
  395 + break;
  396 + default:
  397 + if (!header.hasClass('boys')) {
  398 + header.addClass('boys');
  399 + }
  400 + break;
  401 + }
  402 + } else {
  403 + header.removeClass('girls', 'life-style', 'kids').addClass('boys');
400 } 404 }
401 - } else {  
402 - header.removeClass('girls', 'life-style', 'kids').addClass('boys');  
403 } 405 }
404 406
405 switch (channel) { 407 switch (channel) {
@@ -83,7 +83,7 @@ function getUrlParam(name) { @@ -83,7 +83,7 @@ function getUrlParam(name) {
83 } 83 }
84 84
85 defaultOpt = $.extend({ 85 defaultOpt = $.extend({
86 - yh_channel: getUrlParam('channel') || 'boys', 86 + yh_channel: getUrlParam('channel') || defaultOpt.channel || 'boys', //TODO GO ON!
87 saleType: 1 87 saleType: 1
88 }, defaultOpt); 88 }, defaultOpt);
89 89
@@ -114,7 +114,6 @@ const formatArticle = (articleData, showTag, isApp, showAuthor, uid, reqQueryStr @@ -114,7 +114,6 @@ const formatArticle = (articleData, showTag, isApp, showAuthor, uid, reqQueryStr
114 } else { 114 } else {
115 // 编辑人员 app跳转url处理 20160601 115 // 编辑人员 app跳转url处理 20160601
116 let isLogin = uid ? true : false; 116 let isLogin = uid ? true : false;
117 -  
118 articleData.author.url = `${helpers.https(articleData.author.url)}&openby:yohobuy={"action":"go.h5","params":{"param":{},"share":"","id":${articleData.author.author_id},"type":0,"islogin":"${isLogin}","url":"${articleData.author.url}"}}`; 117 articleData.author.url = `${helpers.https(articleData.author.url)}&openby:yohobuy={"action":"go.h5","params":{"param":{},"share":"","id":${articleData.author.author_id},"type":0,"islogin":"${isLogin}","url":"${articleData.author.url}"}}`;
119 } 118 }
120 119