怀揣着激动的心情,第一次发表博客,希望在这里记录我的一些经历,同时也希望能够帮到一些人,更希望高人路过指点迷津!
这是我在刚毕业的那年开发的一个项目,当时组长给我分的这个活感觉分分钟就会搞定,没想到前前后后整了将近两个礼拜,现在回想起来还是有点唏嘘,还是当时对需求的理解不够深导致。废话不多说了,上代码:
listeners : {
render : function(){
var index = moduleStore.find('mod_id',gridSelModeDel[0].get('mod_id'));
if(index!=-1){
return moduleStore.getAt(index).get("mod_name");
}
return gridSelModeDel[0];
},
focus: function(tfd){
tfd.blur();
},
beforerender : function(){
var loadMarsk = new Ext.LoadMask(document.body,{
msg : '正在加载数据,请稍后...',
removeMask :true// 完成后移除
});
//loadMarsk.show();//显示遮罩
//动态添加fieldset(父节点)
Ext.Ajax.request({
url: requestPath+'/moduleCombobox/queryModuleListByParentId.do',
params:{"parent_id":gridSelModeDel[0].get("mod_id")},
method:'post',
success:function(response,action)
{
var adata=Ext.decode(response.responseText);
for(var a=0;a
//这里开始添加子节点,包括一级菜单,二级菜单及按钮
Ext.Ajax.request({
url:requestPath+'/menu/queryRightMenu.do',
params:{mod_id:aModId,role_id:gridSelModeDel[0].get("role_id")},
method:'post',
success:function(response,action)
{
//js闭包,ajax异步加载时记录数据状态,这个代码会在下面给出
var module1 = innerCallback1();
var data=Ext.decode(response.responseText);
var ri=data.right_id;
var ria=data.right_id_all;
var button_data = data.button_Right_idall;
var my_button_data = data.button_Right_id;
var item_d = [];
for(var z=0;z提示','发生异常,请重新操作!');
return;
}
});
//Ext.getCmp(aModId).expand();
me.expand();
var innerCallback3 = callback3(aModId);
Ext.Ajax.request({
//async:false,//解决ajax请求与后台不同步的问题
url: requestPath+'/moduleCombobox/queryModuleListByParentIdFirst.do',
params:{mod_id:aModId,role_id:gridSelModeDel[0].get("role_id")},
method:'post',
success:function(response,action)
{
var module3 = innerCallback3();
var fmData=Ext.decode(response.responseText);
for(var b=0;b提示','发生异常,请重新操作!');
return;
}
});
Ext.getCmp(fmModId).expand();
//me1.expand();
}}
}));
}
},
failure:function(form,action)
{
Ext.Msg.alert('提示','发生异常,请重新操作!');
return;
}
});
//loadMarsk.hide();//取消遮罩
}}
}));
}
},
failure:function(form,action)
{
Ext.Msg.alert('提示','发生异常,请重新操作!');
return;
}
});
}
}
//打完收工
//js闭包
function callback(moduleId){
var module =moduleId;
function innerCallback(){
return module;
}
return innerCallback;
}
/**
* 按条件查询菜单,这里是后台代码,从上面的js代码可以看出,其实后台的操作都是简单的条件查询,下面这两段代码实现的相同的东西,只是 * 效率问题,前一段是我最初的设计,后一段是改进后的
*/
public void queryRightMenu(){
final HashMap paramsMap = super.getParamsMap();
Map map=new HashMap();
List listContainValue=new ArrayList();
List listRoleToRightValueId=rightMenuService.queryRoleToRight(paramsMap);
List listRightMenu=rightMenuService.queryRightMenu(paramsMap);
HashMap button_tempMap = new HashMap();
HashMap button_tempMap_a = new HashMap();
for (RightMenu rightMenu : listRoleToRightValueId) {
//查找某个对象在不在列表之中
if(!listRightMenu.contains(rightMenu)){
listContainValue.add(rightMenu);
}
}
map.put("right_id",listRoleToRightValueId);
map.put("right_id_all", listRightMenu);
for(int nIndex=0;nIndex buttonMap = new HashMap();
buttonMap.put("parent_id", listRightMenu.get(nIndex).getRight_id());
List listRightMenuUnButton=rightMenuService.queryRightMenuUnButton(buttonMap);
List listRightToRoleUnButton=rightMenuService.queryRightToRoleUnButton(buttonMap);
button_tempMap.put(listRightMenu.get(nIndex).getRight_id(), listRightMenuUnButton);
button_tempMap_a.put(listRightMenu.get(nIndex).getRight_id(), listRightToRoleUnButton);
}
map.put("button_Right_id",button_tempMap_a);
map.put("button_Right_idall", button_tempMap);
logger.info("菜单的值为:"+JSON.toJSONString(map));
super.outJson(map);
}
public void queryRightMenuAndBtnAtIE(){
final HashMap paramsMap = super.getParamsMap();
List listRoleToRightValueId=rightMenuService.queryRoleToRight(paramsMap);
List listRightMenu=rightMenuService.queryRightMenu(paramsMap);
Map map=new HashMap();
final HashMap mapBtn=new HashMap();
for (RightMenu rightMenu1 : listRightMenu) {
Integer roleId=rightMenu1.getRole_id();
Integer rightId=rightMenu1.getRight_id();
logger.info(JSON.toJSONString("菜单id:"+rightId));
mapBtn.put("role_id", roleId);
mapBtn.put("right_id", rightId);
List listRightMenuUnButton=rightMenuService.queryRightMenuUnButton(mapBtn);
List listRightToRoleUnButton=rightMenuService.queryRightToRoleUnButton(mapBtn);
map.put("right_ids",listRightToRoleUnButton);
map.put("right_id_alls", listRightMenuUnButton);
logger.info(JSON.toJSONString("IE中一个菜单下所有按钮的值:"+listRightToRoleUnButton));
logger.info(JSON.toJSONString("IE中一个菜单下并且所有已存在的按钮的值:"+listRightMenuUnButton));
}
map.put("right_id",listRoleToRightValueId);
map.put("right_id_all", listRightMenu);
logger.info(JSON.toJSONString("IE中一个模块下所有菜单也就是权限的值:"+listRightMenu));
logger.info(JSON.toJSONString("IE中一个模块和对应的角色下所有存在的菜单也就是存在的权限的值:"+listRoleToRightValueId ));
super.outJson(map);
}
好了,就是这些.第一次发博文有点紧张,希望可以互相学习.