<!DOCTYPE html>
|
<html>
|
<head>
|
<meta charset="utf-8">
|
<title>菜单信息列表</title>
|
<meta name="renderer" content="webkit">
|
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
|
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
|
<link rel="stylesheet" href="../../layuiadmin/layui/css/layui.css" media="all">
|
<link rel="stylesheet" href="../../layuiadmin/style/admin.css" media="all">
|
<script>
|
// 这里是需要在页面渲染之前执行的代码
|
document.addEventListener("DOMContentLoaded", function() {
|
|
//获取table默认显示数
|
pageCntFirst();
|
});
|
</script>
|
</head>
|
<body id="body">
|
<div class="layui-card" style="margin-bottom: 0px;">
|
<div class="layui-form layui-card-header layuiadmin-card-header-auto" style="border-bottom:1px solid #CCC" id="top">
|
<div class="layui-form-item" >
|
<div class="layui-inline">
|
<label class="layui-form-label">菜单名称</label>
|
<div class="layui-input-inline">
|
<input type="text" id="MenuName" name="MenuName" placeholder="请输入菜单名称" autocomplete="off" class="layui-input">
|
</div>
|
</div>
|
<div class="layui-inline">
|
<label class="layui-form-label">模块菜单</label>
|
<div class="layui-input-block">
|
<select name="MenuNo" id="MenuNo" lay-filter="lay-filter-selectMenuNo" >
|
<option value=""></option>
|
</select>
|
</div>
|
</div>
|
<div class="layui-inline">
|
<label class="layui-form-label">页面菜单</label>
|
<div class="layui-input-block">
|
<select name="MenuNoo" id="MenuNoo" lay-search>
|
<option value=""></option>
|
</select>
|
</div>
|
</div>
|
<div class="layui-inline">
|
<label class="layui-form-label" style="width: 60px;">模块类型</label>
|
<div class="layui-input-inline">
|
<select name="Level" id="Level" lay-verify="" lay-search >
|
<option value=""></option>
|
<option value="0">模块</option>
|
<option value="1">页面</option>
|
<option value="2">按钮</option>
|
</select>
|
</div>
|
</div>
|
<div class="layui-inline">
|
<button class="layui-btn layui-btn-sm layuiadmin-btn-list" lay-submit lay-filter="LAY-app-contlist-search">
|
<i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>搜索
|
</button>
|
</div>
|
<div class="layui-inline">
|
<button class="layui-btn layui-btn-sm layuiadmin-btn-list" data-type="add" id="approvalBtn">
|
<i class="layui-icon layuiadmin-button-btn"></i>添加
|
</button>
|
</div>
|
</div>
|
</div>
|
|
<div id="center"></div>
|
|
<div class="layui-card-body">
|
<!-- <div style="padding-bottom: 5px;display: flex; flex-direction: row-reverse;">
|
<button class="layui-btn layui-btn-sm layuiadmin-btn-list layui-hide layui-btn-danger" data-type="hide">
|
<i class="layui-icon"></i>隐藏按钮
|
</button>
|
</div> -->
|
<table id="LAY-app-content-list" lay-filter="LAY-app-content-list"></table>
|
<script type="text/html" id="Leveltype">
|
{{# if(d.Level=='0'){ }}
|
<button class="layui-btn layui-btn-radius layui-btn-xs" style="background-color:#000080;">模块</button>
|
{{# } else if(d.Level=='1') { }}
|
<button class="layui-btn layui-btn-radius layui-btn-danger layui-btn-xs" style="background-color:#1E90FF;">页面</button>
|
{{# } else if(d.Level=='2') { }}
|
<button class="layui-btn layui-btn-radius layui-btn-danger layui-btn-xs" style="background-color: #7B68EE;">按钮</button>
|
{{# } }}
|
</script>
|
|
<script type="text/html" id="createTime">
|
{{# if(d.CreateTime == undefined){ }}
|
<p>{{""}}</p>
|
{{# } else { }}
|
<p>{{ formatDate(d.CreateTime) }}</p>
|
{{# } }}
|
</script>
|
<script type="text/html" id="table-content-list">
|
<button class="layui-btn layui-btn-normal layui-btn-xs approvalBtnupt" id="approvalBtnupt" lay-event="edit">
|
<i class="layui-icon layui-icon-edit"></i>编辑
|
</button>
|
<button class="layui-btn layui-btn-danger layui-btn-xs approvalBtndel" id="approvalBtndel" lay-event="del">
|
<i class="layui-icon layui-icon-delete"></i>删除
|
</button>
|
</script>
|
</div>
|
</div>
|
<script src="../../layuiadmin/layui/layui.js"></script>
|
<script src="../../js/public.js"></script>
|
<script src="../../js/jquery-3.5.1.min.js"></script>
|
<script src="../../js/jquery.cookie.js"></script>
|
<script>
|
var uid = $.cookie('userId');
|
if (uid == null) {
|
alert('请登录后操作');
|
window.parent.location.href = '../Login.html'
|
}
|
layui.config({
|
base: '../../layuiadmin/' //静态资源所在路径
|
}).extend({
|
index: 'lib/index' //主入口模块
|
}).use(['index', 'table', 'laypage', 'layer'], function() {
|
var table = layui.table,
|
form = layui.form,
|
laypage = layui.laypage,
|
layer = layui.layer;
|
var h1 = GetTableHeight();
|
refreshTable("","","","","");
|
var tableIns;
|
|
//监听下拉框
|
form.on('select(lay-filter-selectMenuNo)', function(data){
|
//根据父级菜单号获取子级菜单
|
sendData(IP + "/Sys/GetMenuByParentNo?MenuNo="+data.value, {}, 'get', function(res) {
|
if (res.code == 0) //成功
|
{
|
var menunoohtml = '';
|
var num = $('#MenuNoo')[0].length;
|
if(num > 1)
|
{
|
for (var a = 1; a < num; a=1)
|
{
|
num = $('#MenuNoo')[0].length;
|
if (num == 1)
|
{
|
break;
|
}
|
else
|
{
|
$('#MenuNoo')[0][a] = null;
|
continue;
|
}
|
}
|
}
|
if(num == 1)
|
{
|
for (var i = 0; i < res.data.length; i++)
|
{
|
//判断层级不是按钮
|
if (res.data[i].Level != '2')
|
{
|
menunoohtml += '<option value =' + res.data[i].MenuNo + '>'+ res.data[i].MenuName +'</option>';
|
}
|
}
|
//页面菜单
|
$("#MenuNoo").append(menunoohtml);
|
form.render('select');
|
}
|
}
|
else { //不成功
|
layer.msg('获取环境信息失败', {
|
icon: 2,
|
time: 2000 //2秒关闭(如果不配置,默认是3秒)
|
}, function() {
|
//回调
|
form.render('select');
|
});
|
}
|
});
|
});
|
|
//获取菜单信息
|
function refreshTable(MenuNo,MenuName,MenuNoo,Level) {
|
var param = {
|
MenuNo: MenuNo,
|
MenuName: MenuName,
|
MenuNoo: MenuNoo,
|
Level: Level
|
};
|
var url = "/Sys/GetMenuList?MenuName="+param.MenuName+"&PMenuNo="+param.MenuNo+"&MenuNo="+param.MenuNoo+"&Level="+param.Level;
|
sendData(IP + url, {}, 'post', function(res) {
|
if (res.code == 0) { //成功
|
var list = res.data;
|
$.extend(infoOptions, {
|
data: list
|
});
|
infoOptions.page = {
|
curr: 1
|
}
|
tableIns = table.render(infoOptions);
|
sendData(IP + "/Basis/GetRoleRightList", param, 'get', function(res) {
|
menuList = res.data;
|
$(function() {
|
$("#approvalBtn").hide();
|
$(".approvalBtnupt").hide();
|
$(".approvalBtndel").hide();
|
});
|
if (res.code == 0) { //成功
|
var list = res.data.filter(item => item.Layer == 0);
|
if (list) {
|
for (var i = 0; i < list.length; i++) {
|
xml = xml + '<li class="layui-nav-item">' + '<a href="javascript:;" lay-tips=' + list[i].Icon + ' lay-direction="2">' + '<span class="iconfont ' + list[i].Icon + '"></span>' + '<cite>' + list[i].MenuName + '</cite>' + '</a>';
|
var id = list[i].Id;
|
//查询有无子菜单
|
var count = res.data.filter(item => item.ParentId == id).length;
|
if (count > 0) {
|
xml = xml + '<dl class="layui-nav-child">';
|
getchiled(res.data, id);
|
xml = xml + '</dl>';
|
}
|
xml = xml + '</li>'
|
}
|
}
|
|
for (var k = 0; k < res.data.length; k++) {
|
if (res.data[k].MenuName == "添加菜单") {
|
$(function() {
|
$("#approvalBtn").show();
|
});
|
}
|
if (res.data[k].MenuName == "编辑菜单") {
|
$(function() {
|
$(".approvalBtnupt").show();
|
});
|
}
|
if (res.data[k].MenuName == "删除菜单") {
|
$(function() {
|
$(".approvalBtndel").show();
|
});
|
}
|
}
|
}
|
else
|
{ //不成功
|
layer.msg('获取信息失败', {
|
icon: 2,
|
time: 2000 //2秒关闭(如果不配置,默认是3秒)
|
}, function() {
|
//回调
|
});
|
}
|
});
|
}
|
else { //不成功
|
layer.msg('获取菜单列表信息失败!', {
|
icon: 2,
|
time: 2000 //2秒关闭(如果不配置,默认是3秒)
|
}, function() {});
|
}
|
});
|
|
}
|
var element = layui.element;
|
var houseId = 0;
|
var param = {
|
Id: $.cookie('userId')
|
}
|
var xml = '';
|
|
function getchiled(data, mainId) {
|
if (data) {
|
var list = data.filter(item => item.ParentId == mainId);
|
if (list) {
|
for (var i = 0; i < list.length; i++) {
|
var id = list[i].Id;
|
//查询有无子菜单
|
var count = data.filter(item => item.ParentId == id).length;
|
if (count > 0) {
|
xml = xml + '<dd>' + '<a href="javascript:;">' + list[i].MenuName + '</a>' + '<dl class="layui-nav-child">';
|
getchiled(data, id);
|
xml = xml + '</dl></dd>';
|
}
|
else
|
{
|
xml = xml + '<dd>' + '<a lay-href="' + list[i].Url + '">' + list[i].MenuName + '</a>' + '</dd>';
|
}
|
}
|
}
|
}
|
}
|
var menuList;
|
|
|
// 表单需要的变量
|
var infoOptions = {
|
elem: '#LAY-app-content-list',
|
height: h1,
|
id: 'LAY-app-content-list',
|
page: true,
|
limit: pageCnt,
|
limits: pageLimits,
|
even: true,
|
cellMinWidth: 80, //全局定义常规单元格的最小宽度,layui 2.2.1 新增
|
cols:
|
[[
|
{
|
title: '序号', type: 'numbers', width:65
|
},
|
{
|
field: 'MenuNo', title: '菜单编号', align: 'center',
|
}, {
|
field: 'MenuName', title: '菜单名称', align: 'center',
|
},
|
{
|
field: 'ParentName', title: '父级菜单', align: 'center',
|
},
|
{
|
field: 'Ord', title: '显示顺序', align: 'center',
|
},
|
{
|
field: 'Url', title: '路径', align: 'center',
|
},
|
{
|
field: 'Level', templet: '#Leveltype', title: '模块类型', align: 'center',
|
},
|
{
|
field: 'CreateUserName', title: '创建人', align: 'center',
|
},
|
{
|
field: 'CreateTime', title: '创建时间', align: 'center',
|
templet: function (d) {
|
return formatDate(d.CreateTime);
|
},
|
},
|
{
|
title: '操作', fixed: 'right', align: 'center', toolbar: '#table-content-list'
|
}
|
]]
|
};
|
//监听搜索
|
//监听搜索
|
form.on('submit(LAY-app-contlist-search)', function(data) {
|
console.log(data.field)
|
var MenuNo = data.field.MenuNo;
|
var MenuName = data.field.MenuName;
|
var MenuNoo = data.field.MenuNoo;
|
var Level = data.field.Level;
|
refreshTable(MenuNo,MenuName,MenuNoo,Level);
|
});
|
|
var doing = true;
|
// ------------------------------------新增---------------------------------------------------
|
// var $ = layui.$,
|
active = {
|
add: function() {
|
layer.open({
|
type: 2,
|
title: '添加菜单信息',
|
content: 'MenumanageFrom.html',
|
maxmin: true,
|
area: ['520px', '508px'],
|
btn: ['确定', '取消'],
|
yes: function(index, layero) {
|
var iframeWindow = window['layui-layer-iframe' + index],
|
submitID = 'layuiadmin-app-form-submit',
|
submit = layero.find('iframe').contents().find('#' + submitID);
|
//监听提交
|
iframeWindow.layui.form.on('submit(' + submitID + ')', function(
|
data) {
|
var field = data.field; //获取提交的字段
|
//提交 Ajax 成功后,静态更新表格中的数据
|
var param = {
|
ParentNo: field.ParentNo, //父级菜单号
|
MenuNo: field.MenuNo, //菜单号
|
MenuName: field.MenuName, //菜单名称
|
Ord: field.Ord, //显示顺序
|
Url: field.Url, //路径
|
Level: field.Level, //层级
|
Demo: field.Demo, //备注
|
};
|
if(doing){
|
doing = false;
|
sendData(IP + "/Sys/AddMenu", param, 'post',
|
function(res) {
|
if (res.code == 0) { //成功
|
layer.msg(res.msg, {
|
icon: 1,
|
time: 2000 //2秒关闭(如果不配置,默认是3秒)
|
}, function() {
|
ParentSelect($("#MenuNo").val());
|
refreshTable($("#MenuNo").val(), $("#MenuName").val(), $("#MenuNoo").val(), $("#Level").val());
|
layer.close(index); //关闭弹层
|
doing = true;
|
});
|
} else { //不成功
|
layer.msg(res.msg, {
|
icon: 2,
|
time: 2000 //2秒关闭(如果不配置,默认是3秒)
|
}, function() {
|
doing = true;
|
});
|
}
|
});
|
}
|
else
|
{
|
console.log(123);
|
}
|
});
|
submit.trigger('click');
|
}
|
});
|
}
|
};
|
$('.layui-btn.layuiadmin-btn-list').on('click', function() {
|
var type = $(this).data('type');
|
active[type] ? active[type].call(this) : '';
|
});
|
|
// ------------------------------------删除、编辑---------------------------------------------------
|
table.on('tool(LAY-app-content-list)', function(obj) {
|
var data = obj.data;
|
//编辑
|
if (obj.event === 'edit') {
|
Id = data.Id;
|
console.log(data)
|
layer.open({
|
type: 2,
|
title: '编辑菜单信息',
|
content: 'MenumanageFrom.html?Id=' + Id,
|
maxmin: true,
|
area: ['450px', '456px'],
|
btn: ['确定', '取消'],
|
yes: function(index, layero) {
|
var iframeWindow = window['layui-layer-iframe' + index],
|
submitID = 'layuiadmin-app-form-edit',
|
submit = layero.find('iframe').contents().find('#' + submitID);
|
//监听提交
|
iframeWindow.layui.form.on('submit(' + submitID + ')', function(data) {
|
var field = data.field; //获取提交的字段
|
//提交 Ajax 成功后,静态更新表格中的数据
|
var param = {
|
Id : Id, //Id
|
ParentNo: field.ParentNo, //父级菜单号
|
MenuNo: field.MenuNo, //菜单号
|
MenuName: field.MenuName, //菜单名称
|
Ord: field.Ord, //显示顺序
|
Url: field.Url, //路径
|
Level: field.Level, //层级
|
Demo: field.Demo, //备注
|
};
|
console.log(param)
|
if(doing){
|
doing = false;
|
sendData(IP + "/Sys/UpdateMenu", param, 'post', function(res) {
|
if (res.code == 0) { //成功
|
layer.msg("修改成功", {
|
icon: 1,
|
time: 1000 //2秒关闭(如果不配置,默认是3秒)
|
}, function() {
|
ParentSelect($("#MenuNo").val());
|
//$("#MenuNo").val($("#MenuNo").val());
|
console.log($("#MenuNo").val())
|
|
refreshTable($("#MenuNo").val(), $("#MenuName").val(), $("#MenuNoo").val(), $("#Level").val());
|
layer.close(index); //关闭弹层
|
doing = true;
|
});
|
}
|
else
|
{ //不成功
|
layer.msg(res.msg, {
|
icon: 2,
|
time: 2000 //2秒关闭(如果不配置,默认是3秒)
|
}, function() {
|
doing = true;
|
});
|
}
|
});
|
}
|
else
|
{
|
console.log(123);
|
}
|
});
|
submit.trigger('click');
|
}
|
});
|
}
|
//删除
|
else if (obj.event === 'del') {
|
layer.confirm('确定删除选中的菜单列表?', function(index) {
|
if(doing){
|
doing = false;
|
sendData(IP + "/Sys/DelMenu?Id=" + data.Id + "", {} , 'get', function(res) {
|
if (res.code == 0) { //成功
|
layer.msg(res.msg, {
|
icon: 1,
|
time: 1000 //2秒关闭(如果不配置,默认是3秒)
|
}, function() {
|
ParentSelect($("#MenuNo").val());
|
refreshTable($("#MenuNo").val(), $("#MenuName").val(), $("#MenuNoo").val(), $("#Level").val());
|
doing = true;
|
});
|
}
|
else
|
{ //不成功
|
layer.msg(res.msg, {
|
icon: 2,
|
time: 2000 //2秒关闭(如果不配置,默认是3秒)
|
}, function() {
|
doing = true;
|
});
|
}
|
});
|
}
|
else{
|
console.log(123);
|
}
|
});
|
}
|
});
|
//父级菜单下拉框
|
var param = {
|
id: $.cookie('userId'),
|
};
|
function ParentSelect(MenuNo)
|
{
|
//环境下拉框
|
sendData(IP + "/Sys/GetParentMenuList", param, 'post', function(res) {
|
if (res.code == 0) { //成功
|
$("#MenuNo").empty();
|
$("#MenuNo").append('<option value =""></option>');
|
for (var i = 0; i < res.data.length; i++) {
|
//判断层级不是按钮
|
if (res.data[i].Level != '2')
|
{
|
//模块菜单
|
if ((res.data[i].MenuNo).toString().substring(1) == '000')
|
{
|
$("#MenuNo").append('<option value =' + res.data[i].MenuNo + '>' + res.data[i].MenuName + '</option>');
|
}
|
//页面菜单
|
else
|
{
|
//console.log(res.data[i])
|
}
|
}
|
$("#MenuNo option[value='" + MenuNo + "']").attr("selected", "selected");
|
}
|
form.render('select');
|
}
|
else
|
{
|
//不成功
|
layer.msg('获取环境信息失败', {
|
icon: 2,
|
time: 2000 //2秒关闭(如果不配置,默认是3秒)
|
}, function() {
|
//回调
|
form.render('select');
|
});
|
}
|
});
|
}
|
//环境下拉框
|
sendData(IP + "/Sys/GetParentMenuList", param, 'post', function(res) {
|
if (res.code == 0) { //成功
|
for (var i = 0; i < res.data.length; i++) {
|
//判断层级不是按钮
|
if (res.data[i].Level != '2')
|
{
|
//模块菜单
|
if ((res.data[i].MenuNo).toString().substring(1) == '000')
|
{
|
$("#MenuNo").append('<option value =' + res.data[i].MenuNo + '>' + res.data[i].MenuName + '</option>');
|
}
|
//页面菜单
|
else
|
{
|
//console.log(res.data[i])
|
}
|
}
|
}
|
form.render('select');
|
}
|
else
|
{
|
//不成功
|
layer.msg('获取环境信息失败', {
|
icon: 2,
|
time: 2000 //2秒关闭(如果不配置,默认是3秒)
|
}, function() {
|
//回调
|
form.render('select');
|
});
|
}
|
});
|
});
|
</script>
|
</body>
|
</html>
|