继承dcat用户权限菜单管理重构判断
parent
ad2dcafcce
commit
e0084c5d77
|
|
@ -0,0 +1,22 @@
|
|||
<?php
|
||||
|
||||
namespace App\Admin\Controllers;
|
||||
|
||||
use Dcat\Admin\Admin;
|
||||
use Dcat\Admin\Http\Controllers\UserController;
|
||||
|
||||
class AdministratorController extends UserController
|
||||
{
|
||||
public function grid()
|
||||
{
|
||||
$grid = parent::grid();
|
||||
/** 操作 **/
|
||||
//新增
|
||||
if (Admin::user()->can('dcat.admin.administrator.create')) {
|
||||
$grid->disableCreateButton(false);
|
||||
$grid->enableDialogCreate();
|
||||
}
|
||||
// $grid->
|
||||
return $grid;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,100 @@
|
|||
<?php
|
||||
|
||||
namespace App\Admin\Controllers;
|
||||
|
||||
use Dcat\Admin\Admin;
|
||||
use Dcat\Admin\Http\Actions\Menu\Show;
|
||||
use Dcat\Admin\Http\Controllers\MenuController as BaseController;
|
||||
use Dcat\Admin\Layout\Column;
|
||||
use Dcat\Admin\Layout\Content;
|
||||
use Dcat\Admin\Layout\Row;
|
||||
use Dcat\Admin\Tree;
|
||||
use Dcat\Admin\Widgets\Box;
|
||||
use Dcat\Admin\Widgets\Form as WidgetForm;
|
||||
|
||||
class MenuController extends BaseController
|
||||
{
|
||||
public function index(Content $content)
|
||||
{
|
||||
return $content
|
||||
->title($this->title())
|
||||
->description(trans('admin.list'))
|
||||
->body(function (Row $row) {
|
||||
$row->column(7, $this->treeView()->render());
|
||||
if (Admin::user()->can('dcat.admin.menus.create')) {
|
||||
$row->column(5, function (Column $column) {
|
||||
$form = new WidgetForm();
|
||||
$form->action(admin_url('auth/menu'));
|
||||
|
||||
$menuModel = config('admin.database.menu_model');
|
||||
$permissionModel = config('admin.database.permissions_model');
|
||||
$roleModel = config('admin.database.roles_model');
|
||||
|
||||
$form->select('parent_id', trans('admin.parent_id'))->options($menuModel::selectOptions());
|
||||
$form->text('title', trans('admin.title'))->required();
|
||||
$form->icon('icon', trans('admin.icon'))->help($this->iconHelp());
|
||||
$form->text('uri', trans('admin.uri'));
|
||||
|
||||
if ($menuModel::withRole()) {
|
||||
$form->multipleSelect('roles', trans('admin.roles'))->options($roleModel::all()->pluck('name', 'id'));
|
||||
}
|
||||
if ($menuModel::withPermission()) {
|
||||
$form->tree('permissions', trans('admin.permission'))
|
||||
->expand(false)
|
||||
->treeState(false)
|
||||
->nodes((new $permissionModel())->allNodes());
|
||||
}
|
||||
|
||||
$form->width(9, 2);
|
||||
|
||||
$column->append(Box::make(trans('admin.new'), $form));
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Dcat\Admin\Tree
|
||||
*/
|
||||
protected function treeView()
|
||||
{
|
||||
$menuModel = config('admin.database.menu_model');
|
||||
|
||||
return new Tree(new $menuModel(), function (Tree $tree) {
|
||||
$tree->disableCreateButton();
|
||||
$tree->disableQuickCreateButton();
|
||||
$tree->disableEditButton();
|
||||
$tree->maxDepth(3);
|
||||
if (Admin::user()->cannot('dcat.admin.menus.edit')) {
|
||||
$tree->disableSaveButton();
|
||||
}
|
||||
|
||||
$tree->actions(function (Tree\Actions $actions) {
|
||||
if ($actions->getRow()->extension) {
|
||||
$actions->disableDelete();
|
||||
} else {
|
||||
$actions->disableDelete(Admin::user()->cannot('dcat.admin.menus.destroy'));
|
||||
}
|
||||
$actions->disableEdit(Admin::user()->cannot('dcat.admin.menus.edit'));
|
||||
|
||||
$actions->prepend(new Show());
|
||||
});
|
||||
|
||||
$tree->branch(function ($branch) {
|
||||
$payload = "<i class='fa {$branch['icon']}'></i> <strong>{$branch['title']}</strong>";
|
||||
|
||||
if (! isset($branch['children'])) {
|
||||
if (url()->isValidUrl($branch['uri'])) {
|
||||
$uri = $branch['uri'];
|
||||
} else {
|
||||
$uri = admin_base_path($branch['uri']);
|
||||
}
|
||||
|
||||
$payload .= " <a href=\"$uri\" class=\"dd-nodrag\">$uri</a>";
|
||||
}
|
||||
|
||||
return $payload;
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,73 @@
|
|||
<?php
|
||||
|
||||
namespace App\Admin\Controllers;
|
||||
|
||||
use Dcat\Admin\Admin;
|
||||
use Dcat\Admin\Http\Controllers\PermissionController as BaseController;
|
||||
use Dcat\Admin\Tree;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class PermissionController extends BaseController
|
||||
{
|
||||
protected function treeView()
|
||||
{
|
||||
$model = config('admin.database.permissions_model');
|
||||
|
||||
return new Tree(new $model(), function (Tree $tree) {
|
||||
$tree->disableCreateButton();
|
||||
$tree->disableEditButton();
|
||||
|
||||
if (Admin::user()->cannot('dcat.admin.permissions.create')) {
|
||||
$tree->disableQuickCreateButton();
|
||||
}
|
||||
$tree->actions(function (Tree\Actions $actions) {
|
||||
$actions->disableEdit(Admin::user()->cannot('dcat.admin.permissions.edit'));
|
||||
$actions->disableDelete(Admin::user()->cannot('dcat.admin.permissions.destroy'));
|
||||
});
|
||||
$tree->branch(function ($branch) {
|
||||
$branchName = htmlspecialchars($branch['name']);
|
||||
$branchSlug = htmlspecialchars($branch['slug']);
|
||||
$payload = "<div class='pull-left' style='min-width:310px'><b>{$branchName}</b> [<span class='text-primary'>{$branchSlug}</span>]";
|
||||
|
||||
$path = array_filter($branch['http_path']);
|
||||
|
||||
if (! $path) {
|
||||
return $payload.'</div> ';
|
||||
}
|
||||
|
||||
$max = 3;
|
||||
if (count($path) > $max) {
|
||||
$path = array_slice($path, 0, $max);
|
||||
array_push($path, '...');
|
||||
}
|
||||
|
||||
$method = $branch['http_method'] ?: [];
|
||||
|
||||
$path = collect($path)->map(function ($path) use (&$method) {
|
||||
if (Str::contains($path, ':')) {
|
||||
[$me, $path] = explode(':', $path);
|
||||
|
||||
$method = array_merge($method, explode(',', $me));
|
||||
}
|
||||
if ($path !== '...' && ! empty(config('admin.route.prefix')) && ! Str::contains($path, '.')) {
|
||||
$path = trim(admin_base_path($path), '/');
|
||||
}
|
||||
|
||||
$color = Admin::color()->primaryDarker();
|
||||
|
||||
return "<code style='color:{$color}'>$path</code>";
|
||||
})->implode(' ');
|
||||
|
||||
$method = collect($method ?: ['ANY'])->unique()->map(function ($name) {
|
||||
return strtoupper($name);
|
||||
})->map(function ($name) {
|
||||
return "<span class='label bg-primary'>{$name}</span>";
|
||||
})->implode(' ').' ';
|
||||
|
||||
$payload .= "</div> $method<a class=\"dd-nodrag\">$path</a>";
|
||||
|
||||
return $payload;
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
<?php
|
||||
|
||||
namespace App\Admin\Controllers;
|
||||
|
||||
use Dcat\Admin\Admin;
|
||||
use Dcat\Admin\Http\Controllers\RoleController as BaseController;
|
||||
|
||||
class RoleController extends BaseController
|
||||
{
|
||||
public function grid()
|
||||
{
|
||||
$grid = parent::grid();
|
||||
/** 操作 **/
|
||||
//新增
|
||||
if (Admin::user()->can('dcat.admin.roles.create')) {
|
||||
$grid->disableCreateButton(false);
|
||||
$grid->enableDialogCreate();
|
||||
}
|
||||
// $grid->
|
||||
return $grid;
|
||||
}
|
||||
}
|
||||
|
|
@ -12,10 +12,16 @@ Route::group([
|
|||
'middleware' => config('admin.route.middleware'),
|
||||
], function (Router $router) {
|
||||
$router->get('/', 'HomeController@index');
|
||||
$router->resource('adminstrators', 'AdministratorController');
|
||||
$router->resource('roles', 'RoleController');
|
||||
$router->resource('permissions', 'RoleController');
|
||||
$router->resource('menus', 'MenuController');
|
||||
|
||||
$router->resource('ad-addresses', 'AdAddressController')->only([
|
||||
'index', 'create', 'store', 'edit', 'update', 'destroy',
|
||||
])->names('ad_addresses');
|
||||
|
||||
$router->resource('ads', 'AdController');
|
||||
$router->resource('ads', 'AdController')->only([
|
||||
'index', 'create', 'store', 'edit', 'update', 'destroy',
|
||||
])->names('ads');
|
||||
});
|
||||
|
|
|
|||
|
|
@ -0,0 +1,18 @@
|
|||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use Illuminate\Database\Seeder;
|
||||
|
||||
class AdminMenuSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function run()
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
|
|
@ -28,11 +28,11 @@ class AdminPermissionSeeder extends Seeder
|
|||
// ],
|
||||
// ],
|
||||
// ],
|
||||
'auth-management'=> [
|
||||
'management'=> [
|
||||
'name' => '系统管理',
|
||||
'curd' => false,
|
||||
'children' => [
|
||||
'users' => [
|
||||
'administrators' => [
|
||||
'name' => '管理员',
|
||||
'curd' => true,
|
||||
],
|
||||
|
|
|
|||
|
|
@ -0,0 +1,18 @@
|
|||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use Illuminate\Database\Seeder;
|
||||
|
||||
class AdministratorSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function run()
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue