help.js
1.89 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/**
* 帮助中心
* @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.siteUrl,
name: 'YOHO!BLK首页'
},
{
name: '帮助中心',
link: '/help'
}
];
data.qid = id;
if (!(typeof (getNav(id)) === 'undefined')) {
nav = nav.concat(getNav(id));
}
res.display('detail', {
module: 'help',
page: 'help',
content: Object.assign({nav}, data),
qid: id
});
};
module.exports = {
index
};