419 lines
18 KiB
Plaintext
419 lines
18 KiB
Plaintext
@using CRM.Core.Model.Entity
|
||
@using Core.Web.WebHelper
|
||
@{
|
||
ViewBag.Title = "角色权限管理";
|
||
Layout = "~/Views/Shared/_Layout.cshtml";
|
||
}
|
||
|
||
<style>
|
||
.hiddentr {
|
||
display: none;
|
||
}
|
||
|
||
.redColor {
|
||
color: red;
|
||
}
|
||
|
||
.treeCooseColor {
|
||
background-color: #f3ebbc;
|
||
}
|
||
|
||
.treeCooseColor :hover {
|
||
background-color: #f3ebbc;
|
||
}
|
||
</style>
|
||
|
||
<div class="x-body" id="contentBody">
|
||
<div class="layui-btn-group" style="padding-bottom:10px;">
|
||
@Html.Action("ToolBar", "Home",
|
||
new {
|
||
area="",
|
||
rightcode = (ViewBag.rightCode as string),
|
||
otherToolBars =new Core.Web.WebHelper.ToolBar[]
|
||
{
|
||
new Core.Web.WebHelper.ToolBar(ToolBarConfig.CONST_Other1, "保存", "" ,"layui-icon-tabs")
|
||
}
|
||
}
|
||
)
|
||
@*<button class="layui-btn layui-btn-normal" data-method="other1">保存</button>*@
|
||
</div>
|
||
<div id="mytoolbar">
|
||
<form>
|
||
关键字:
|
||
<div class="layui-inline">
|
||
<input type="text" name="txt_rname" id="txt_rname" required lay-verify="required" placeholder="关键字" autocomplete="off" class="layui-input">
|
||
</div>
|
||
<input class="layui-btn layui-btn-sm layui-btn-ok" data-method="search" type="button" value="查询" />
|
||
<input class="layui-btn layui-btn-sm layui-btn-reset" type="reset" value="清空" />
|
||
</form>
|
||
</div>
|
||
<div class="layui-fluid">
|
||
<div class="layui-row">
|
||
<div class="layui-col-xs3">
|
||
<div id="leftrole" class="demo-tree demo-tree-box"></div>
|
||
</div>
|
||
<div class="layui-col-xs9" id="righttree">
|
||
@*<div id="rightp" class="demo-tree demo-tree-box"></div>*@
|
||
<table class="layui-hide" id="tab_kefuzhuangtaiyi1" lay-filter="wochao"></table>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<!--确定宽度-->
|
||
|
||
<script>
|
||
var table;
|
||
</script>
|
||
<script>
|
||
var selectRow = {};
|
||
var winindex;
|
||
var layer;
|
||
var rowid;
|
||
var choosenode;
|
||
var tree;
|
||
var righttreedata;
|
||
//注意:选项卡 依赖 element 模块,否则无法进行功能性操作
|
||
layui.use('element', function () {
|
||
var element = layui.element;
|
||
element.on('tab(tonghuajiankong)', function (n) {
|
||
$(".bodytable").addClass("hidden");
|
||
$("#kefuzhuangtai" + (n.index + 1)).removeClass("hidden");
|
||
});
|
||
element.on('tab(maintab)', function (n) {
|
||
if (n.index == 0)
|
||
$("#bottomcard").removeClass("hidden");
|
||
else
|
||
$("#bottomcard").addClass("hidden");
|
||
});
|
||
});
|
||
layui.use(['laypage', 'layer', 'table', 'laydate', 'tree'], function () {
|
||
tree = layui.tree;
|
||
layer = layui.layer;
|
||
table = layui.table;
|
||
|
||
LoadLeftRoleTree();
|
||
LoadRightSource();
|
||
|
||
var active = {
|
||
other1: function () {
|
||
if (choosenode == null || choosenode.id == null) {
|
||
layer.alert("没有选择修改的角色!", { title: '提示' });
|
||
//layer.msg('没有选择修改的角色!', { icon: 2 });
|
||
return;
|
||
}
|
||
layer.confirm('确定要您确定要保存此角色的权限修改吗?', { icon: 3, title: '提示' }, function (index) {
|
||
var loadingindex = layer.load(3, { shade: false });
|
||
|
||
var mydata = {
|
||
RID: choosenode.id,
|
||
RNAME: choosenode.title,
|
||
PERMISSON: []
|
||
};
|
||
var i = 0;
|
||
$("#righttree .myAllbutton input:checked").each(function (n, x) {
|
||
var pid = $(this).val();
|
||
var pcode = $(this).attr("pcode");
|
||
var pname = $(this).attr("pname");
|
||
if (pid != "0") {
|
||
|
||
var buttons = 0;
|
||
$(this).parent().nextAll(".mybutton").find("input:checked").each(function (a, n) {
|
||
buttons += Number($(this).attr("butid")) || 0;
|
||
});
|
||
mydata.PERMISSON[i] = {
|
||
CODE: pcode,
|
||
PNAME: pname,
|
||
TOOLBARAVLUE: buttons,
|
||
PID: pid
|
||
}
|
||
i++;
|
||
}
|
||
|
||
});
|
||
//console.log(mydata);
|
||
$.ajax({
|
||
type: "POST",
|
||
url: "Save",
|
||
data: mydata,
|
||
dataType: "json",
|
||
success: function (da) {
|
||
layer.close(loadingindex);
|
||
if (da.result == true) {
|
||
layer.msg('操作成功!', { icon: 1 });
|
||
} else {
|
||
layer.msg(da.retmsg, { icon: 2 });
|
||
}
|
||
},
|
||
error: function () {
|
||
layer.close(loadingindex);
|
||
layer.msg('操作失败!', { icon: 2 });
|
||
}
|
||
});
|
||
layer.close(index);
|
||
}
|
||
);
|
||
}, search: function () {
|
||
|
||
$(".redColor").each(function (i, n) {
|
||
$(this).after($(this).attr("ntitle"));
|
||
$(this).remove();
|
||
});
|
||
var txt = $.trim($("#txt_rname").val());
|
||
if (txt == "")
|
||
return;
|
||
$("#contentBody tbody tr td[data-field='CODE'],[data-field='ID'] .layui-table-cell ").each(function () {
|
||
var html = $(this).html();
|
||
html = html.replace(txt, "<b ntitle=\"" + txt + "\" class=\"redColor\">" + txt + "</b>");
|
||
$(this).html(html);
|
||
|
||
});
|
||
$("#contentBody tbody tr td[data-field='NAME'] .layui-table-cell .mspan").each(function () {
|
||
var html = $(this).html();
|
||
html = html.replace(txt, "<b ntitle=\"" + txt + "\" class=\"redColor\">" + txt + "</b>");
|
||
$(this).html(html);
|
||
});
|
||
}
|
||
};
|
||
$('.layui-btn').on('click', function () {
|
||
var othis = $(this), method = othis.data('method');
|
||
active[method] ? active[method].call(this, othis) : '';
|
||
|
||
});
|
||
});
|
||
|
||
function Closed() {
|
||
layer.close(winindex);
|
||
}
|
||
function TableReload() {
|
||
table.reload('testReload', {
|
||
page: {
|
||
curr: 1 //重新从第 1 页开始
|
||
}
|
||
});
|
||
}
|
||
function LoadLeftRoleTree() {
|
||
$.ajax({
|
||
type: "POST",
|
||
url: "/Role/GetList",
|
||
dataType: "json",
|
||
success: function (da) {
|
||
if (da.code == 0) {
|
||
var treedata = [];
|
||
$(da.data).each(function (n, wa) {
|
||
treedata[n] = {
|
||
title: wa.RNAME
|
||
, id: wa.ROLEID
|
||
}
|
||
});
|
||
//开启节点操作图标
|
||
tree.render({
|
||
elem: '#leftrole'
|
||
, data: treedata
|
||
, id: "demoId"
|
||
, onlyIconControl: true //是否仅允许节点左侧图标控制展开收缩
|
||
, click: function (obj) {
|
||
|
||
$(".treeCooseColor").removeClass("treeCooseColor");
|
||
$("#leftrole [data-id='" + obj.data.id + "']").children().first().addClass("treeCooseColor");
|
||
choosenode = obj.data;
|
||
InitRiht(obj.data.id);
|
||
|
||
}
|
||
});
|
||
|
||
|
||
} else {
|
||
layer.msg(da.retmsg, { icon: 2 });
|
||
}
|
||
},
|
||
error: function () {
|
||
layer.msg('获取权限菜单失败!', { icon: 2 });
|
||
}
|
||
});
|
||
}
|
||
|
||
function LoadRightSource() {
|
||
table.render({
|
||
id: 'testReload'//列表别名ID
|
||
, elem: '#tab_kefuzhuangtaiyi1'
|
||
, url: 'GetTreeList'
|
||
, method: 'POST'
|
||
, cellMinWidth: 80 //全局定义常规单元格的最小宽度,layui 2.2.1 新增
|
||
, page: false
|
||
//, height: "full-200"
|
||
, cols: [[
|
||
{
|
||
field: 'NAME', title: '名称', templet: function (d) {
|
||
var html = '<span style="padding-left:' + (d.TYPE - 1) * 20 + 'px;" myparentids="' + d.PARENTSTR + '" myparent="' + d.PRENTID + '" nmyid="' + d.ID + '" mytype="' + d.TYPE + '""></span>';
|
||
if (d.ISHAVECHILD == 1)
|
||
html += '<i class="layui-icon layui-icon-subtraction manmagerhidden" myid="' + d.ID + '" style="border:1px solid #c0c4cc;cursor:pointer;font-size:12px;" onclick="HiddenOrShow(' + d.ID + ')"></i> ';
|
||
else
|
||
html += '<i class="layui-icon layui-icon-file" ></i> ';
|
||
html += '<span class="myAllbutton"><input name="mb_' + d.ID + '" myparentidsck="' + d.PARENTSTR + '" lay-skin="primary" pname="' + d.NAME + '" pcode="' + d.CODE + '" type="checkbox" value="' + d.ID + '" id="ck_' + d.ID + '"/></span> ';
|
||
html += '<span class="mspan">' + d.NAME + "</span>"
|
||
html += "<span class='mybutton' mybutton='mkn_" + d.ID + "'>";
|
||
$(d.buttonlist).each(function (n, bda) {
|
||
if (bda.CODE.indexOf("Other") > -1)
|
||
html += ' <input pid="' + d.ID + '" name="mb_' + bda.ID + '" class="woco" lay-skin="primary" butid="' + bda.BUTTONID + '" type="checkbox" value="' + bda.ID + '" id="ck_' + bda.ID + '" site="' + bda.SITE +'"/> <span class="layui-badge layui-bg-cyan" code="' + bda.CODE + '" myname="' + bda.NAME + '">' + bda.NAME + '</span> ';
|
||
else
|
||
html += ' <input pid="' + d.ID + '" name="mb_' + bda.ID + '" class="woco" lay-skin="primary" butid="' + bda.BUTTONID + '" type="checkbox" value="' + bda.ID + '" id="ck_' + bda.ID + '" site="' + bda.SITE +'"/> <span class="layui-badge layui-bg-blue" code="' + bda.CODE + '" myname="' + bda.NAME + '">' + bda.NAME + '</span> ';
|
||
});
|
||
html += "</span>";
|
||
return html;
|
||
}
|
||
}
|
||
|
||
]],
|
||
done: function () {
|
||
$("#righttree .myAllbutton .layui-form-checkbox .layui-icon").click(function () {
|
||
console.log("点击了哦1")
|
||
var checkbox = $(this).parent().prev();
|
||
var clickid = checkbox.val();
|
||
var parentstr = checkbox.attr("myparentidsck");
|
||
var isCheck = checkbox.is(':checked');
|
||
$(this).parent().parent().nextAll(".mybutton").find(".layui-form-checkbox").each(function () {
|
||
if (isCheck) {
|
||
if ($(this).hasClass("layui-form-checked")) {
|
||
$(this).click();
|
||
}
|
||
}
|
||
else {
|
||
if (!$(this).hasClass("layui-form-checked")) {
|
||
$(this).click();
|
||
}
|
||
}
|
||
|
||
});
|
||
|
||
$("#righttree [myparentids]").each(function (n, m) {
|
||
var str = $(this).attr("myparentids");
|
||
var myparentid = parseInt($(this).attr("myparent"));
|
||
var myid = parseInt($(this).attr("nmyid"));
|
||
|
||
if (str.indexOf("[" + clickid + "]") > -1 || parentstr.indexOf("[" + myid + "]") > -1) {
|
||
//console.log(clickid + "" + parentstr);
|
||
if (isCheck) {
|
||
if (parentstr.indexOf("[" + myid + "]") == -1) {
|
||
var wc = $(this).nextAll(".myAllbutton").find(".layui-form-checkbox");
|
||
if (wc.hasClass("layui-form-checked")) {
|
||
wc.click();
|
||
}
|
||
$(this).nextAll(".mybutton").find(".layui-form-checkbox").each(function () {
|
||
if ($(this).hasClass("layui-form-checked")) {
|
||
$(this).click();
|
||
}
|
||
});
|
||
}
|
||
}
|
||
else {
|
||
|
||
var wc = $(this).nextAll(".myAllbutton").find(".layui-form-checkbox");
|
||
if (!wc.hasClass("layui-form-checked")) {
|
||
wc.click();
|
||
}
|
||
$(this).nextAll(".mybutton").find(".layui-form-checkbox").each(function () {
|
||
if (!$(this).hasClass("layui-form-checked")) {
|
||
$(this).click();
|
||
}
|
||
});
|
||
|
||
}
|
||
}
|
||
});
|
||
});
|
||
}
|
||
|
||
});
|
||
}
|
||
function HiddenOrShow(id) {
|
||
var clickbutton = $("[myid='" + id + "']");
|
||
var isHidden = $(clickbutton).hasClass("layui-icon-subtraction");
|
||
if (isHidden)
|
||
$(clickbutton).removeClass("layui-icon-subtraction").addClass("layui-icon-addition");
|
||
else
|
||
$(clickbutton).removeClass("layui-icon-addition").addClass("layui-icon-subtraction");
|
||
$("[myparentids]").each(function (n, m) {
|
||
var str = $(this).attr("myparentids");
|
||
var myparentid = parseInt($(this).attr("myparent"));
|
||
if (str.indexOf("[" + id + "]") > -1) {
|
||
if (isHidden)
|
||
$(this).parent().parent().parent().addClass("hiddentr");
|
||
else {
|
||
if ($("[myid='" + myparentid + "']").hasClass("layui-icon-subtraction"))
|
||
$(this).parent().parent().parent().removeClass("hiddentr");
|
||
}
|
||
}
|
||
});
|
||
|
||
}
|
||
function checkNode(obj) {
|
||
if (obj.checked) {
|
||
$("#rightp [data-id='" + obj.data.id + "']").find(".layui-tree-txt .layui-form-checkbox").each(function (w, a) {
|
||
if (!$(this).hasClass("layui-form-checked")) {
|
||
$(this).click();
|
||
}
|
||
});
|
||
} else {
|
||
$("#rightp [data-id='" + obj.data.id + "']").find(".layui-tree-txt .layui-form-checkbox").each(function (w, a) {
|
||
if ($(this).hasClass("layui-form-checked")) {
|
||
$(this).click();
|
||
}
|
||
});
|
||
}
|
||
}
|
||
//点击后初始化角色权限
|
||
function InitRiht(id) {
|
||
var loadingindex = layer.load(3, { shade: false });
|
||
$.ajax({
|
||
type: "POST",
|
||
url: "GetDetials",
|
||
data: { roleId: id },
|
||
dataType: "json",
|
||
success: function (da) {
|
||
layer.close(loadingindex);
|
||
if (da.result == true) {
|
||
ClearChoose();
|
||
console.log(da);
|
||
$(da.retmsg.PERMISSON).each(function (w, ax) {
|
||
//console.log(ax);
|
||
var checkbox = $("#ck_" + ax.PID + "[pcode='" + ax.CODE + "']").nextAll(".layui-form-checkbox");
|
||
checkbox.click();
|
||
//console.log(checkbox.parent().nextAll(".mybutton").find("input[type='checkbox']").length);
|
||
checkbox.parent().nextAll(".mybutton").find("input[type='checkbox']").each(function (aa, bb) {
|
||
//console.log(bb);
|
||
if (Number(ax.TOOLBARAVLUE) && ((Number(ax.TOOLBARAVLUE) & Number($(this).attr("butid"))) > 0)) {
|
||
$(this).next().first().click();
|
||
}
|
||
});
|
||
|
||
});
|
||
if (da.retmsg.PERMISSON.length > 0) {
|
||
$("#ck_0").nextAll(".layui-form-checkbox").click();
|
||
}
|
||
|
||
} else {
|
||
layer.msg(da.retmsg, { icon: 2 });
|
||
}
|
||
},
|
||
error: function () {
|
||
layer.close(loadingindex);
|
||
layer.msg('操作失败!', { icon: 2 });
|
||
}
|
||
});
|
||
}
|
||
function ClearChoose() {
|
||
$("#righttree").find(".layui-form-checkbox").each(function (w, a) {
|
||
if ($(this).hasClass("layui-form-checked")) {
|
||
$(this).click();
|
||
}
|
||
});
|
||
}
|
||
function woadfasd() {
|
||
$('[id=\'ck_1207491800\']').click();
|
||
}
|
||
//function test() {
|
||
// $("#righttree .myAllbutton .layui-form-checkbox").click();
|
||
//}
|
||
</script>
|
||
@*<input value="测试" type="button" onclick="test()"/>*@ |