1234567891011

liushenping_branch
liushenping 9 months ago
parent 452a115b6a
commit fbb9640df8

@ -167,40 +167,20 @@
{field: 'title', title: '', align: 'center',width:'150'}, {field: 'title', title: '', align: 'center',width:'150'},
{field: 'href', title: '', align: 'center',width:'200'}, {field: 'href', title: '', align: 'center',width:'200'},
{field: 'icon', title: '', align: 'center',width:'90',templet:function (d) { {field: 'icon', title: '', align: 'center',width:'90',templet:function (d) {
return '<font class="layui-icon">'+d.icon+'</font>'; return '<font class="layui-icon">'+d.icon+'</font>';
}}, }},
{field: 'available', title: '', align: 'center',width:'100',templet:function (d) { {field: 'available', title: '', align: 'center',width:'100',templet:function (d) {
return d.available==1?'<font color="blue"></font>':'<font color="red"></font>'; return d.available==1?'<font color="blue"></font>':'<font color="red"></font>';
}}, }},
{field: 'open', title: '', align: 'center',width:'100',templet:function (d) { {field: 'open', title: '', align: 'center',width:'100',templet:function (d) {
return d.open==1?'<font color="blue"></font>':'<font color="red"></font>'; return d.open==1?'<font color="blue"></font>':'<font color="red"></font>';
}}, }},
{field: 'ordernum', title: '', align: 'center',width:'80'}, {field: 'ordernum', title: '', align: 'center',width:'100'},
{field: 'target', title: 'TARGET', align: 'center',width:'80',hide:true}, {fixed: 'right', title: '', toolbar: '#menuRowBar', width: 200}
{fixed: 'right', title: '', toolbar: '#menuRowBar', align: 'center',width:'180'} ] ]
] ],
done: function (data, curr, count) {
//不是第一页时如果当前返回的数据为0那么就返回上一页
if (data.data.length == 0 && curr != 1) {
tableIns.reload({
page: {
curr: curr - 1
}
})
}
/*//当是第一页时如果当前返回的数据为0并且当前为第一页 给一个空的查询条件并给curr赋初值为1
if (data.data.length==0 && curr==1){
tableIns.reload({
where: "",
page:{
curr:1
}
})
}*/
}
}); });
//监控模糊查询按钮事件 //搜索条件:提交表单进行查询
form.on("submit(doSearch)", function (data) { form.on("submit(doSearch)", function (data) {
tableIns.reload({ tableIns.reload({
where: data.field, where: data.field,
@ -211,160 +191,104 @@
return false; return false;
}); });
//监控工具条事件 //弹出新增菜单表单
table.on("toolbar(menuTable)", function (obj) { $(".layui-btn[lay-event='add']").click(function () {
switch (obj.event) { layer.open({
case 'add': type: 1,
openAddLayer(); title: "添加菜单",
break; area: ['600px', 'auto'],
}; content: $("#addOrUpdateDiv")
});
$("#dataFrm")[0].reset();
$("#pid").val(0);
$("#ordernum").val(100);
}); });
//监控行工具条事件 //监听表格工具条事件
table.on("tool(menuTable)", function (obj) { table.on('toolbar(menuTable)', function (obj) {
//获取当前行数据
var data = obj.data;
switch (obj.event) { switch (obj.event) {
case 'delete': case 'add': //新增菜单
deleteMenu(data); layer.open({
break; type: 1,
case 'update': title: "添加菜单",
updateMenu(data); area: ['600px', 'auto'],
break; content: $("#addOrUpdateDiv")
};
});
var mainIndex;
var url;
//打开添加弹出层
function openAddLayer() {
mainIndex = layer.open({
type:1,
content:$("#addOrUpdateDiv"),
area:['800px','450px'],
title:'',
success:function () {
$("#dataFrm")[0].reset();
//设置下拉树中父节点的值为空
$("#pid").val("");
url="/menu/addMenu";
//初始化排序码
$.get("/menu/loadMenuMaxOrderNum",function (res) {
$("#ordernum").val(res.value);
}); });
//设置下拉树的value值为空
selectTree.selectVal("");
}
});
}
//打开修改的弹出层
function updateMenu(data) {
mainIndex = layer.open({
type:1,
content:$("#addOrUpdateDiv"),
area:['800px','450px'],
title:'',
success:function () {
//清空原有的数据
$("#dataFrm")[0].reset(); $("#dataFrm")[0].reset();
//装载新的数据 $("#pid").val(0);
form.val("dataFrm",data); $("#ordernum").val(100);
//选中之前的父级菜单 nodeId=data.pid break;
dtree.dataInit("menuTree",data.pid); }
dtree.selectVal("menuTree"); });
url="/menu/updateMenu";
}
});
}
form.on("submit(doSubmit)",function (data) { //监听行工具事件
$.post(url,data.field,function (res) { table.on('tool(menuTable)', function (obj) {
if (res.code==200){ var data = obj.data;
tableIns.reload(); var layEvent = obj.event;
//重新加载添加弹出层的下拉树 if (layEvent === 'update') { //编辑
selectTree.reload(); $("#dataFrm")[0].reset();
//重新加载左边的菜单树 //打开修改菜单弹出层
window.parent.left.menuTree.reload(); layer.open({
type: 1,
title: "编辑菜单",
area: ['600px', 'auto'],
content: $("#addOrUpdateDiv")
});
//初始化表单数据
$("#dataFrm")[0].reset();
form.val("dataFrm", {
id: data.id,
pid: data.pid,
title: data.title,
href: data.href,
icon: data.icon,
target: data.target,
available: data.available,
open: data.open,
ordernum: data.ordernum
});
dtree.render({
elem: "#menuTree",
url: "/menu/loadMenuTree",
dataStyle: "layui",
click: function (data) {
$("#pid").val(data.id);
}
});
} else if (layEvent === 'delete') { //删除
if (data.children && data.children.length > 0) {
layer.msg("该菜单有子菜单,请先删除子菜单!", {icon: 5});
return;
} }
layer.msg(res.msg); layer.confirm("您确定删除该菜单吗?", {icon: 3, title: ''}, function (index) {
layer.close(mainIndex); $.post("/menu/delete", {id: data.id}, function (res) {
}); if (res.code === 200) {
return false; layer.msg(res.msg, {icon: 1});
tableIns.reload();
} else {
layer.msg(res.msg, {icon: 5});
}
});
layer.close(index);
});
}
}); });
/*$("#doSubmit").click(function () { //监听提交按钮:添加或修改菜单
var data = $("#dataFrm").serialize(); form.on("submit(doSubmit)", function (data) {
$.post(url,data,function (res) { $.post("/menu/saveOrUpdate", data.field, function (res) {
if (res.code==200){ if (res.code === 200) {
layer.msg(res.msg, {icon: 1});
layer.closeAll();
tableIns.reload(); tableIns.reload();
//重新加载添加弹出层的下拉树 } else {
selectTree.reload(); layer.msg(res.msg, {icon: 5});
//重新加载左边的菜单树
window.parent.left.menuTree.reload();
}
layer.msg(res.msg);
layer.close(mainIndex);
});
});*/
//删除
function deleteMenu(data) {
$.post("/menu/checkMenuHasChildrenNode", {id: data.id}, function (resoult) {
if (resoult.value){
layer.msg("当前菜单节点有子菜单,请选择删除子菜单!")
}else {
layer.confirm('' + data.title + '', {icon: 3, title: ''}, function (index) {
$.post("/menu/deleteMenu", {id: data.id},function (res) {
if (res.code == 200) {
tableIns.reload({
where:"",
});
//刷新下拉树
selectTree.reload();
//刷新左边的菜单树
window.parent.left.menuTree.reload();
}
layer.msg(res.msg);
});
layer.close(index);
});
} }
}); });
} return false;
//初始化下拉树
var selectTree = dtree.renderSelect({
elem: "#menuTree",
width: "100%", // 可以在这里指定树的宽度来填满div
dataStyle: "layuiStyle", //使用layui风格的数据格式
dataFormat: "list", //配置data的风格为list
response:{message:"msg",statusCode:0}, //修改response中返回数据的定义
url: "/menu/loadMenuManagerLeftTreeJson" // 使用url加载可与data加载同时存在
}); });
//监听点击的方法
dtree.on("node(menuTree)",function (obj) {
$("#pid").val(obj.param.nodeId);
console.log(obj.param.nodeId);
})
}); });
//给其它页面刷新当前页面数据表格的方法
function reloadTable(id) {
tableIns.reload({
where:{
id:id
},
page:{
curr:1
}
});
}
</script> </script>
</body> </body>

Loading…
Cancel
Save