From 3036a54042d92e908aad3dc561e16d00c9121747 Mon Sep 17 00:00:00 2001 From: vine_liutk <961510893@qq.com> Date: Tue, 9 Aug 2022 16:42:41 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4=E8=8F=9C=E5=8D=95=E9=80=89?= =?UTF-8?q?=E4=B8=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Layout/Menu.php | 33 ++++++++++++++++++++++++++------- 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/src/Layout/Menu.php b/src/Layout/Menu.php index c069066..9606e6d 100755 --- a/src/Layout/Menu.php +++ b/src/Layout/Menu.php @@ -125,26 +125,45 @@ class Menu if (empty($path)) { $path = request()->path(); } - if (empty($item['children'])) { if (empty($item['uri'])) { return false; } - - return trim($this->getPath($item['uri']), '/') == $path; + $_uri = str_replace('/admin', '', $this->getPath($item['uri'])); + if (empty($_uri) && $path !== 'admin') { + return false; + } + if (strpos($path, '?')) { + $path = substr($path, 0, strpos($path, '?')); + } + if (strpos($_uri, '?')) { + $_uri = substr($_uri, 0, strpos($_uri, '?')); + } + return strpos('/'.$path, $_uri) !== false; } foreach ($item['children'] as $v) { - if ($path == trim($this->getPath($v['uri']), '/')) { - return true; - } + //针对大于2级的菜单 if (! empty($v['children'])) { if ($this->isActive($v, $path)) { return true; } + }else{ + $_uri = str_replace('/admin', '', $this->getPath($v['uri'])); + if (empty($_uri) && $path !== 'admin') { + return false; + } + if (strpos($path, '?')) { + $path = substr($path, 0, strpos($path, '?')); + } + if (strpos($_uri, '?')) { + $_uri = substr($_uri, 0, strpos($_uri, '?')); + } + if (strpos('/'.$path, $_uri) !== false) { + return true; + } } } - return false; }