<!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" />
|
</head>
|
<body>
|
<div class="layui-fluid" style="padding-bottom: 0">
|
<div class="layui-card">
|
<div class="layui-form layui-card-header layuiadmin-card-header-auto" style="border-bottom:1px solid #CCC">
|
<div class="layui-form-item">
|
<div class="layui-inline">
|
<label class="layui-form-label" style="width: 56px">角色编号</label>
|
<div class="layui-input-inline">
|
<input type="text" id="RoleNo" name="RoleNo" placeholder="角色编号" autocomplete="off" class="layui-input"/>
|
</div>
|
</div>
|
<div class="layui-inline">
|
<label class="layui-form-label" style="width: 56px">角色名称</label>
|
<div class="layui-input-inline">
|
<input type="text" id="RoleName" name="RoleName" placeholder="角色名称" autocomplete="off" class="layui-input"/>
|
</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>
|
</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" data-type="add" id="approvalBtn">
|
<i class="layui-icon"></i>添加
|
</button>
|
<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="table-content-list">
|
<a class="layui-btn layui-btn-normal layui-btn-xs editClass" id="editClass" lay-event="edit" >
|
<i class="layui-icon layui-icon-edit"></i>编辑
|
</a>
|
<a class="layui-btn layui-btn-xs roleClass" id="roleClass" style="background-color: rgb(67, 90, 20);" lay-event="roleright" >
|
<i class="layui-icon layui-icon-util"></i>分配权限
|
</a>
|
<a class="layui-btn layui-btn-danger layui-btn-xs approvalBtndel" id="approvalBtndel" lay-event="del" >
|
<i class="layui-icon layui-icon-delete"></i>删除
|
</a>
|
</script>
|
</div>
|
</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>
|
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;
|
|
refreshTable("", "");
|
var tableIns;
|
|
function refreshTable(RoleNo, RoleName) {
|
var param = {
|
RoleNo: RoleNo,
|
RoleName: RoleName,
|
};
|
sendData(IP + "/Basis/GetRolesList?RoleNo=" + RoleNo + "&&RoleName=" + RoleName, {}, "get", function (res) {
|
if (res.code == 0)
|
{
|
//成功
|
var list = res.data;
|
$.extend(infoOptions, {
|
data: list,
|
});
|
infoOptions.page = {
|
curr: 1,
|
};
|
tableIns = table.render(infoOptions);
|
}
|
else
|
{
|
//不成功
|
layer.msg(
|
"获取角色列表信息失败!",
|
{
|
icon: 2,
|
time: 2000, //2秒关闭(如果不配置,默认是3秒)
|
},
|
function () {}
|
);
|
}
|
});
|
}
|
sendData(IP + "/basis/GetRoleRightList", {}, "get", function (res) {
|
$(function() {
|
$("#approvalBtn").hide();
|
});
|
$(function() {
|
$(".editClass").hide();
|
});
|
$(function() {
|
$(".roleClass").hide();
|
});
|
$(function() {
|
$(".approvalBtndel").hide();
|
});
|
if (res.code == 0)
|
{
|
//成功
|
for (var k = 0; k < res.data.length; k++)
|
{
|
if (res.data[k].MenuName == "编辑角色")
|
{
|
$(function () {
|
$(".editClass").show();
|
});
|
}
|
if (res.data[k].MenuName == "分配权限")
|
{
|
$(function () {
|
$(".roleClass").show();
|
});
|
}
|
if (res.data[k].MenuName == "添加角色")
|
{
|
$(function () {
|
$("#approvalBtn").show();
|
});
|
}
|
if (res.data[k].MenuName == "删除角色")
|
{
|
$(function () {
|
$(".approvalBtndel").show();
|
});
|
}
|
}
|
}
|
else
|
{
|
//不成功
|
layer.msg(
|
"获取信息失败",
|
{
|
icon: 2,
|
time: 2000, //2秒关闭(如果不配置,默认是3秒)
|
},
|
function () {
|
//回调
|
}
|
);
|
}
|
});
|
|
var infoOptions = {
|
elem: "#LAY-app-content-list",
|
height: "full-130",
|
id: "LAY-app-content-list",
|
page: true,
|
limit: pageCnt,
|
limits: pageLimits,
|
even: true,
|
cellMinWidth: 80, //全局定义常规单元格的最小宽度,layui 2.2.1 新增
|
cols:
|
[[
|
{
|
title: "序号", type: "numbers", fixed: "left", width: 65,
|
},
|
{
|
field: "RoleNo", title: "角色号", align: "center"
|
},
|
{
|
field: "RoleName", title: "角色名称", align: "center"
|
},
|
{
|
field: "Demo", title: "备注", align: "center"
|
},
|
{
|
field: "CreateUserName", title: "创建人", align: "center"
|
},
|
{
|
field: "CreateTime", title: "创建日期", align: "center",
|
templet: function (d) {
|
return formatDate(d.CreateTime);
|
}
|
},
|
{
|
field: "UpdateUserName", title: "更改人", align: "center"
|
},
|
{
|
field: "UpdateTime", title: "更改日期", align: "center",
|
templet: function (d) {
|
return formatDate(d.UpdateTime);
|
}
|
},
|
{
|
title: "操作", fixed: "right", align: "center", toolbar: "#table-content-list", width: 240
|
},
|
]]
|
};
|
|
sendData(IP + "/basis/GetRolesList", {}, "get", function (res) {
|
var html = "";
|
if (res.code == 0)
|
{
|
//成功
|
var list = res.data;
|
for (var i = 0; i < list.length; i++) {
|
html += '<option value = "' + list[i].Id + '">' + list[i].RoleName + "</option>";
|
}
|
$("#Type").append(html);
|
form.render("select");
|
}
|
else
|
{
|
//不成功
|
layer.msg(
|
"获取角色信息失败!",
|
{
|
icon: 2,
|
time: 2000, //2秒关闭(如果不配置,默认是3秒)
|
},
|
function () {}
|
);
|
}
|
});
|
|
//监听搜索
|
form.on("submit(LAY-app-contlist-search)", function (data) {
|
var RoleNo = data.field.RoleNo;
|
var RoleName = data.field.RoleName;
|
refreshTable(RoleNo, RoleName);
|
});
|
|
var id = 0;
|
table.on("tool(LAY-app-content-list)", function (obj) {
|
var data = obj.data;
|
//编辑
|
if (obj.event === "edit")
|
{
|
id = data.Id;
|
//console.log(data.Id)
|
layer.open({
|
type: 2,
|
title: "编辑角色信息",
|
content: "RoleForm.html?id=" + data.Id,
|
maxmin: true,
|
area: ["450px", "300px"],
|
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
|
RoleNo: field.RoleNo, //角色号
|
RoleName: field.RoleName, //角色名称
|
Demo: field.Demo, //备注
|
};
|
sendData( IP + "/basis/UpdateRolesInfo", param, "post", function (res) {
|
if (res.code == 0)
|
{
|
//成功
|
layer.msg(
|
"修改成功",
|
{
|
icon: 1,
|
time: 1000, //2秒关闭(如果不配置,默认是3秒)
|
},
|
function () {
|
refreshTable($("#RoleName").val(), $("#RoleNo").val());
|
layer.close(index); //关闭弹层
|
doing = true;
|
}
|
);
|
}
|
else
|
{
|
//不成功
|
layer.msg(
|
res.msg,
|
{
|
icon: 2,
|
time: 2000, //2秒关闭(如果不配置,默认是3秒)
|
},
|
function () {
|
doing = true;
|
}
|
);
|
}
|
});
|
}
|
);
|
submit.trigger("click");
|
},
|
});
|
}
|
//分配权限
|
else if (obj.event === "roleright")
|
{
|
id = data.Id;
|
layer.open({
|
type: 2,
|
title: "分配角色权限",
|
content: "RoleRight.html?id=" + id,
|
maxmin: true,
|
area: ["720px", "800px"],
|
// 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
|
RoleNo: field.SortCode, //角色号
|
RoleName: field.Name, //角色名称
|
Demo: field.Demo, //备注
|
};
|
sendData( IP + "/basis/UpdateRolesInfo", param, "post", function (res) {
|
if (res.code == 0)
|
{
|
//成功
|
layer.msg(
|
"修改成功",
|
{
|
icon: 1,
|
time: 1000, //2秒关闭(如果不配置,默认是3秒)
|
},
|
function () {
|
refreshTable($("#RoleName").val(), $("#RoleNo").val());
|
layer.close(index); //关闭弹层
|
doing = true;
|
}
|
);
|
}
|
else
|
{
|
//不成功
|
layer.msg(
|
res.msg,
|
{
|
icon: 2,
|
time: 2000, //2秒关闭(如果不配置,默认是3秒)
|
},
|
function () {
|
doing = true;
|
}
|
);
|
}
|
});
|
});
|
submit.trigger("click");
|
},
|
});
|
}
|
//删除
|
else if (obj.event === "del") {
|
layer.confirm("确定删除选中的角色?", function (index) {
|
// console.log(data);
|
cusid = data.Id;
|
var arr = [];
|
arr.push(cusid); //属性
|
var param = {
|
Ids: arr,
|
};
|
if (doing)
|
{
|
doing = false;
|
sendData( IP + "/Basis/DeleteRoleInfo?Roleids=" + data.Id + "", {}, "post", function (res) {
|
console.log(res);
|
if (res.code == 0)
|
{
|
//成功
|
layer.msg(
|
res.msg,
|
{
|
icon: 1,
|
time: 2000, //2秒关闭(如果不配置,默认是3秒)
|
},
|
function () {
|
refreshTable($("#RoleName").val(), $("#RoleNo").val());
|
doing = true;
|
}
|
);
|
}
|
else
|
{
|
//不成功
|
layer.msg(
|
res.msg,
|
{
|
icon: 2,
|
time: 2000, //2秒关闭(如果不配置,默认是3秒)
|
},
|
function () {
|
doing = true;
|
}
|
);
|
}
|
});
|
}
|
else
|
{
|
console.log(123);
|
}
|
});
|
}
|
});
|
|
var doing = true;
|
//添加
|
active = {
|
add: function () {
|
layer.open({
|
type: 2,
|
title: "添加角色信息",
|
content: "RoleForm.html",
|
maxmin: true,
|
area: ["450px", "300px"],
|
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 = {
|
RoleNo: field.RoleNo, //角色号
|
RoleName: field.RoleName, //角色名称
|
Demo: field.Demo, //备注
|
};
|
if (doing)
|
{
|
doing = false;
|
sendData( IP + "/basis/InsertRoleInfo", param, "post", function (res) {
|
if (res.code == 0)
|
{
|
//成功
|
layer.msg(
|
res.msg,
|
{
|
icon: 1,
|
time: 2000, //2秒关闭(如果不配置,默认是3秒)
|
},
|
function () {
|
refreshTable($("#RoleName").val(), $("#RoleNo").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) : "";
|
});
|
});
|
</script>
|
</body>
|
</html>
|