6 changed files with 140 additions and 2 deletions
-
6MySQL_change.sql
-
101app/AdminAgent/Controllers/NoticeController.php
-
16app/AdminAgent/Repositories/Notice.php
-
1app/AdminAgent/routes.php
-
3app/Http/Controllers/Api/IndexController.php
-
15resources/lang/zh_CN/notice.php
@ -0,0 +1,101 @@ |
|||
<?php |
|||
|
|||
namespace App\AdminAgent\Controllers; |
|||
|
|||
use App\AdminAgent\Repositories\Notice; |
|||
use Dcat\Admin\Admin; |
|||
use Dcat\Admin\Form; |
|||
use Dcat\Admin\Grid; |
|||
use Dcat\Admin\Show; |
|||
use Dcat\Admin\Http\Controllers\AdminController; |
|||
|
|||
class NoticeController extends AdminController |
|||
{ |
|||
/** |
|||
* Make a grid builder. |
|||
* |
|||
* @return Grid |
|||
*/ |
|||
protected function grid() |
|||
{ |
|||
return Grid::make(new Notice(), function (Grid $grid) { |
|||
$grid->model()->where('agent_id', Admin::user()->id) |
|||
->orderBy('sort')->orderBy('id', 'DESC'); |
|||
|
|||
$grid->column('id')->sortable(); |
|||
$grid->column('title'); |
|||
$grid->column('sort')->editable()->width(120); |
|||
$grid->column('created_at'); |
|||
$grid->column('updated_at'); |
|||
|
|||
$grid->filter(function (Grid\Filter $filter) { |
|||
$filter->panel(); |
|||
|
|||
$filter->equal('id')->width(2); |
|||
$filter->like('title')->width(3); |
|||
}); |
|||
}); |
|||
} |
|||
|
|||
/** |
|||
* Make a show builder. |
|||
* |
|||
* @param mixed $id |
|||
* |
|||
* @return Show |
|||
*/ |
|||
protected function detail($id) |
|||
{ |
|||
return Show::make($id, new Notice(), function (Show $show) { |
|||
//不允许查看非自己的数据
|
|||
if ($show->model()->agent_id != Admin::user()->id) { |
|||
Admin::exit('数据不存在'); |
|||
} |
|||
|
|||
$show->field('id'); |
|||
$show->field('title'); |
|||
$show->field('content')->unescape(); |
|||
$show->field('sort'); |
|||
$show->field('created_at'); |
|||
$show->field('updated_at'); |
|||
}); |
|||
} |
|||
|
|||
/** |
|||
* Make a form builder. |
|||
* |
|||
* @return Form |
|||
*/ |
|||
protected function form() |
|||
{ |
|||
return Form::make(new Notice(), function (Form $form) { |
|||
//不允许查看非自己的数据
|
|||
if ($form->isEditing() && $form->model()->agent_id != Admin::user()->id) { |
|||
return $form->response()->error('数据不存在'); |
|||
} |
|||
|
|||
$form->display('id'); |
|||
$form->text('title'); |
|||
$form->editor('content'); |
|||
$form->text('sort')->default(255); |
|||
})->saving(function (Form $form) { |
|||
//不允许修改非自己的数据
|
|||
if ($form->isEditing() && $form->model()->agent_id != Admin::user()->id) { |
|||
return $form->response()->error('数据不存在'); |
|||
} |
|||
|
|||
//特殊字段处理
|
|||
$form->hidden(['agent_id']); |
|||
$form->agent_id = Admin::user()->id; |
|||
$form->sort = $form->sort ?? 255; |
|||
|
|||
//不允许编辑的字段
|
|||
$form->ignore(['id', 'created_at', 'updated_at']); |
|||
})->deleting(function (Form $form) { |
|||
//不允许删除非自己的数据
|
|||
if ($form->model()[0]['agent_id'] != Admin::user()->id) { |
|||
return $form->response()->error('数据不存在'); |
|||
} |
|||
}); |
|||
} |
|||
} |
|||
@ -0,0 +1,16 @@ |
|||
<?php |
|||
|
|||
namespace App\AdminAgent\Repositories; |
|||
|
|||
use App\Models\Notice as Model; |
|||
use Dcat\Admin\Repositories\EloquentRepository; |
|||
|
|||
class Notice extends EloquentRepository |
|||
{ |
|||
/** |
|||
* Model. |
|||
* |
|||
* @var string |
|||
*/ |
|||
protected $eloquentClass = Model::class; |
|||
} |
|||
@ -0,0 +1,15 @@ |
|||
<?php |
|||
return [ |
|||
'labels' => [ |
|||
'Notice' => '系统公告', |
|||
'notice' => '系统公告', |
|||
], |
|||
'fields' => [ |
|||
'agent_id' => '发布者ID', |
|||
'title' => '公告标题', |
|||
'sort' => '排序', |
|||
'content' => '公告内容', |
|||
], |
|||
'options' => [ |
|||
], |
|||
]; |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue