index.js
1.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/**
* 频道页面
* @author: Bi Kai<kai.bi@yoho.cn>
* @date: 2016/05/09
*/
'use strict';
const _ = require('lodash');
const channelModel = require('../models/channel');
const helpers = require('../../../library/helpers');
const mod = 'channel';
let footerTab = {
indexUrl: helpers.url('/?go=1'), // 首页
categoryUrl: helpers.url('/cate'), // 分类
guangUrl: helpers.url('', null, 'guang'), // 逛首页
shoppingCartUrl: helpers.url('/cart/index/index'), // 购物车
mineUrl: helpers.url('/home') // 个人中心
};
/**
* 频道选择
* @param {object} req
* @param {object} res
* @param {Function} next
* @return {Function}
*/
exports.switchChannel = (req, res, next) => {
let channel = req.cookies._Channel;
// 如果查询字符串设置了 go 参数,跳转到 cookie 中设置的频道页
if (req.query.go && channel) {
res.redirect('/' + channel);
} else {
// 设置浏览器缓存5分钟 300000ms
res.set('Expires', (new Date(_.now() + 300000)).toGMTString());
return next();
}
};
/**
* 男生首页
*/
exports.boys = (req, res) => {
channelModel.getChannelDate({
gender: 'boys',
uid: 123
}).then(result => {
res.render('channel', Object.assign({
module: mod,
page: 'home',
title: '男生首页',
boysHomePage: true,
homeHeader: {
searchUrl: helpers.url('/search', null, 'search')
},
maybeLike: true,
showFooterTab: footerTab,
pageFooter: true
}, result));
}).catch(console.trace);
};
exports.bottomBanner = (req, res) => {
let gender = req.query.gender || 'boys';
channelModel.getBottomBannerDate(gender).then(result => {
res.send(result);
}).catch(console.trace);
};