Authored by weiqingting

灰色代理

@@ -3,7 +3,7 @@ @@ -3,7 +3,7 @@
3 * @type {Object} 3 * @type {Object}
4 */ 4 */
5 module.exports = { 5 module.exports = {
6 - url:'http://admin.portal.yohobuy.com', 6 + url:'http://admin.yohobuy.com',//'http://admin.portal.yohobuy.com',
7 sessionKeep:'/account/profile/display', 7 sessionKeep:'/account/profile/display',
8 timeout:30000 8 timeout:30000
9 }; 9 };
@@ -25,11 +25,7 @@ var errorMessage = { @@ -25,11 +25,7 @@ var errorMessage = {
25 util.setLogger(res.app.logger); 25 util.setLogger(res.app.logger);
26 var options = { 26 var options = {
27 url:oldService.login, 27 url:oldService.login,
28 - form:{  
29 - account:user,  
30 - password:password,  
31 - website:WEBSITE  
32 - } 28 + form:'["'+user+'","'+password+'",1]'//'["zhiyuan","lzy111111",1]'//
33 } 29 }
34 30
35 //调用登陆 31 //调用登陆
@@ -38,8 +34,9 @@ var errorMessage = { @@ -38,8 +34,9 @@ var errorMessage = {
38 res.json(errorMessage); 34 res.json(errorMessage);
39 return; 35 return;
40 } else { 36 } else {
  37 + console.log(ret);
41 //调用菜单 38 //调用菜单
42 - _callGetMenu(ret.data.pid,function(err,data){ 39 + _callGetMenu(ret.data.pid,ret.data.role_id,function(err,data){
43 if(err) { 40 if(err) {
44 res.json(errorMessage); 41 res.json(errorMessage);
45 } else { 42 } else {
@@ -66,24 +63,22 @@ var errorMessage = { @@ -66,24 +63,22 @@ var errorMessage = {
66 * @param {Number} pid 操作员ID 63 * @param {Number} pid 操作员ID
67 * @param {Function} callback 回调 64 * @param {Function} callback 回调
68 */ 65 */
69 -function _callGetMenu(pid,callback) { 66 +function _callGetMenu(pid,roleid,callback) {
70 var options = { 67 var options = {
71 url:oldService.getResourceByPid, 68 url:oldService.getResourceByPid,
72 - form:{  
73 - pid:pid,  
74 - website:WEBSITE  
75 - } 69 + form:'['+pid+','+roleid+',1]'
76 } 70 }
77 - 71 +console.log(options);
78 util.httpCall(options,function(err,ret){ 72 util.httpCall(options,function(err,ret){
79 if(err) { 73 if(err) {
80 callback(err); 74 callback(err);
81 } else { 75 } else {
82 var menuData = {menu:[],right:{}}; 76 var menuData = {menu:[],right:{}};
83 - if(ret.data && ret.data.length>0) { 77 + if(ret.data) {
84 menuData = _makeMenu(ret.data); 78 menuData = _makeMenu(ret.data);
85 } 79 }
86 _getAllMenu(function(ret){ 80 _getAllMenu(function(ret){
  81 + filterRight(ret,menuData);
87 menuData.noRight = filterRight(ret,menuData); 82 menuData.noRight = filterRight(ret,menuData);
88 delete menuData.right; 83 delete menuData.right;
89 callback(null,menuData); 84 callback(null,menuData);
@@ -102,14 +97,17 @@ function _callGetMenu(pid,callback) { @@ -102,14 +97,17 @@ function _callGetMenu(pid,callback) {
102 function filterRight(ret,menuData) { 97 function filterRight(ret,menuData) {
103 var noRight = {}; 98 var noRight = {};
104 //匹配没有权限 99 //匹配没有权限
105 - _.forEach(ret,function(v,k){  
106 - if(v.module_url!=='') {  
107 - if(!menuData.right[v.module_url]) {  
108 - noRight[v.module_url] = true; 100 + for(var key in ret){
  101 + var item=ret[key];
  102 + for(var i in item.sub){
  103 + var v=item.sub[i];
  104 + if(v.menu_url!=='') {
  105 + if(!menuData.right[v.menu_url]) {
  106 + noRight[v.menu_url] = true;
  107 + }
109 } 108 }
110 } 109 }
111 - });  
112 - 110 + }
113 return noRight; 111 return noRight;
114 } 112 }
115 113
@@ -120,7 +118,7 @@ function filterRight(ret,menuData) { @@ -120,7 +118,7 @@ function filterRight(ret,menuData) {
120 function _getAllMenu (callback) { 118 function _getAllMenu (callback) {
121 var options = { 119 var options = {
122 url:oldService.getAllResByWebsite+'?website='+WEBSITE+'&sort=', 120 url:oldService.getAllResByWebsite+'?website='+WEBSITE+'&sort=',
123 - method:'GET' 121 + form:'['+WEBSITE+']'
124 } 122 }
125 123
126 util.httpCall(options,function(err,ret){ 124 util.httpCall(options,function(err,ret){
@@ -140,27 +138,51 @@ function _getAllMenu (callback) { @@ -140,27 +138,51 @@ function _getAllMenu (callback) {
140 function _makeMenu (data) { 138 function _makeMenu (data) {
141 var menu = []; 139 var menu = [];
142 var right = {}; 140 var right = {};
143 - _.forEach(data,function(v){  
144 - var item = {  
145 - title:v.resource_name, 141 + for(var key in data){
  142 +
  143 + var v=data[key];
  144 + var item = {
  145 + title:v.menu_name,
146 } 146 }
147 if(v.parent_id === "0") { 147 if(v.parent_id === "0") {
148 item.parent = 'menu-template'; 148 item.parent = 'menu-template';
149 var itemSubs = []; 149 var itemSubs = [];
150 _.forEach(v.sub,function(val) { 150 _.forEach(v.sub,function(val) {
151 var sub = { 151 var sub = {
152 - title:val.resource_name,  
153 - href:val.module_url, 152 + title:val.menu_name,
  153 + href:val.menu_url,
154 icon: 'list-alt' 154 icon: 'list-alt'
155 } 155 }
156 - right[val.module_url] = true; 156 + right[val.menu_url] = true;
157 itemSubs.push(sub); 157 itemSubs.push(sub);
158 }); 158 });
159 159
160 item.menu = itemSubs; 160 item.menu = itemSubs;
161 } 161 }
162 menu.push(item); 162 menu.push(item);
163 - }); 163 + }
  164 + // _.forEach(data,function(v){
  165 + // var item = {
  166 + // title:v.menu_name,
  167 + // }
  168 + // if(v.parent_id === "0") {
  169 + // item.parent = 'menu-template';
  170 + // var itemSubs = [];
  171 + // _.forEach(v.sub,function(val) {
  172 + // console.log(v.sub);
  173 + // var sub = {
  174 + // title:val.menu_name,
  175 + // href:val.menu_url,
  176 + // icon: 'list-alt'
  177 + // }
  178 + // right[val.menu_url] = true;
  179 + // itemSubs.push(sub);
  180 + // });
  181 +
  182 + // item.menu = itemSubs;
  183 + // }
  184 + // menu.push(item);
  185 + // });
164 186
165 return { 187 return {
166 menu:menu, 188 menu:menu,
1 -var oldSerDomain = 'http://service.api.yohobuy.com'; 1 +// var oldSerDomain = 'http://service.api.yohobuy.com';
  2 +// module.exports = {
  3 +// login: oldSerDomain + '/account/api/v1/profile/login',
  4 +// getResourceByPid: oldSerDomain + '/account/api/v1/profile/getResourceByPid',
  5 +// getAllResByWebsite: oldSerDomain + '/account/api/v1/resources/getAllResByWebsite'
  6 +// };
  7 +
  8 +var oldSerDomain = 'http://lserve.yohobuy.com';
2 module.exports = { 9 module.exports = {
3 - login: oldSerDomain + '/account/api/v1/profile/login',  
4 - getResourceByPid: oldSerDomain + '/account/api/v1/profile/getResourceByPid',  
5 - getAllResByWebsite: oldSerDomain + '/account/api/v1/resources/getAllResByWebsite'  
6 -};  
  10 + login: oldSerDomain + '/service/account/v1/Profile/login',
  11 + getResourceByPid: oldSerDomain + '/service/account/v1/Profile/getMenuByPid',
  12 + getAllResByWebsite: oldSerDomain + '/service/setting/v1/menu/getAllMenu'
  13 +};
  14 +