channel.js
1.85 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 channelModel = require('../models/channel');
const channelMap = {
men: '9ee58aadd9559d07207fe4a98843eaac',
women: '3ad8826fc89fb0d023a4cd06a6991219',
lifestyle: 'aa8d34c85934c2ccc16e2babd3eb5e47'
};
const _ = require('lodash');
/**
* 频道选择页
*/
module.exports = {
index(req, res, next) {
let channel = req.path.split('/')[1] || req.yoho.channel;
channelModel.getResourcesData({
contentCode: channelMap[channel]
}).then(result => {
const resources = result.slice(0, 3);
_.each(resources, (resource) => {
// 只拿第一个数据
if (_.isArray(resource.data)) {
resource.data = [resource.data[0]];
}
});
res.locals.resources = resources;
res.render('index', {
module: 'channel',
page: 'home',
channel: channel
});
}).catch(next);
},
channel(req, res, next) {
channelModel.getChannelData().then(result => {
return res.json(result);
}).catch(next);
},
resources(req, res, next) {
channelModel.getResourcesData(req.query).then(result => {
return res.json(result);
}).catch(next);
},
goods(req, res, next) {
channelModel.getGoodsData(req.query).then(result => {
return res.json(result);
}).catch(next);
},
sidebar(req, res, next) {
if (!req.xhr) {
return res.render('sidebar', {
module: 'channel',
page: 'sidebar'
});
}
channelModel.getSidebarData(req.query).then(result => {
return res.json(result);
}).catch(next);
}
};