diff --git a/application/admin/controller/auth/Rule.php b/application/admin/controller/auth/Rule.php index 8ae23cb4..4a9ba5bd 100644 --- a/application/admin/controller/auth/Rule.php +++ b/application/admin/controller/auth/Rule.php @@ -36,7 +36,7 @@ class Rule extends Backend $v['title'] = __($v['title']); } unset($v); - Tree::instance()->init($ruleList); + Tree::instance()->init($ruleList)->icon = ['    ', '    ', '    ']; $this->rulelist = Tree::instance()->getTreeList(Tree::instance()->getTreeArray(0), 'title'); $ruledata = [0 => __('None')]; foreach ($this->rulelist as $k => &$v) { diff --git a/application/admin/controller/user/Rule.php b/application/admin/controller/user/Rule.php index 611d6871..9302dfec 100644 --- a/application/admin/controller/user/Rule.php +++ b/application/admin/controller/user/Rule.php @@ -32,7 +32,7 @@ class Rule extends Backend $v['remark'] = __($v['remark']); } unset($v); - Tree::instance()->init($ruleList); + Tree::instance()->init($ruleList)->icon = ['    ', '    ', '    ']; $this->rulelist = Tree::instance()->getTreeList(Tree::instance()->getTreeArray(0), 'title'); $ruledata = [0 => __('None')]; foreach ($this->rulelist as $k => &$v) { diff --git a/application/admin/lang/zh-cn/user/rule.php b/application/admin/lang/zh-cn/user/rule.php index 0d01117a..35e3a2e5 100644 --- a/application/admin/lang/zh-cn/user/rule.php +++ b/application/admin/lang/zh-cn/user/rule.php @@ -12,5 +12,8 @@ return [ 'Menu tips' => '规则任意,请不可重复,仅做层级显示,无需匹配控制器和方法', 'Node tips' => '模块/控制器/方法名', 'Weigh' => '权重', - 'Status' => '状态' + 'Status' => '状态', + 'Toggle all' => '显示全部', + 'Toggle menu visible' => '点击切换菜单显示', + 'Toggle sub menu' => '点击切换子菜单', ]; diff --git a/application/admin/view/user/rule/index.html b/application/admin/view/user/rule/index.html index 1ecb4ed7..ff57bad2 100644 --- a/application/admin/view/user/rule/index.html +++ b/application/admin/view/user/rule/index.html @@ -14,6 +14,7 @@
  • {:__('Set to hidden')}
  • + {:__('Toggle all')} ', - operate: false, - formatter: Controller.api.formatter.subnode - }, { field: 'operate', title: __('Operate'), @@ -56,10 +50,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'template'], function search: false, commonSearch: false, rowAttributes: function (row, index) { - if (this.totalRows > 500) { - return row.pid == 0 ? {} : {style: "display:none"}; - } - return row.haschild == 1 || row.ismenu == 1 ? {} : {style: "display:none"}; + return row.pid == 0 ? {} : {style: "display:none"}; } }); @@ -104,13 +95,27 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'template'], function //显示隐藏子节点 $(document).on("click", ".btn-node-sub", function (e) { 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); }); + 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); + }); + //批量删除后的回调 $(".toolbar > .btn-del,.toolbar .btn-more~ul>li>a").data("success", function (e) { Fast.api.refreshmenu(); @@ -118,12 +123,11 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'template'], function //展开隐藏一级 $(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 show = $("i", that).hasClass("fa-chevron-down"); - $("i", that).toggleClass("fa-chevron-down", !show); - $("i", that).toggleClass("fa-chevron-up", show); - $("a.btn[data-id][data-pid][data-pid!=0]").not('.disabled').closest("tr").toggle(show); + $("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); }); @@ -131,10 +135,10 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'template'], function $(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); - $("i", that).toggleClass("fa-minus", show); - $(".btn-node-sub.disabled").closest("tr").toggle(show); + $("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 () { @@ -147,17 +151,18 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'template'], function formatter: { title: function (value, row, index) { value = value.toString().replace(/(&|&)nbsp;/g, ' '); - return !row.ismenu || row.status == 'hidden' ? "" + value + "" : value; + var caret = row.haschild == 1 || row.ismenu == 1 ? '' : ''; + value = value.indexOf(" ") > -1 ? value.replace(/(.*) /, "$1" + caret) : caret + value; + + value = !row.ismenu || row.status == 'hidden' ? "" + value + "" : value; + return '' + value + ''; }, name: function (value, row, index) { return !row.ismenu || row.status == 'hidden' ? "" + value + "" : value; }, icon: function (value, row, index) { return ''; - }, - subnode: function (value, row, index) { - return ''; } }, bindevent: function () { diff --git a/public/assets/js/backend/user/rule.js b/public/assets/js/backend/user/rule.js index c485c311..b9fea439 100644 --- a/public/assets/js/backend/user/rule.js +++ b/public/assets/js/backend/user/rule.js @@ -21,18 +21,16 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin url: $.fn.bootstrapTable.defaults.extend.index_url, pk: 'id', sortName: 'weigh', + escape: false, columns: [ [ {checkbox: true}, {field: 'id', title: __('Id')}, {field: 'pid', title: __('Pid'), visible: false}, - {field: 'title', title: __('Title'), align: 'left', formatter:function (value, row, index) { - return value.toString().replace(/(&|&)nbsp;/g, ' '); - } - }, + {field: 'title', title: __('Title'), align: 'left', formatter: Controller.api.formatter.title}, {field: 'name', title: __('Name'), align: 'left'}, {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: 'updatetime', title: __('Updatetime'), formatter: Table.api.formatter.datetime, operate: 'RANGE', addclass: 'datetimerange', sortable: true, visible: false}, {field: 'weigh', title: __('Weigh')}, @@ -43,10 +41,57 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin pagination: false, search: false, commonSearch: false, + rowAttributes: function (row, index) { + return row.pid == 0 ? {} : {style: "display:none"}; + } }); // 为表格绑定事件 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 () { Controller.api.bindevent(); @@ -55,6 +100,17 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin Controller.api.bindevent(); }, api: { + formatter: { + title: function (value, row, index) { + value = value.toString().replace(/(&|&)nbsp;/g, ' '); + var caret = row.haschild == 1 || row.ismenu == 1 ? '' : ''; + value = value.indexOf(" ") > -1 ? value.replace(/(.*) /, "$1" + caret) : caret + value; + + value = !row.ismenu || row.status == 'hidden' ? "" + value + "" : value; + return '' + value + ''; + } + }, bindevent: function () { $(document).on('click', "input[name='row[ismenu]']", function () { var name = $("input[name='row[name]']");