暂存后台菜单选中问题处理
parent
683b3a5e7e
commit
0ae85a494e
|
|
@ -0,0 +1,54 @@
|
|||
<?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;
|
||||
}
|
||||
}
|
||||
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace App\Providers;
|
||||
|
||||
use App\Models\Admin\Layout\Menu;
|
||||
use App\Services\SettingService;
|
||||
use EasyWeChat\Factory as EasyWeChatFactory;
|
||||
use EasyWeChat\Payment\Application as EasyWeChatPaymentApplication;
|
||||
|
|
@ -24,6 +25,7 @@ class AppServiceProvider extends ServiceProvider
|
|||
$this->registerEasyWeChat();
|
||||
$this->registerRequestRealIp();
|
||||
$this->registerSettings();
|
||||
// $this->registerAdminMenu();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -48,6 +50,11 @@ class AppServiceProvider extends ServiceProvider
|
|||
JsonResource::withoutWrapping();
|
||||
}
|
||||
|
||||
protected function registerAdminMenu()
|
||||
{
|
||||
$this->app->singleton('admin.menu', Menu::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* 注册微信服务
|
||||
*
|
||||
|
|
|
|||
Loading…
Reference in New Issue