1.菜单列表功能模块效果图如下
菜单列表模块jsp代码
<%@ page language="java" contentType="text/html;charset=utf-8" pageEncoding="utf-8"%>
<!DOCTYPE HTML>
<html>
<%@ include file="/resource/include/meta.jsp"%>
<head>
<title>菜单列表</title>
<!-- 树形Grid -->
<script type="text/javascript" src="${ctx}/resource/common/ext3/ux/maximgb/TreeGrid.js"></script>
<script type="text/javascript" src="${ctx}/resource/common/js/sysManage/sysMenuTreeTable.js"></script>
</head>
<body>
</body>
</html>
菜单列表模块js代码
/********************************************Ext入口函数,相当于java中的主函数开始********************************************/
Ext.onReady(function() {
Ext.QuickTips.init();
var menuStateStore = new Ext.data.ArrayStore({
autoLoad :true, //页面加载时自动load数据
fields : ['key', 'value'],
data : [['有效','1'],['无效', '0']]
});
/***************************************** 新增editForm开始 **************************************************/
var editForm = new Ext.form.FormPanel({
formId:'editForm',
frame:true,
border:false,
labelAlign:'center',
standardSubmit:false,
layout : 'form',//*form布局
items : [{
layout:'column',
items : [{
columnWidth : .5, //列宽为25%
layout : 'form', //*form布局
items: [{
columnWidth : .5, //列宽为25%
layout : 'form', //*form布局
items: [{
fieldLabel : '<font color="red">*</font>菜单名称',
name : 'menuName',
xtype : 'textfield', // 设置为数字输入框类型
labelStyle : 'text-align:right;',//右对齐
emptyText:'请您输入菜单名称', //水印提示
allowBlank:false, //allowBlank : false就是已经定义好的校验规则,extjs getForm().isValid()函数会调用已经定义的校验规则来验证输入框中的值
anchor : '90%'
}]
},{
columnWidth : .5, //列宽为25%
layout : 'form', //*form布局
items : [{ //下拉框
xtype : 'combo',
fieldLabel : '<font color="red">*</font>菜单状态',
name : 'menuState',
store : menuStateStore, //*加载客户类型Store
//下列属性在复用时一般不作修改
editable : false, //false为不可编辑,页面效果为点击下拉框空白处直接触发下拉菜单
labelStyle : 'text-align:right;',//fieldLabel右对齐
triggerAction : 'all', //*触发器被激活时执行allQuery查询
displayField : 'key', //*下列列表选项的中文名,对应Store中的value
valueField : 'value', //*下列列表选项对应的key值,对应Store中的key
mode : 'local', //*读取本地数据
emptyText:'请您选择', //*水印提示
resizable : false, //*下拉框下部的缩放柄,可改变下拉框大小
allowBlank:false, //allowBlank : false就是已经定义好的校验规则,extjs getForm().isValid()函数会调用已经定义的校验规则来验证输入框中的值
anchor : '90%'
}]
}]
},{
columnWidth : .5, //列宽为25%
layout : 'form', //*form布局
items: [{
fieldLabel : '<font color="red">*</font>菜单URL',
id:'menuUrl',
name : 'menuUrl',
xtype : 'textfield', // 设置为数字输入框类型
labelStyle : 'text-align:right;',//右对齐
emptyText:'请您输入菜单URL', //水印提示
anchor : '90%'
}]
},{
columnWidth : .5, //列宽为25%
layout : 'form', //*form布局
items: [{
fieldLabel : '<font color="red">*</font>菜单排序',
id:'menuSort',
name : 'menuSort',
xtype : 'textfield', // 设置为数字输入框类型
labelStyle : 'text-align:right;',//右对齐
emptyText:'请您输入菜单排序', //水印提示
allowBlank:false, //allowBlank : false就是已经定义好的校验规则,extjs getForm().isValid()函数会调用已经定义的校验规则来验证输入框中的值
anchor : '90%'
}]
}]
},{
columnWidth : 1, //列宽为25%
layout : 'form', //*form布局
items: [{
xtype : 'htmleditor',
height : 140,
width : 700,
fontFamilies : ['宋体','黑体','隶书','微软雅黑','Arial','Courier New','Tahoma','Times New Roman','Verdana'],
defaultFont: '宋体',
defaultLinkValue:"http://www.",
enableAlignments:true,
enableColors:true,
enableFont:true,
enableFontSize:true,
enableFormat:true,
enableLinks:true,
enableSourceEdit:true,
fieldLabel:'菜单描述',
labelStyle:'text-align:right;',
name:'menuDesc',
anchor:'95%'
}]
},{
id:'menuId',
name : 'menuId',
xtype : 'hidden'
},{
id:'menuPid',
name : 'menuPid',
xtype : 'hidden'
},{
id:'createTime',
name : 'createDate',
xtype : 'hidden'
}]
});
/***************************************** 新增editForm结束 **************************************************/
/***************************************** 新增和修改editWindow窗口开始 **************************************************/
var editWindow=new Ext.Window({
id:'editWindow',
width : 880,
height :350,
closable : true,
resizable : false,
collapsible : false,
draggable : true,
closeAction : 'hide',
title : '新增系统菜单',
modal : true,
animCollapse : false,
border : false,
closable : true,
animateTarget : Ext.getBody(),
constrain : true,
items : [editForm],
buttonAlign:'center',
buttons:[{
text:'保存',
handler:function(){
if(!editForm.getForm().isValid()){
Ext.MessageBox.alert('系统提示', '请您正确输入各项信息!');
return false;
}
var pars = editForm.getForm().getFieldValues();
var menuSort=pars.menuSort;
var reg=/^\+?[1-9][0-9]*$/;//baseNum dimName dimCd
if(!reg.test(menuSort)){
Ext.MessageBox.alert('系统提示', '菜单排序必须是数字!');
return false;
}
//提交表单的方法
editForm.getForm().submit({
url : basepath + '/sysMenu/sysMenuInfoSave',
method : 'POST',
waitTilte : '系统提示',
waitMsg : '正在提交数据,请稍后!',
success:function(response){
Ext.Msg.alert('系统提示', '保存成功!',function(btn){
if(btn == 'ok'){
}
});
},
failure : function(form, action){
Ext.MessageBox.alert('系统提示', '保存失败!');
},
});
editWindow.hide();
}
},{
text: '关闭',
handler:function(){
editWindow.hide();
}
}]
});
/***************************************** 新增和修改editWindow窗口结束 **************************************************/
/*******************************************列表菜单树开始***************************************************/
//定义树的加载器
var treeloader = new Ext.ux.tree.TreeGridLoader({
dataUrl : basepath + '/sysMenu/getAuthSysMenuInfoJson',
});
//定义treegrid
var treeGrid = new Ext.ux.tree.TreeGrid({
title : '菜单列表树', //表头名称,去掉则不显示表头
width: '100%',
border : false,
animate : true,
enableDD : true, //节点是否可移动
enableSort:false, //默认为true,控件根据列的内容排序;置为false,则按照数据顺序显示
autoScroll : true,
columnLines: true,// 斑马线 ,
rootVisible : false,
height : document.body.scrollHeight-20,
tbar : [{
text : '新增',
iconCls : 'addIconCss', //定义图标
handler : function(){ //调用新增方法
editWindow.setTitle("新增系统菜单");
editForm.getForm().reset();
editWindow.restore();
editWindow.show();
}
}, '-', {
text : '修改',
iconCls : 'editIconCss',
handler : function() {
var node = treeGrid.selModel.selNode;
if(null!=node){
editWindow.setTitle("修改系统菜单");
var dataMap = {};
var data = {};
data['menuId'] = node.attributes.id;
data['menuName'] = node.attributes.text;
data['menuPid'] = node.attributes.menuPid;
data['menuIcon'] = node.attributes.menuIcon;
data['menuUrl'] = node.attributes.menuUrl;
data['menuState'] = node.attributes.menuState;
data['menuSort'] = node.attributes.menuSort;
data['menuDesc'] = node.attributes.menuDesc;
dataMap['data']=data;
editForm.getForm().loadRecord(dataMap);
editWindow.restore();
editWindow.show();
}else{
Ext.Msg.alert("系统提示", "请您先选择一条要修改的记录!");
}
}
}, '-', {
text : '删除',
iconCls : 'deleteIconCss',
handler : function() {
var node = treeGrid.selModel.selNode;
if(null==node){
Ext.Msg.alert("系统提示", "请您先选择一条要删除的记录!");
return ;
}else{
if(node.attributes.leaf&&node.attributes.children.length==0){
Ext.MessageBox.confirm("系统提示","您确定要删除吗?",
function(button,text){
if( button == 'yes'){
Ext.Ajax.request({
url : basepath + '/sysMenu/sysMenuInfoDelete?idStr=' + node.attributes.id,
waitTilte : '系统提示',
waitMsg : '正在删除数据,请您等待...', // 显示读盘的动画效果,执行完成后效果消失
success : function(response) {
Ext.Msg.alert("系统提示", response.responseText);
},
failure : function() {
Ext.MessageBox.alert('系统提示', '操作失败!');
}
});
}
}
);
}else{
Ext.MessageBox.alert('系统提示', '该菜单下有子菜单无法删除!');
}
}
}
}, '-', {
text : '详情',
iconCls : 'detailIconCss',
handler : function() {
if(treeGrid.selModel.hasSelection()){
// 得到被选择的行
var _record = treeGrid.getSelectionModel();
if (_record.selections.length>1) {
Ext.MessageBox.alert('系统提示', '请您选择其中一条记录进行查看!');
return false;
} else {
detailForm.getForm().loadRecord(_record.getSelected());
detailWindow.restore();
detailWindow.show();
}
}else{
Ext.Msg.alert("系统提示", "请您先选择一条要查看的记录!");
}
}
},{
xtype : 'textfield',
id:'menuName',
name : 'menuName',
emptyText : '请您输入要查询的菜单名称',
anchor : '90%'
},{
text : '搜索',
iconCls : 'searchIconCss',
handler : function(){
debugger;
var menuName = Ext.getCmp("menuName").getValue();
treeGrid.loader.dataUrl = basepath + '/sysMenu/getAuthSysMenuInfoJson?menuName='+menuName;
treeGrid.loader.treeloader();
/*Ext.Ajax.request({
url : basepath + '/sysMenu/getAuthSysMenuInfoJson',
mothed: 'GET',
params :{
"menuName":menuName
},
success:function(response){
// treeGrid('loadData', response.responseText);
treeGrid('loadData', response.responseText);//加载数据更新treegrid
}
});*/
}
},{
text : '重置',
iconCls : 'resetIconCss',
handler : function(){
Ext.getCmp("menuName").setValue('');
dataStore.load({
params : {
start : 0,
limit : parseInt(pagesize_combo.getValue())
}
});
}
}
],
columns : [ { header : '菜单名称', dataIndex : 'text', width : 150,align : 'left',sortable:true
},{ header : '菜单URL',dataIndex : 'menuUrl', width : 250,align : 'left'
},{ header : '菜单图标', dataIndex : 'menuIcon',width : 80,align : 'left'
},{ header : '菜单状态', dataIndex : 'menuState',width : 80,align : 'left',
renderer : function(value){
if(value=="1"){
return "<span style='color:green;'>有效</span>";
}else if( value=="0"){
return "<span style='color:red;'>无效</span>";
}
}
},{ header : '菜单排序', dataIndex : 'menuSort',width : 80,align : 'left',sortable : true
},{ header : '创建时间', dataIndex : 'createTime',width : 120,align : 'left',sortable : true
},{ header : '更新时间', dataIndex : 'updateTime',width : 120,align : 'left',sortable : true
},{ header : '菜单描述', dataIndex : 'menuDesc',width : 200
}],
loadMask:{
msg : '正在加载数据,请稍等...'
},
loader : treeloader //绑定加载器
});
treeGrid.expandAll();
var treeContainer = new Ext.Panel( {
border : false,
region : 'center',
layout : 'fit',
items : [ treeGrid ]
});
/*******************************************列表菜单树结束***************************************************/
/***************************************** 布局模型开始 **************************************************/
var viewport = new Ext.Viewport({
layout:'fit',
items:[{
layout : 'border',
items: [treeContainer]
}]
});
/***************************************** 布局模型结束 **************************************************/
});
/********************************************Ext入口函数,相当于java中的主函数结束********************************************/