|
@@ -54,11 +54,14 @@ module.exports = function(req, res, next) { |
|
@@ -54,11 +54,14 @@ module.exports = function(req, res, next) { |
54
|
if(guestAccessList[method+":"+path]||req.session.user) {
|
54
|
if(guestAccessList[method+":"+path]||req.session.user) {
|
55
|
//判断是否已存在appendData
|
55
|
//判断是否已存在appendData
|
56
|
if(!res.appendData) {
|
56
|
if(!res.appendData) {
|
57
|
- res.appendData = req.session.user;
|
57
|
+ res.appendData = _.cloneDeep(req.session.user);
|
58
|
} else {
|
58
|
} else {
|
59
|
- res.appendData = _.merge(res.appendData,req.session.user);
|
59
|
+ res.appendData = _.merge({},res.appendData,req.session.user);
|
60
|
}
|
60
|
}
|
61
|
|
61
|
|
|
|
62
|
+ //添加当前菜单激活
|
|
|
63
|
+ addActiveMenu(req,res);
|
|
|
64
|
+
|
62
|
//添加管理员信息到http头
|
65
|
//添加管理员信息到http头
|
63
|
if(req.session.user) {
|
66
|
if(req.session.user) {
|
64
|
appendAdminInfo(req,req.session.user.auth);
|
67
|
appendAdminInfo(req,req.session.user.auth);
|
|
@@ -73,6 +76,40 @@ module.exports = function(req, res, next) { |
|
@@ -73,6 +76,40 @@ module.exports = function(req, res, next) { |
73
|
}
|
76
|
}
|
74
|
|
77
|
|
75
|
/**
|
78
|
/**
|
|
|
79
|
+ * 添加当前激活的菜单
|
|
|
80
|
+ * @param {Object} req 请求对象
|
|
|
81
|
+ * @param {Object} res 返回对象
|
|
|
82
|
+ */
|
|
|
83
|
+function addActiveMenu(req,res) {
|
|
|
84
|
+ var curUrl = req.originalUrl;
|
|
|
85
|
+ var lastOpen = req.headers['referer'];
|
|
|
86
|
+ var hasActive = false;
|
|
|
87
|
+ if(!res.appendData||!res.appendData.menu) {
|
|
|
88
|
+ return;
|
|
|
89
|
+ }
|
|
|
90
|
+ var menu = _.cloneDeep(res.appendData.menu);
|
|
|
91
|
+
|
|
|
92
|
+ function loop(list,condition) {
|
|
|
93
|
+ _.forEach(menu,function(v,k) {
|
|
|
94
|
+ _.forEach(v.menu,function(val,key) {
|
|
|
95
|
+ if(condition(val.href,curUrl)) {
|
|
|
96
|
+ v.active = 'active';
|
|
|
97
|
+ val.active = 'active';
|
|
|
98
|
+ hasActive = true;
|
|
|
99
|
+ }
|
|
|
100
|
+ });
|
|
|
101
|
+ });
|
|
|
102
|
+ }
|
|
|
103
|
+
|
|
|
104
|
+ loop(menu,function(url) { return url === curUrl;});
|
|
|
105
|
+
|
|
|
106
|
+ if(!hasActive && lastOpen) {
|
|
|
107
|
+ loop(menu,function(url) { return lastOpen.indexOf(url)>-1;});
|
|
|
108
|
+ }
|
|
|
109
|
+ res.appendData.menu = menu;
|
|
|
110
|
+}
|
|
|
111
|
+
|
|
|
112
|
+/**
|
76
|
* 检查路径是否没有权限
|
113
|
* 检查路径是否没有权限
|
77
|
* @param {String} path
|
114
|
* @param {String} path
|
78
|
* @param {Object} req
|
115
|
* @param {Object} req
|
|
@@ -98,7 +135,7 @@ function checkPath(path,req) { |
|
@@ -98,7 +135,7 @@ function checkPath(path,req) { |
98
|
* @return {Object} 用户信息对象
|
135
|
* @return {Object} 用户信息对象
|
99
|
*/
|
136
|
*/
|
100
|
function appendAdminInfo(req,auth) {
|
137
|
function appendAdminInfo(req,auth) {
|
101
|
- var ipObject = ipaddr.process(req.ip).octets
|
138
|
+ var ipObject = ipaddr.process(req.ip).octets;
|
102
|
var ip = ipObject?ipObject.join('.'):req.ip;
|
139
|
var ip = ipObject?ipObject.join('.'):req.ip;
|
103
|
req._yoheaders = {
|
140
|
req._yoheaders = {
|
104
|
'x-user-id':auth.pid,
|
141
|
'x-user-id':auth.pid,
|