display.js
1.14 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
/**
* 渲染布局
* @author: yyq<yanqing.yang@yoho.cn>
* @date: 2016/7/4
*/
'use strict';
const _ = require('lodash');
const header = require('../models/header');
module.exports = () => {
return (req, res, next) => {
res.display = (path, data) => {
let isHead = true;
// 判断是否隐藏公共布局
if (_.isBoolean(data.layout) && !data.layout) {
isHead = false;
}
// 判断是否显示默认头部
if (_.isBoolean(data.defaultHeader) && !data.defaultHeader) {
_.unset(data, 'defaultHeader');
isHead = false;
}
if (!isHead) {
res.render(path, data);
} else {
header.requestHeaderData('boys').then(result => {
Object.assign(data, result);
// 登录状态
if (req.user.uid) {
data.pageHeader.userName = req.user.username;
}
res.render(path, data);
}).catch(next);
}
};
next();
};
};