Mini.Crm/Mini.Web/Areas/Admin/Views/RoleRightResource/Index.cshtml

190 lines
7.0 KiB
Plaintext

@using Mini.Web.WebHelper;
@{
ViewBag.Title = "Index";
Layout = "~/Areas/Admin/Views/Shared/_EasyUI_Layout.cshtml";
}
<div data-options="region:'north',border:false" style="height:30px;">
<div class="mvctool">
@*@Html.ToolButton("btnQuery", "icon-search", "查询", true)*@
@*@Html.Action("ToolBar", "Control", ViewBag.ToolBar as ToolBar)*@
@await Component.InvokeAsync("ToolBar", new { ToolBar = ViewBag.ToolBar as ToolBar })
</div>
</div>
<div data-options="region:'west',split:true" style="width:200px;border-left:none;border-bottom:none;padding:5px;">
<ul id="ulRole"></ul>
</div>
<div data-options="region:'center'" style="border-right: none; border-bottom: none; padding: 10px; ">
<ul id="ulRight"></ul>
</div>
<script type="text/javascript">
$(function () {
$('#ulRight').tree({
checkbox: true,
url: "RightGroup/GetRightTreeList?isSelect=true",
onLoadSuccess: function () {
$('.tree-checkbox').attr("onclick", "javascript:selectBttn(this);");
}
});
$('#ulRole').tree({
dnd: true,
url: "Role/GetRoleTree",
onSelect: function (node) {
Clear_RoleRight();
Load_RoleRight(node);
}
});
});
function selectBttn(right) {
if ($(right).hasClass("tree-checkbox1")) {
var $top_select = $(right).parent('div').next('ul');
var $cur_select = $(right).next('span').children('input');
if ($cur_select.length) {
$cur_select.each(function () {
$(this).removeAttr("checked");
})
}
else if ($top_select.length) {
$top_select.find('.tool_button').each(function () {
$(this).removeAttr("checked");
})
}
//$(right).next('span').children('input').each(function () {
// $(this).removeProp("checked");
//})
}
else {
var $top_select = $(right).parent('div').next('ul');
var $cur_select = $(right).next('span').children('input');
if ($cur_select.length) {
$cur_select.each(function () {
$(this).attr("checked", 'true');
});
}
else if ($top_select.length) {
$top_select.find('.tool_button').each(function () {
$(this).attr("checked", 'true');
})
}
//$(right).next('span').children('input').each(function () {
// $(this).prop("checked", 'true');
//})
}
}
function Clear_RoleRight() { //清除之前的角色权限
var checked = $("#ulRight").tree("getChecked");
$(checked).each(function (i, n) {
$("#ulRight").tree("uncheck", n.target);
});
}
function Load_RoleRight(node) { //加载角色对应的权限
$.r_post("RoleRightResource/GetBas_RoleRight?id=" + node.id, function (data) {
if (data) {
$(".tool_button").each(function () {
$(this).removeAttr("checked");
});
}
$(data).each(function (i, n) {
$("#ulRight").tree("check", $("#ulRight").tree("find", n.id).target);
$("input[name='" + n.id + "']").each(function () {
if (n.id == "B152")
{
console.log(Number(n.toolValue));
console.log($(this).val());
console.log(((Number(n.toolValue) & Number($(this).val())) > 0));
}
if (Number(n.toolValue) && ((Number(n.toolValue) & Number($(this).val())) > 0)) {
$(this).attr("checked", 'true');
}
});
});
}, "json");
}
</script>
<script type="text/javascript">
function ExpandAll_Click() {
$("#ulRight").tree("expandAll");
}
function CollapseAll_Click() {
$("#ulRight").tree("collapseAll");
}
function Reload_Click() {
var node = $("#ulRole").tree("getSelected");
if (node) {
Clear_RoleRight();
Load_RoleRight(node);
}
else {
//console
$('#ulRight').tree({
checkbox: true,
url: "RightGroup/GetRightTreeList?isSelect=true"
});
}
}
function Save_Click() {
var row = $('#ulRole').tree('getSelected');
if (row != null) {
$.messager.confirm('提示', '您确定要保存此角色的权限修改吗?', function (r) {
if (r) {
var checked = $("#ulRight").tree("getChecked");
var rightIds = [];
var hasbuttons;
$(checked).each(function (i, n) {
if (typeof n.id == "string") {
var buttons = 0;
$("input[name='" + n.id + "']:checked").each(function () {
buttons += Number($(this).val()) || 0;
hasbuttons = true;
});
rightIds.push({ rightId: n.id, buttons: buttons });
//rightIds += n.id + ",";
}
//rightIds += "" + (-parseInt(n.id.toString().replace("r_", ""))) + ",";
});
if (!hasbuttons) {
$.messager.confirm('提示', '按钮权限为空,是否要保存?', function (r) {
if (r) {
$.r_post("RoleRightResource/Save", { roleId: row.id, rightIds: JSON.stringify(rightIds) }, function (data) {
$.messageBox5s('提示', data.message);
}, "json");
}
})
}
else {
$.r_post("RoleRightResource/Save", { roleId: row.id, rightIds: JSON.stringify(rightIds) }, function (data) {
$.messageBox5s('提示', data.message);
}, "json");
}
//if (rightIds.length > 0)
// rightIds = rightIds.substr(0, rightIds.length - 1);
}
});
} else { $.messageBox5s('提示', '请您选中左边的角色!'); }
}
function AddRole_Click() {
$("#modalwindow").html(GetIframeHtml("Role/Edit"));
$("#modalwindow").window({ title: '新增角色', width: 700, height: 400, iconCls: 'icon-add' }).window('open');
}
function GetIframeHtml(src) {
return "<iframe width='100%' height='98%' scrolling='no' frameborder='0'' src='" + src + "'></iframe>";
}
</script>