channel.js 1.18 KB
/**
 * 主页
 * @author: Bi Kai<kai.bi@yoho.cn>
 * @date: 2016/05/09
 */
'use strict';
const channelModel = require('../models/channel');

/**
 * 频道选择页
 */
module.exports = {
    index(req, res) {
        let channel = req.path.split('/')[1] || req.yoho.channel;

        res.render('index', {
            module: 'channel',
            page: 'home',
            channel: channel
        });
    },
    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);
    }
};