| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337 | 
							- <?php
 
- namespace App\Admin\Controllers\System;
 
- use App\Admin\Extensions\Tools\DialogTool;
 
- use App\Http\Controllers\Controller;
 
- use App\Models\Page;
 
- use App\Models\Subsite;
 
- 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\Http\Request;
 
- use Illuminate\Validation\Rule;
 
- class PageController 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 Page);
 
-         $grid->id('ID');
 
-         $grid->pname('页面名称')->width(200);
 
-         $grid->alias('别名')->width(200);
 
-         $grid->systemclass('类型')->display(function ($systemclass) {
 
-             return $systemclass ? '系统内置' : '自定义';
 
-         });
 
-         $grid->url('链接')->display(function ($url) {
 
-             return $url ? '伪静态' : '原始链接';
 
-         });
 
-         $grid->caching('缓存')->display(function ($caching) {
 
-             return $caching ? $caching.'分' : '已关闭';
 
-         })->width(150);
 
-         $grid->created_at('添加时间');
 
-         $grid->updated_at('更新时间');
 
-         $grid->actions(function ($actions) use ($grid) {
 
-             if (Admin::user()->can('system_page_edit')) {
 
-                 $actions->disableEdit(false);
 
-             }
 
-             if (Admin::user()->can('system_page_delete')) {
 
-                 $actions->disableDelete(false);
 
-             }
 
-         });
 
-         if (Admin::user()->can('system_page_delete')) {
 
-             $grid->tools(function ($tools) {
 
-                 $tools->batch(function ($batch) {
 
-                     $batch->disableDelete(false);
 
-                 });
 
-             });
 
-             $grid->disableRowSelector(false);
 
-         }
 
-         if (Admin::user()->can('system_page_caching')) {
 
-             $grid->tools(function ($tools) {
 
-                 /*  $tools->batch(function ($batch) {
 
-                       $batch->disableDelete();
 
-                       $batch->add('设置缓存(3天)', new PageCache(4320));
 
-                       $batch->add('设置缓存(7天)', new PageCache(10080));
 
-                       $batch->add('设置缓存(15天)', new PageCache(21600));
 
-                   });*/
 
-                 $form = new \Encore\Admin\Widgets\Form();
 
-                 $form->action(route('admin.sys.caching'));
 
-                 $form->text('caching', '设置缓存')->default(200)->placeholder('单位:分钟');
 
-                 $tools->append(new DialogTool($form, [], '设置缓存'));
 
-             });
 
-         }
 
-         if (Admin::user()->can('system_page_create')) {
 
-             $grid->disableCreateButton(false);
 
-         }
 
-         return $grid;
 
-     }
 
-     /**
 
-      * Make a show builder.
 
-      *
 
-      * @param mixed $id
 
-      * @return Show
 
-      */
 
-     protected function detail($id)
 
-     {
 
-         $show = new Show(Page::findOrFail($id));
 
-         $show->id('ID');
 
-         $show->pname('页面名称');
 
-         $show->alias('别名');
 
-         $show->systemclass('类型')->as(function ($systemclass) {
 
-             return $systemclass ? '系统内置' : '自定义';
 
-         });
 
-         $show->url('链接')->as(function ($url) {
 
-             return $url ? '伪静态' : '原始链接';
 
-         });
 
-         $show->caching('缓存')->as(function ($caching) {
 
-             return $caching ? $caching.'分' : '已关闭';
 
-         });
 
-         $show->created_at('添加时间');
 
-         $show->updated_at('更新时间');
 
-         return $show;
 
-     }
 
-     /**
 
-      * Make a form builder.
 
-      *
 
-      * @return Form
 
-      */
 
-     protected function editForm($id)
 
-     {
 
-         $form = new Form(new Page);
 
-         $model = Page::findOrfail($id);
 
-         $systemclass = isset($model['pagetpye']) ? $model['pagetpye'] : 0;
 
-         if ($systemclass) {
 
-             $form->radio('systemclass', '类型')->options([1 => '系统内置']);
 
-         } else {
 
-             $form->radio('systemclass', '类型')->options([0 => '自定义']);
 
-         }
 
-         $form->display('alias', '别名')->setWidth(3);
 
-         $form->display('pname', '页面名称')->setWidth(3);
 
-         $form->text('tag', '导航关联标记')->rules([
 
-             'required',
 
-         ])->setWidth(3)->setMustMark();
 
-         $form->text('route', '路由')->rules([
 
-             'required',
 
-             Rule::unique('pages')->ignore($id),
 
-         ])->setWidth(3)->setMustMark();
 
-         $form->radio('url', '链接优化')->options([1 => '伪静态'])->default(1);
 
-         $form->radio('pagetpye', '页面类型')->options([1 => '首页或频道首页',2=>'信息列表页',3=>'信息内容页'])->default(1);
 
-         if (config('aix.system.site_safety.subsite.close_subsite')==0) {
 
-             $form->select('subsite_id', '分站信息')->options(
 
-                 Subsite::List()->pluck('sitename', 'id')
 
-             )->setWidth(2);
 
-         }
 
-         $form->text('caching', '缓存时间')->placeholder('默认为分钟(0不设置缓存)')->rules([
 
-             'required',
 
-         ])->setWidth(2)->setMustMark();
 
-         $form->text('title', 'Seo标题')->rules([
 
-             'required',
 
-         ])->setWidth(3)->setMustMark();
 
-         $form->text('keywords', 'Seo关键字')->setWidth(3);
 
-         $form->text('description', 'Seo描述')->setWidth(8);
 
-         return $form;
 
-     }
 
-     protected function createForm()
 
-     {
 
-         $form = new Form(new Page);
 
-         $form->radio('systemclass', '类型')->options([0 => '自定义'])->default(0);
 
-         $form->text('alias', '别名')->rules([
 
-             'required',
 
-             'unique:pages',
 
-         ])->setWidth(3)->setMustMark();
 
-         $form->text('pname', '页面名称')->rules([
 
-             'required',
 
-             'unique:pages',
 
-         ])->setWidth(3)->setMustMark();
 
-         $form->text('tag', '导航关联标记')->rules([
 
-             'required',
 
-         ])->setWidth(3)->setMustMark();
 
-         $form->text('route', '路由')->rules([
 
-             'required',
 
-             'unique:pages',
 
-         ])->setWidth(3)->setMustMark();
 
-         $form->radio('url', '链接优化')->options([1 => '伪静态'])->default(1);
 
-         $form->radio('pagetpye', '页面类型')->options([1 => '首页或频道首页',2=>'信息列表页',3=>'信息内容页'])->default(1);
 
-         if (config('aix.system.site_safety.subsite.close_subsite')==0) {
 
-             $form->select('subsite_id', '分站信息')->options(
 
-                 Subsite::List()->pluck('sitename', 'id')
 
-             )->setWidth(2);
 
-         }
 
-         $form->text('caching', '缓存时间')->placeholder('默认为分钟(0不设置缓存)')->rules([
 
-             'required',
 
-         ])->setWidth(2)->setMustMark();
 
-         $form->text('title', 'Seo标题')->rules([
 
-             'required',
 
-         ])->setWidth(3)->setMustMark();
 
-         $form->text('keywords', 'Seo关键字')->setWidth(3);
 
-         $form->text('description', 'Seo描述')->setWidth(8);
 
-         return $form;
 
-     }
 
-     /**
 
-      * Store a newly created resource in storage.
 
-      *
 
-      * @return mixed
 
-      */
 
-     public function store()
 
-     {
 
-         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)
 
-     {
 
-         return $this->editForm($id)->update($id);
 
-     }
 
-     public function release(Request $request)
 
-     {
 
-         foreach (Page::find($request->get('ids')) as $post) {
 
-             $post->caching = $request->get('action');
 
-             $post->save();
 
-         }
 
-     }
 
-     public function tag(Request $request)
 
-     {
 
-         $q = $request->get('q');
 
-         dd($q);
 
-         return Page::where('alias', $q)->get(['tag']);
 
-     }
 
-     /**
 
-      * 设置缓存.
 
-      */
 
-     public function caching(Request $request)
 
-     {
 
-         $id = $request->post('ids', 0);
 
-         $da = $request->post('caching', '');
 
-         if (!$id) {
 
-             return admin_error("错误", "请勾选设置的列");
 
-         }
 
-         if (!$da) {
 
-             $caching = 0;
 
-         } else {
 
-             $caching = $da;
 
-         }
 
-         $res = Page::whereIn('id', explode(',', $id))->update(['caching'=>$caching]);
 
-         if ($res) {
 
-              return admin_success("成功", "设置成功");
 
-         } else {
 
-              return admin_error("失败", "设置失败");
 
-         }
 
-     }
 
-     /**
 
-      * Make a form builder.
 
-      *
 
-      * @return Form
 
-      */
 
-     protected function form()
 
-     {
 
-         $form = new Form(new Page);
 
-         $form->display('ID');
 
-         $form->display('Created at');
 
-         $form->display('Updated at');
 
-         return $form;
 
-     }
 
-     /**
 
-      * 通过别名获取导航关联标记
 
-      * @param Request $request
 
-      * @return Page;
 
-      */
 
-     public function getTag(Request $request)
 
-     {
 
-         $q = $request->get('q');
 
-         return Page::where('alias', $q)->get(['id','tag as text']);
 
-     }
 
- }
 
 
  |