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

'use strict';
const helpModel = require('../models/help');

/**
 * 根据id获取文章数据
 * @param id
 * @returns {*}
 */
/* const getData = (id)=> {
 let contentData = helpModel.contentData().content;

 for (var 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,next) => {
    let id = req.query.id || '11';

    helpModel.getHelpDetail('81', 1, 15, '').then(result=> {
        let content = {content: result.helpdetail_list[0].content};
        let data = Object.assign(content, 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)
        });
    }).catch(next);

    /*  let data = Object.assign(getData(id), helpModel.menuData());
     let nav = [
     {
     link: global.yoho.config.sitUrl,
     name: 'YOHO!BLK首页'
     },
     {
     name: '帮助中心'
     }
     ];
     nav = nav.concat(getNav(id));
     res.display('detail', {
     module: 'help',
     page: 'help',
     content: Object.assign({nav}, data)
     });*/
};


module.exports = {
    index
};