...
|
...
|
@@ -54,11 +54,14 @@ module.exports = function(req, res, next) { |
|
|
if(guestAccessList[method+":"+path]||req.session.user) {
|
|
|
//判断是否已存在appendData
|
|
|
if(!res.appendData) {
|
|
|
res.appendData = req.session.user;
|
|
|
res.appendData = _.cloneDeep(req.session.user);
|
|
|
} else {
|
|
|
res.appendData = _.merge(res.appendData,req.session.user);
|
|
|
res.appendData = _.merge({},res.appendData,req.session.user);
|
|
|
}
|
|
|
|
|
|
//添加当前菜单激活
|
|
|
addActiveMenu(req,res);
|
|
|
|
|
|
//添加管理员信息到http头
|
|
|
if(req.session.user) {
|
|
|
appendAdminInfo(req,req.session.user.auth);
|
...
|
...
|
@@ -73,6 +76,40 @@ module.exports = function(req, res, next) { |
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 添加当前激活的菜单
|
|
|
* @param {Object} req 请求对象
|
|
|
* @param {Object} res 返回对象
|
|
|
*/
|
|
|
function addActiveMenu(req,res) {
|
|
|
var curUrl = req.originalUrl;
|
|
|
var lastOpen = req.headers['referer'];
|
|
|
var hasActive = false;
|
|
|
if(!res.appendData||!res.appendData.menu) {
|
|
|
return;
|
|
|
}
|
|
|
var menu = _.cloneDeep(res.appendData.menu);
|
|
|
|
|
|
function loop(list,condition) {
|
|
|
_.forEach(menu,function(v,k) {
|
|
|
_.forEach(v.menu,function(val,key) {
|
|
|
if(condition(val.href,curUrl)) {
|
|
|
v.active = 'active';
|
|
|
val.active = 'active';
|
|
|
hasActive = true;
|
|
|
}
|
|
|
});
|
|
|
});
|
|
|
}
|
|
|
|
|
|
loop(menu,function(url) { return url === curUrl;});
|
|
|
|
|
|
if(!hasActive && lastOpen) {
|
|
|
loop(menu,function(url) { return lastOpen.indexOf(url)>-1;});
|
|
|
}
|
|
|
res.appendData.menu = menu;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 检查路径是否没有权限
|
|
|
* @param {String} path
|
|
|
* @param {Object} req
|
...
|
...
|
@@ -98,7 +135,7 @@ function checkPath(path,req) { |
|
|
* @return {Object} 用户信息对象
|
|
|
*/
|
|
|
function appendAdminInfo(req,auth) {
|
|
|
var ipObject = ipaddr.process(req.ip).octets
|
|
|
var ipObject = ipaddr.process(req.ip).octets;
|
|
|
var ip = ipObject?ipObject.join('.'):req.ip;
|
|
|
req._yoheaders = {
|
|
|
'x-user-id':auth.pid,
|
...
|
...
|
|