63 lines
1.7 KiB
PHP
63 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace App\Models\Admin\Layout;
|
|
|
|
use Dcat\Admin\Layout\Menu as DcatLayoutMenu;
|
|
|
|
class Menu extends DcatLayoutMenu
|
|
{
|
|
/**
|
|
* 判断是否选中.
|
|
*
|
|
* @param array $item
|
|
* @param null|string $path
|
|
* @return bool
|
|
*/
|
|
public function isActive($item, ?string $path = null)
|
|
{
|
|
if (empty($path)) {
|
|
$path = request()->path();
|
|
}
|
|
if (empty($item['children'])) {
|
|
if (empty($item['uri'])) {
|
|
return false;
|
|
}
|
|
$_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) {
|
|
$_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;
|
|
}
|
|
//针对大于2级的菜单
|
|
if (! empty($v['children'])) {
|
|
if ($this->isActive($v, $path)) {
|
|
return true;
|
|
}
|
|
}
|
|
}
|
|
|
|
return false;
|
|
}
|
|
}
|