123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259 |
- <?php
- namespace App\Admin\Controllers\System;
- use App\Http\Controllers\Controller;
- use App\Models\Navigation;
- use App\Models\NavigationCategory;
- use App\Models\Page;
- use Encore\Admin\Controllers\HasResourceActions;
- use Encore\Admin\Facades\Admin;
- use Encore\Admin\Form;
- use Encore\Admin\Grid;
- use Encore\Admin\Layout\Content;
- use Encore\Admin\Show;
- use Illuminate\Support\Facades\Cache;
- class NavigationController extends Controller
- {
- use HasResourceActions;
- /**
- * Index interface.
- *
- * @param Content $content
- * @return Content
- */
- public function index(Content $content)
- {
- return $content
- ->header('导航列表')
- ->description('')
- ->body($this->grid());
- }
- /**
- * Show interface.
- *
- * @param mixed $id
- * @param Content $content
- * @return Content
- */
- public function show($id, Content $content)
- {
- return $content
- ->header('导航列表')
- ->description('详细')
- ->body($this->detail($id));
- }
- /**
- * Edit interface.
- *
- * @param mixed $id
- * @param Content $content
- * @return Content
- */
- public function edit($id, Content $content)
- {
- return $content
- ->header('导航列表')
- ->description('编辑')
- ->body($this->editForm($id)->edit($id));
- }
- /**
- * Create interface.
- *
- * @param Content $content
- * @return Content
- */
- public function create(Content $content)
- {
- return $content
- ->header('导航列表')
- ->description('创建')
- ->body($this->createForm());
- }
- /**
- * Make a grid builder.
- *
- * @return Grid
- */
- protected function grid()
- {
- $grid = new Grid(new Navigation);
- $grid->id('ID');
- $grid->alias('分类名称')->width(200);
- $grid->urltype('类型')->display(function ($urltype) {
- return $urltype ? '系统内' : '系统外';
- });
- $grid->display('是否显示')->display(function ($urltype) {
- return $urltype ? "<i class='fa fa-check' style='color:green'></i>" : "<i class='fa fa-close' style='color:red'></i>";
- });
- $grid->title('栏目名称')->width(200);
- $grid->target('打开方式')->display(function ($target) {
- if ($target=='_self') {
- return '原窗口';
- } else {
- return '新窗口';
- }
- });
- $grid->created_at('添加时间');
- $grid->updated_at('创建时间');
- $grid->actions(function ($actions) use ($grid) {
- if (Admin::user()->can('system_nav_list_edit')) {
- $actions->disableEdit(false);
- }
- if (Admin::user()->can('system_nav_list_delete')) {
- $actions->disableDelete(false);
- }
- });
- if (Admin::user()->can('system_nav_list_delete')) {
- $grid->tools(function ($tools) {
- $tools->batch(function ($batch) {
- $batch->disableDelete(false);
- });
- });
- $grid->disableRowSelector(false);
- }
- if (Admin::user()->can('system_nav_list_create')) {
- $grid->disableCreateButton(false);
- }
- return $grid;
- }
- /**
- * Make a show builder.
- *
- * @param mixed $id
- * @return Show
- */
- protected function detail($id)
- {
- $show = new Show(Navigation::findOrFail($id));
- $show->id('ID');
- $show->alias('分类名称');
- $show->urltype('类型')->as(function ($urltype) {
- return $urltype ? '系统内' : '系统外';
- });
- $show->display('是否显示')->as(function ($urltype) {
- return $urltype ? '显示' : '隐藏';
- });
- $show->title('栏目名称');
- $show->target('打开方式')->as(function ($target) {
- if ($target=='_self') {
- return '原窗口';
- } else {
- return '新窗口';
- }
- });
- $show->created_at('添加时间');
- $show->updated_at('创建时间');
- return $show;
- }
- /**
- * Make a form builder.
- *
- * @return Form
- */
- protected function editForm($id)
- {
- $form = new Form(new Navigation);
- $form->radio('urltype', '类型')->options([1 => '系统内',0=>'系统外'])->default(1);
- $form->select('alias', '分类名称')->options(
- NavigationCategory::List()->pluck('name', 'alias')
- )->rules([
- 'required',
- ])->setWidth(3)->setMustMark();
- $form->radio('display', '是否显示')->options([1=>'显示',0=>'隐藏'])->default(1);
- $form->display('title', '栏目名称')->setWidth(3);
- $form->color('color', '显示颜色')->setWidth(3);
-
- $form->select('pagealias', '页面名称')->options(
- Page::List()->pluck('pname', 'alias')
- )->load('tag', route('admin.sys.getTag'))->rules([
- 'required',
- ])->setWidth(3)->setMustMark();
- $form->text('tag', '导航关联')->setWidth(3);
- $form->text('url', '链接地址(路由)')->setWidth(3);
- $form->radio('target', '打开方式')->options(['_self'=>'原窗口','_blank'=>'新窗口'])->default('_self');
- $form->number('order', '排序')->min(0)->default(0);
- return $form;
- }
- protected function createForm()
- {
- $form = new Form(new Navigation);
- $form->radio('urltype', '类型')->options([1 => '系统内',0=>'系统外'])->default(1);
- $form->select('alias', '分类名称')->options(
- NavigationCategory::List()->pluck('name', 'alias')
- )->rules([
- 'required',
- ])->setWidth(3)->setMustMark();
- $form->radio('display', '是否显示')->options([1=>'显示',0=>'隐藏'])->default(1);
- $form->text('title', '栏目名称')->rules([
- 'required',
- ])->setWidth(3)->setMustMark();
- $form->color('color', '显示颜色');
- $form->select('pagealias', '页面名称')->options(
- Page::List()->pluck('pname', 'alias')
- )->load('tag', route('admin.sys.getTag'))->rules([
- 'required',
- ])->setWidth(3)->setMustMark();
- $form->select('tag', '导航关联')->rules([
- 'required',
- ])->setWidth(3)->setMustMark();
- $form->text('url', '链接地址(路由)')->setWidth(3);
- $form->radio('target', '打开方式')->options(['_self'=>'原窗口','_blank'=>'新窗口'])->default('_self');
- $form->number('order', '排序')->min(0)->default(0);
- return $form;
- }
- /**
- * Store a newly created resource in storage.
- *
- * @return mixed
- */
- public function store()
- {
- Cache::forget('nav_list');
- return $this->createForm()->store();
- }
- /**
- * Update the specified resource in storage.
- *
- * @param int $id
- *
- * @return \Illuminate\Http\Response|\Symfony\Component\HttpFoundation\Response
- */
- public function update($id)
- {
- Cache::forget('nav_list');
- return $this->editForm($id)->update($id);
- }
- protected function form()
- {
- $form = new Form(new Navigation);
- $form->display('ID');
- $form->display('添加时间');
- $form->display('更新时间');
- return $form;
- }
- }
|