优化权限规则列表显示

pull/446/head
Karson 2023-06-16 23:05:05 +08:00
parent 42fdea065a
commit 2c66c67d71
6 changed files with 96 additions and 31 deletions

View File

@ -36,7 +36,7 @@ class Rule extends Backend
$v['title'] = __($v['title']); $v['title'] = __($v['title']);
} }
unset($v); unset($v);
Tree::instance()->init($ruleList); Tree::instance()->init($ruleList)->icon = ['    ', '    ', '    '];
$this->rulelist = Tree::instance()->getTreeList(Tree::instance()->getTreeArray(0), 'title'); $this->rulelist = Tree::instance()->getTreeList(Tree::instance()->getTreeArray(0), 'title');
$ruledata = [0 => __('None')]; $ruledata = [0 => __('None')];
foreach ($this->rulelist as $k => &$v) { foreach ($this->rulelist as $k => &$v) {

View File

@ -32,7 +32,7 @@ class Rule extends Backend
$v['remark'] = __($v['remark']); $v['remark'] = __($v['remark']);
} }
unset($v); unset($v);
Tree::instance()->init($ruleList); Tree::instance()->init($ruleList)->icon = ['    ', '    ', '    '];
$this->rulelist = Tree::instance()->getTreeList(Tree::instance()->getTreeArray(0), 'title'); $this->rulelist = Tree::instance()->getTreeList(Tree::instance()->getTreeArray(0), 'title');
$ruledata = [0 => __('None')]; $ruledata = [0 => __('None')];
foreach ($this->rulelist as $k => &$v) { foreach ($this->rulelist as $k => &$v) {

View File

@ -12,5 +12,8 @@ return [
'Menu tips' => '规则任意,请不可重复,仅做层级显示,无需匹配控制器和方法', 'Menu tips' => '规则任意,请不可重复,仅做层级显示,无需匹配控制器和方法',
'Node tips' => '模块/控制器/方法名', 'Node tips' => '模块/控制器/方法名',
'Weigh' => '权重', 'Weigh' => '权重',
'Status' => '状态' 'Status' => '状态',
'Toggle all' => '显示全部',
'Toggle menu visible' => '点击切换菜单显示',
'Toggle sub menu' => '点击切换子菜单',
]; ];

View File

@ -14,6 +14,7 @@
<li><a class="btn btn-link btn-multi btn-disabled disabled" href="javascript:;" data-params="status=hidden"><i class="fa fa-eye-slash"></i> {:__('Set to hidden')}</a></li> <li><a class="btn btn-link btn-multi btn-disabled disabled" href="javascript:;" data-params="status=hidden"><i class="fa fa-eye-slash"></i> {:__('Set to hidden')}</a></li>
</ul> </ul>
</div> </div>
<a href="javascript:;" class="btn btn-danger btn-toggle-all"><i class="fa fa-plus"></i> {:__('Toggle all')}</a>
</div> </div>
<table id="table" class="table table-striped table-bordered table-hover table-nowrap" <table id="table" class="table table-striped table-bordered table-hover table-nowrap"
data-operate-edit="{:$auth->check('user/rule/edit')}" data-operate-edit="{:$auth->check('user/rule/edit')}"

View File

@ -37,12 +37,6 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'template'], function
table: table, table: table,
formatter: Table.api.formatter.toggle formatter: Table.api.formatter.toggle
}, },
{
field: 'id',
title: '<a href="javascript:;" class="btn btn-success btn-xs btn-toggle" style="border-top:none;"><i class="fa fa-chevron-up"></i></a>',
operate: false,
formatter: Controller.api.formatter.subnode
},
{ {
field: 'operate', field: 'operate',
title: __('Operate'), title: __('Operate'),
@ -56,10 +50,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'template'], function
search: false, search: false,
commonSearch: false, commonSearch: false,
rowAttributes: function (row, index) { rowAttributes: function (row, index) {
if (this.totalRows > 500) { return row.pid == 0 ? {} : {style: "display:none"};
return row.pid == 0 ? {} : {style: "display:none"};
}
return row.haschild == 1 || row.ismenu == 1 ? {} : {style: "display:none"};
} }
}); });
@ -104,13 +95,27 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'template'], function
//显示隐藏子节点 //显示隐藏子节点
$(document).on("click", ".btn-node-sub", function (e) { $(document).on("click", ".btn-node-sub", function (e) {
var status = $(this).data("shown") ? true : false; var status = $(this).data("shown") ? true : false;
$("a.btn[data-pid='" + $(this).data("id") + "']").each(function () { $("a[data-pid='" + $(this).data("id") + "']").each(function () {
$(this).closest("tr").toggle(!status); $(this).closest("tr").toggle(!status);
}); });
if (status) {
$("a[data-pid='" + $(this).data("id") + "']").trigger("collapse");
}
$(this).data("shown", !status); $(this).data("shown", !status);
$("i", this).toggleClass("fa-caret-down").toggleClass("fa-caret-right");
return false; return false;
}); });
//隐藏子节点
$(document).on("collapse", ".btn-node-sub", function () {
if ($("i", this).length > 0) {
$("a[data-pid='" + $(this).data("id") + "']").trigger("collapse");
}
$("i", this).removeClass("fa-caret-down").addClass("fa-caret-right");
$(this).data("shown", false);
$(this).closest("tr").toggle(false);
});
//批量删除后的回调 //批量删除后的回调
$(".toolbar > .btn-del,.toolbar .btn-more~ul>li>a").data("success", function (e) { $(".toolbar > .btn-del,.toolbar .btn-more~ul>li>a").data("success", function (e) {
Fast.api.refreshmenu(); Fast.api.refreshmenu();
@ -118,12 +123,11 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'template'], function
//展开隐藏一级 //展开隐藏一级
$(document.body).on("click", ".btn-toggle", function (e) { $(document.body).on("click", ".btn-toggle", function (e) {
$("a.btn[data-id][data-pid][data-pid!=0].disabled").closest("tr").hide(); $("a[data-id][data-pid][data-pid!=0].disabled").closest("tr").hide();
var that = this; var that = this;
var show = $("i", that).hasClass("fa-chevron-down"); var show = $("i", that).hasClass("fa-chevron-down");
$("i", that).toggleClass("fa-chevron-down", !show); $("i", that).toggleClass("fa-chevron-down", !show).toggleClass("fa-chevron-up", show);
$("i", that).toggleClass("fa-chevron-up", show); $("a[data-id][data-pid][data-pid!=0]").not('.disabled').closest("tr").toggle(show);
$("a.btn[data-id][data-pid][data-pid!=0]").not('.disabled').closest("tr").toggle(show);
$(".btn-node-sub[data-pid=0]").data("shown", show); $(".btn-node-sub[data-pid=0]").data("shown", show);
}); });
@ -131,10 +135,10 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'template'], function
$(document.body).on("click", ".btn-toggle-all", function (e) { $(document.body).on("click", ".btn-toggle-all", function (e) {
var that = this; var that = this;
var show = $("i", that).hasClass("fa-plus"); var show = $("i", that).hasClass("fa-plus");
$("i", that).toggleClass("fa-plus", !show); $("i", that).toggleClass("fa-plus", !show).toggleClass("fa-minus", show);
$("i", that).toggleClass("fa-minus", show); $(".btn-node-sub:not([data-pid=0])").closest("tr").toggle(show);
$(".btn-node-sub.disabled").closest("tr").toggle(show);
$(".btn-node-sub").data("shown", show); $(".btn-node-sub").data("shown", show);
$(".btn-node-sub > i").toggleClass("fa-caret-down", show).toggleClass("fa-caret-right", !show);
}); });
}, },
add: function () { add: function () {
@ -147,17 +151,18 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'template'], function
formatter: { formatter: {
title: function (value, row, index) { title: function (value, row, index) {
value = value.toString().replace(/(&|&amp;)nbsp;/g, '&nbsp;'); value = value.toString().replace(/(&|&amp;)nbsp;/g, '&nbsp;');
return !row.ismenu || row.status == 'hidden' ? "<span class='text-muted'>" + value + "</span>" : value; var caret = row.haschild == 1 || row.ismenu == 1 ? '<i class="fa fa-caret-right"></i>' : '';
value = value.indexOf("&nbsp;") > -1 ? value.replace(/(.*)&nbsp;/, "$1" + caret) : caret + value;
value = !row.ismenu || row.status == 'hidden' ? "<span class='text-muted'>" + value + "</span>" : value;
return '<a href="javascript:;" data-toggle="tooltip" title="' + __('Toggle sub menu') + '" data-id="' + row.id + '" data-pid="' + row.pid + '" class="'
+ (row.haschild == 1 || row.ismenu == 1 ? 'text-primary' : 'disabled') + ' btn-node-sub">' + value + '</a>';
}, },
name: function (value, row, index) { name: function (value, row, index) {
return !row.ismenu || row.status == 'hidden' ? "<span class='text-muted'>" + value + "</span>" : value; return !row.ismenu || row.status == 'hidden' ? "<span class='text-muted'>" + value + "</span>" : value;
}, },
icon: function (value, row, index) { icon: function (value, row, index) {
return '<span class="' + (!row.ismenu || row.status == 'hidden' ? 'text-muted' : '') + '"><i class="' + value + '"></i></span>'; return '<span class="' + (!row.ismenu || row.status == 'hidden' ? 'text-muted' : '') + '"><i class="' + value + '"></i></span>';
},
subnode: function (value, row, index) {
return '<a href="javascript:;" data-toggle="tooltip" title="' + __('Toggle sub menu') + '" data-id="' + row.id + '" data-pid="' + row.pid + '" class="btn btn-xs '
+ (row.haschild == 1 || row.ismenu == 1 ? 'btn-success' : 'btn-default disabled') + ' btn-node-sub"><i class="fa fa-sitemap"></i></a>';
} }
}, },
bindevent: function () { bindevent: function () {

View File

@ -21,18 +21,16 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
url: $.fn.bootstrapTable.defaults.extend.index_url, url: $.fn.bootstrapTable.defaults.extend.index_url,
pk: 'id', pk: 'id',
sortName: 'weigh', sortName: 'weigh',
escape: false,
columns: [ columns: [
[ [
{checkbox: true}, {checkbox: true},
{field: 'id', title: __('Id')}, {field: 'id', title: __('Id')},
{field: 'pid', title: __('Pid'), visible: false}, {field: 'pid', title: __('Pid'), visible: false},
{field: 'title', title: __('Title'), align: 'left', formatter:function (value, row, index) { {field: 'title', title: __('Title'), align: 'left', formatter: Controller.api.formatter.title},
return value.toString().replace(/(&|&amp;)nbsp;/g, '&nbsp;');
}
},
{field: 'name', title: __('Name'), align: 'left'}, {field: 'name', title: __('Name'), align: 'left'},
{field: 'remark', title: __('Remark')}, {field: 'remark', title: __('Remark')},
{field: 'ismenu', title: __('Ismenu'), formatter: Table.api.formatter.toggle}, // {field: 'ismenu', title: __('Ismenu'), formatter: Table.api.formatter.toggle},
{field: 'createtime', title: __('Createtime'), formatter: Table.api.formatter.datetime, operate: 'RANGE', addclass: 'datetimerange', sortable: true, visible: false}, {field: 'createtime', title: __('Createtime'), formatter: Table.api.formatter.datetime, operate: 'RANGE', addclass: 'datetimerange', sortable: true, visible: false},
{field: 'updatetime', title: __('Updatetime'), formatter: Table.api.formatter.datetime, operate: 'RANGE', addclass: 'datetimerange', sortable: true, visible: false}, {field: 'updatetime', title: __('Updatetime'), formatter: Table.api.formatter.datetime, operate: 'RANGE', addclass: 'datetimerange', sortable: true, visible: false},
{field: 'weigh', title: __('Weigh')}, {field: 'weigh', title: __('Weigh')},
@ -43,10 +41,57 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
pagination: false, pagination: false,
search: false, search: false,
commonSearch: false, commonSearch: false,
rowAttributes: function (row, index) {
return row.pid == 0 ? {} : {style: "display:none"};
}
}); });
// 为表格绑定事件 // 为表格绑定事件
Table.api.bindevent(table); Table.api.bindevent(table);
//显示隐藏子节点
$(document).on("click", ".btn-node-sub", function (e) {
var status = $(this).data("shown") ? true : false;
$("a[data-pid='" + $(this).data("id") + "']").each(function () {
$(this).closest("tr").toggle(!status);
});
if (status) {
$("a[data-pid='" + $(this).data("id") + "']").trigger("collapse");
}
$(this).data("shown", !status);
$("i", this).toggleClass("fa-caret-down").toggleClass("fa-caret-right");
return false;
});
//隐藏子节点
$(document).on("collapse", ".btn-node-sub", function () {
if ($("i", this).length > 0) {
$("a[data-pid='" + $(this).data("id") + "']").trigger("collapse");
}
$("i", this).removeClass("fa-caret-down").addClass("fa-caret-right");
$(this).data("shown", false);
$(this).closest("tr").toggle(false);
});
//展开隐藏一级
$(document.body).on("click", ".btn-toggle", function (e) {
$("a[data-id][data-pid][data-pid!=0].disabled").closest("tr").hide();
var that = this;
var show = $("i", that).hasClass("fa-chevron-down");
$("i", that).toggleClass("fa-chevron-down", !show).toggleClass("fa-chevron-up", show);
$("a[data-id][data-pid][data-pid!=0]").not('.disabled').closest("tr").toggle(show);
$(".btn-node-sub[data-pid=0]").data("shown", show);
});
//展开隐藏全部
$(document.body).on("click", ".btn-toggle-all", function (e) {
var that = this;
var show = $("i", that).hasClass("fa-plus");
$("i", that).toggleClass("fa-plus", !show).toggleClass("fa-minus", show);
$(".btn-node-sub:not([data-pid=0])").closest("tr").toggle(show);
$(".btn-node-sub").data("shown", show);
$(".btn-node-sub > i").toggleClass("fa-caret-down", show).toggleClass("fa-caret-right", !show);
});
}, },
add: function () { add: function () {
Controller.api.bindevent(); Controller.api.bindevent();
@ -55,6 +100,17 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
Controller.api.bindevent(); Controller.api.bindevent();
}, },
api: { api: {
formatter: {
title: function (value, row, index) {
value = value.toString().replace(/(&|&amp;)nbsp;/g, '&nbsp;');
var caret = row.haschild == 1 || row.ismenu == 1 ? '<i class="fa fa-caret-right"></i>' : '';
value = value.indexOf("&nbsp;") > -1 ? value.replace(/(.*)&nbsp;/, "$1" + caret) : caret + value;
value = !row.ismenu || row.status == 'hidden' ? "<span class='text-muted'>" + value + "</span>" : value;
return '<a href="javascript:;" data-toggle="tooltip" title="' + __('Toggle sub menu') + '" data-id="' + row.id + '" data-pid="' + row.pid + '" class="'
+ (row.haschild == 1 || row.ismenu == 1 ? 'text-primary' : 'disabled') + ' btn-node-sub">' + value + '</a>';
}
},
bindevent: function () { bindevent: function () {
$(document).on('click', "input[name='row[ismenu]']", function () { $(document).on('click', "input[name='row[ismenu]']", function () {
var name = $("input[name='row[name]']"); var name = $("input[name='row[name]']");