help.js 1.82 KB
/**
 * 帮助中心
 * @author: jiangmin
 * @date: 2016/07/25
 */

'use strict';
const helpModel = require('../models/help');
const contentData = require('../models/content-data');

/**
 * 根据id获取文章数据
 * @param id
 * @returns {*}
 */
const getData = (id)=> {
    for (let i = 0; i < contentData.length; i++) {
        if (contentData[i].id === id) {
            return contentData[i];
        }
    }
};

/**
 * 根据id获取当前所在位置,拼接面包屑
 * @param id
 */
const getNav = (id)=> {
    let menuData = helpModel.menuData().menuData;

    for (let i = 0; i < menuData.length; i++) {
        if (menuData[i].subsets) {
            for (let j = 0; j < menuData[i].subsets.length; j++) {
                if (menuData[i].subsets[j].id === id) {
                    return [
                        {
                            name: menuData[i].text
                        }, {
                            name: menuData[i].subsets[j].text
                        }
                    ];
                }
            }
        } else {
            if (menuData[i].id === id) {
                return [
                    {
                        name: menuData[i].text
                    }
                ];
            }
        }
    }
};

/**
 * 主界面
 */
const index = (req, res) => {
    let id = req.query.id || '1';
    let data = Object.assign(getData(id), helpModel.menuData());
    let nav = [
        {
            link: global.yoho.config.sitUrl,
            name: 'YOHO!BLK首页'
        },
        {
            name: '帮助中心'
        }
    ];

    if (!(typeof (getNav(id)) === 'undefined')) {
        nav = nav.concat(getNav(id));
    }
    res.display('detail', {
        module: 'help',
        page: 'help',
        content: Object.assign({nav}, data)
    });
};


module.exports = {
    index
};