插件修改后台子菜单

This commit is contained in:
Edward Yang 2022-08-04 18:23:44 +08:00
parent 6773546efd
commit b7bd77ba76
2 changed files with 116 additions and 24 deletions

View File

@ -37,41 +37,38 @@ class Sidebar extends Component
$routeName = str_replace($adminName . '.', '', $routeNameWithPrefix); $routeName = str_replace($adminName . '.', '', $routeNameWithPrefix);
if (Str::startsWith($routeName, ['home.'])) { if (Str::startsWith($routeName, ['home.'])) {
$this->addLink('design.index', 'fa fa-tachometer-alt', $this->equalRoute('design.index'), true); $routes = $this->getHomeSubRoutes();
$this->addLink('plugins.index', 'fa fa-tachometer-alt', $this->equalRoute('plugins.index')); foreach ($routes as $route) {
$this->addLink('categories.index', 'fa fa-tachometer-alt', $this->equalRoute('categories.index')); $this->addLink($route['route'], $route['icon'] ?? '', $this->equalRoute($route['route']), (bool)($route['blank'] ?? false));
$this->addLink('brands.index', 'fa fa-tachometer-alt', $this->equalRoute('brands.index')); }
$this->addLink('tax_rates.index', 'fa fa-tachometer-alt', $this->equalRoute('tax_rates.index'));
$this->addLink('tax_rates.index', 'fa fa-tachometer-alt', $this->equalRoute('tax_rates.index'));
$this->addLink('currencies.index', 'fa fa-tachometer-alt', $this->equalRoute('currencies.index'));
} }
if (Str::startsWith($routeName, ['products.', 'categories.', 'brands.'])) { if (Str::startsWith($routeName, ['products.', 'categories.', 'brands.'])) {
$this->addLink('categories.index', 'fa fa-tachometer-alt', $this->equalRoute('categories.index')); $routes = $this->getProductSubRoutes();
$this->addLink('products.index', 'fa fa-tachometer-alt', $this->equalRoute('products.index')); foreach ($routes as $route) {
$this->addLink('brands.index', 'fa fa-tachometer-alt', $this->equalRoute('brands.index')); $this->addLink($route['route'], $route['icon'] ?? '', $this->equalRoute($route['route']), (bool)($route['blank'] ?? false));
$this->addLink('products.trashed', 'fa fa-tachometer-alt', $this->equalRoute('products.trashed')); }
} }
if (Str::startsWith($routeName, ['customers.', 'customer_groups.'])) { if (Str::startsWith($routeName, ['customers.', 'customer_groups.'])) {
$this->addLink('customers.index', 'fa fa-tachometer-alt', $this->equalRoute('customers.index')); $routes = $this->getCustomerSubRoutes();
$this->addLink('customer_groups.index', 'fa fa-tachometer-alt', $this->equalRoute('customer_groups.index')); foreach ($routes as $route) {
$this->addLink($route['route'], $route['icon'] ?? '', $this->equalRoute($route['route']), (bool)($route['blank'] ?? false));
}
} }
if (Str::startsWith($routeName, ['orders.', 'rmas.'])) { if (Str::startsWith($routeName, ['orders.', 'rmas.'])) {
$this->addLink('orders.index', 'fa fa-tachometer-alt', $this->equalRoute('orders.index')); $routes = $this->getOrderSubRoutes();
$this->addLink('rmas.index', 'fa fa-tachometer-alt', $this->equalRoute('rmas.index')); foreach ($routes as $route) {
$this->addLink($route['route'], $route['icon'] ?? '', $this->equalRoute($route['route']), (bool)($route['blank'] ?? false));
}
} }
if (Str::startsWith($routeName, ['settings.', 'admin_users.', 'admin_roles.', 'plugins.', 'tax_classes', 'tax_rates', 'regions', 'currencies'])) { if (Str::startsWith($routeName, ['settings.', 'admin_users.', 'admin_roles.', 'plugins.', 'tax_classes', 'tax_rates', 'regions', 'currencies'])) {
$this->addLink('settings.index', 'fa fa-tachometer-alt', $this->equalRoute('settings.index')); $routes = $this->getSettingSubRoutes();
$this->addLink('admin_users.index', 'fa fa-tachometer-alt', $this->equalRoute('admin_users.index')); foreach ($routes as $route) {
$this->addLink('plugins.index', 'fa fa-tachometer-alt', $this->equalRoute('plugins.index')); $this->addLink($route['route'], $route['icon'] ?? '', $this->equalRoute($route['route']), (bool)($route['blank'] ?? false));
$this->addLink('regions.index', 'fa fa-tachometer-alt', $this->equalRoute('regions.index')); }
$this->addLink('tax_rates.index', 'fa fa-tachometer-alt', $this->equalRoute('tax_rates.index'));
$this->addLink('tax_classes.index', 'fa fa-tachometer-alt', $this->equalRoute('tax_classes.index'));
$this->addLink('currencies.index', 'fa fa-tachometer-alt', $this->equalRoute('currencies.index'));
$this->addLink('design.index', 'fa fa-tachometer-alt', $this->equalRoute('design.index'), true);
} }
return view('admin::components.sidebar'); return view('admin::components.sidebar');
@ -105,6 +102,85 @@ class Sidebar extends Component
} }
/**
* 获取首页子页面路由
*/
private function getHomeSubRoutes()
{
$routes = [
['route' => 'design.index', 'icon' => 'fa fa-tachometer-alt', 'blank' => 1],
['route' => 'plugins.index', 'icon' => 'fa fa-tachometer-alt'],
['route' => 'categories.index', 'icon' => 'fa fa-tachometer-alt'],
['route' => 'brands.index', 'icon' => 'fa fa-tachometer-alt'],
['route' => 'tax_rates.index', 'icon' => 'fa fa-tachometer-alt'],
['route' => 'tax_classes.index', 'icon' => 'fa fa-tachometer-alt'],
['route' => 'currencies.index', 'icon' => 'fa fa-tachometer-alt'],
];
return hook_filter('sidebar.home_routes', $routes);
}
/**
* 获取产品子页面路由
*/
private function getProductSubRoutes()
{
$routes = [
['route' => 'categories.index', 'icon' => 'fa fa-tachometer-alt'],
['route' => 'products.index', 'icon' => 'fa fa-tachometer-alt'],
['route' => 'brands.index', 'icon' => 'fa fa-tachometer-alt'],
['route' => 'products.trashed', 'icon' => 'fa fa-tachometer-alt'],
];
return hook_filter('sidebar.product_routes', $routes);
}
/**
* 获取产品子页面路由
*/
private function getCustomerSubRoutes()
{
$routes = [
['route' => 'customers.index', 'icon' => 'fa fa-tachometer-alt'],
['route' => 'customer_groups.index', 'icon' => 'fa fa-tachometer-alt'],
];
return hook_filter('sidebar.customer_routes', $routes);
}
/**
* 获取订单子页面路由
*/
private function getOrderSubRoutes()
{
$routes = [
['route' => 'orders.index', 'icon' => 'fa fa-tachometer-alt'],
['route' => 'rmas.index', 'icon' => 'fa fa-tachometer-alt'],
];
return hook_filter('sidebar.order_routes', $routes);
}
/**
* 获取系统设置子页面路由
* @return mixed
*/
private function getSettingSubRoutes()
{
$routes = [
['route' => 'settings.index', 'icon' => 'fa fa-tachometer-alt'],
['route' => 'admin_users.index', 'icon' => 'fa fa-tachometer-alt'],
['route' => 'plugins.index', 'icon' => 'fa fa-tachometer-alt'],
['route' => 'regions.index', 'icon' => 'fa fa-tachometer-alt'],
['route' => 'tax_rates.index', 'icon' => 'fa fa-tachometer-alt'],
['route' => 'tax_classes.index', 'icon' => 'fa fa-tachometer-alt'],
['route' => 'currencies.index', 'icon' => 'fa fa-tachometer-alt'],
['route' => 'design.index', 'icon' => 'fa fa-tachometer-alt', 'blank' => true],
];
return hook_filter('sidebar.setting_routes', $routes);
}
/** /**
* 是否为当前访问路由 * 是否为当前访问路由
* *

View File

@ -15,12 +15,28 @@ class Bootstrap
{ {
public function boot() public function boot()
{ {
$this->addAdminSideBarMenu();
$this->addHeaderMenu(); $this->addHeaderMenu();
} }
/** /**
* 在网页头部添加二级菜单链接 * 在网站管理后台添加菜单链接
*/
private function addAdminSideBarMenu()
{
add_filter('sidebar.order_routes', function ($data) {
$data[] = [
"route" => "currencies.index",
"icon" => "fa fa-tachometer-alt"
];
return $data;
});
}
/**
* 在前台网页头部添加二级菜单链接
*/ */
private function addHeaderMenu() private function addHeaderMenu()
{ {