From 3578b343f8b410ec2bd73e8056741416c8bcf08e Mon Sep 17 00:00:00 2001 From: LiuPengFeiCode <525833532@qq.com> Date: Sun, 9 Feb 2025 12:14:43 +0800 Subject: [PATCH] =?UTF-8?q?=E7=B3=BB=E7=BB=9F=E8=8F=9C=E5=8D=95=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E9=A1=B6=E7=BA=A7=E8=8F=9C=E5=8D=95=E9=80=89=E9=A1=B9?= =?UTF-8?q?=E5=8D=A1=EF=BC=8C=E6=96=B9=E4=BE=BF=E5=A4=8D=E6=9D=82=E8=8F=9C?= =?UTF-8?q?=E5=8D=95=E7=AE=A1=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/admin/controller/Menu.php | 15 +++++++++++++++ app/admin/view/menu/index.html | 11 ++++++++--- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/app/admin/controller/Menu.php b/app/admin/controller/Menu.php index 90ba46cf0..549e62fa2 100644 --- a/app/admin/controller/Menu.php +++ b/app/admin/controller/Menu.php @@ -44,6 +44,13 @@ class Menu extends Controller { $this->title = '系统菜单管理'; $this->type = $this->get['type'] ?? 'index'; + + // 获取顶级菜单ID + $this->pid = $this->get['pid'] ?? ''; + + // 查询顶级菜单集合 + $this->menup_list = SystemMenu::mk()->where(['pid' => 0, 'status' => 1])->order('sort desc,id asc')->column('id,pid,title', 'id'); + SystemMenu::mQuery()->layTable(); } @@ -66,6 +73,14 @@ class Menu extends Controller } // 菜单数据树数据变平化 $data = DataExtend::arr2table($data); + + // 过滤非当前顶级菜单的下级菜单,并重新索引数组 + if ($this->type === 'index' && $this->pid) { + $data = array_values(array_filter($data, function ($item) { + return strpos($item['spp'], ",{$this->pid},") !== false; + })); + } + foreach ($data as &$vo) { if ($vo['url'] !== '#' && !preg_match('/^(https?:)?(\/\/|\\\\)/i', $vo['url'])) { $vo['url'] = trim(url($vo['url']) . ($vo['params'] ? "?{$vo['params']}" : ''), '\\/'); diff --git a/app/admin/view/menu/index.html b/app/admin/view/menu/index.html index 787ffc66b..c191f05b0 100644 --- a/app/admin/view/menu/index.html +++ b/app/admin/view/menu/index.html @@ -17,12 +17,17 @@ {block name="content"} <div class="layui-tab layui-tab-card"> <ul class="layui-tab-title"> - {foreach ['index'=>lang('系统菜单'),'recycle'=>lang('回 收 站')] as $k=>$v} - {if isset($type) and $type eq $k} + {foreach ['index'=>lang('全部菜单'),'recycle'=>lang('回 收 站')] as $k=>$v} + {if isset($type) and $type eq $k and isset($pid) and $pid == ''} <li class="layui-this" data-open="{:url('index')}?type={$k}">{$v}</li> {else} <li data-open="{:url('index')}?type={$k}">{$v}</li> {/if}{/foreach} + + <!--顶级菜单--> + <!--{foreach $menup_list as $k=>$v}--> + <li data-open="{:url('index')}?type=index&pid={$v.id}" {if isset($pid) and $pid eq $v.id}class="layui-this"{/if} >{$v.title}</li> + <!--{/foreach}--> </ul> <div class="layui-tab-content"> <table id="MenuTable" data-url="{:request()->url()}" data-target-search="form.form-search"></table> @@ -34,7 +39,7 @@ $('#MenuTable').layTable({ even: true, height: 'full', page: false, sort: {field: 'sort desc,id', type: 'asc'}, - where: {type: '{$type|default="index"}'}, + where: {type: '{$type|default="index"}', pid: '{$pid|default=""}'}, filter: function (items) { var type = this.where.type; return items.filter(function (item) {