6
0
Fork 0
jiqu-library-server/app/Models/Admin/Layout/Menu.php

55 lines
1.5 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;
}
// return trim($this->getPath($item['uri']), '/') == $path;
// dd($path, trim($this->getPath($item['uri']), '/admin'), strpos($path, trim($this->getPath($item['uri']), '/admin')));
$_uri = trim($this->getPath($item['uri']), '/admin');
if (empty($_uri) && $path!=='admin') {
return false;
}
return strpos($path, $_uri) !== false;
}
foreach ($item['children'] as $v) {
// $_uri = trim($this->getPath($item['uri']), '/admin');
// if (empty($_uri) && $path!=='admin') {
// return false;
// }
// if (strpos($path, $_uri) !== false) {
// return true;
// }
dd($v, empty($v['children']));
if (! empty($v['children'])) {
dd($v, $path);
if ($this->isActive($v, $path)) {
return true;
}
}
}
return false;
}
}