133 lines
5.0 KiB
PHP
133 lines
5.0 KiB
PHP
<?php
|
|
|
|
namespace App\Admin\Controllers;
|
|
|
|
use Carbon\Carbon;
|
|
use Dcat\Admin\Form;
|
|
use Dcat\Admin\Grid;
|
|
use Dcat\Admin\Show;
|
|
use Dcat\Admin\Admin;
|
|
use App\Models\FriendLink;
|
|
use Dcat\Admin\Http\Controllers\AdminController;
|
|
|
|
class FriendLinkController extends AdminController
|
|
{
|
|
/**
|
|
* Make a grid builder.
|
|
*
|
|
* @return Grid
|
|
*/
|
|
protected function grid()
|
|
{
|
|
return Grid::make(new FriendLink(), function (Grid $grid) {
|
|
// $grid->column('id')->sortable();
|
|
$grid->column('name');
|
|
$grid->column('type')->display(function(){
|
|
return $this->typeLabel();
|
|
});
|
|
// $grid->column('content');
|
|
$grid->column('sort');
|
|
$grid->column('is_recommend')->switch();
|
|
$grid->column('is_show')->switch();
|
|
$grid->column('created_at')->sortable();
|
|
// $grid->column('updated_at')->sortable();
|
|
|
|
$grid->model()->orderBy('sort', 'desc')->orderBy('created_at', 'desc');
|
|
|
|
$grid->showCreateButton(! config('admin.permission.enable') || Admin::user()->can('dcat.admin.friend_links.create'));
|
|
$grid->showQuickEditButton(! config('admin.permission.enable') || Admin::user()->can('dcat.admin.friend_links.edit'));
|
|
$grid->showDeleteButton(! config('admin.permission.enable') || Admin::user()->can('dcat.admin.friend_links.destroy'));
|
|
|
|
$grid->filter(function (Grid\Filter $filter) {
|
|
$filter->like('name')->width(3);
|
|
|
|
});
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Make a form builder.
|
|
*
|
|
* @return Form
|
|
*/
|
|
protected function form()
|
|
{
|
|
return Form::make(new FriendLink(), function (Form $form) {
|
|
$form->display('id');
|
|
$form->text('name');
|
|
$form->radio('type')
|
|
->options(FriendLink::typeMap())
|
|
->default(FriendLink::TYPE_LINK)
|
|
->when(FriendLink::TYPE_LINK, function($form){
|
|
$form->text('content_1', '内容')->customFormat(function () {
|
|
if ($this->model()->type == FriendLink::TYPE_LINK) {
|
|
return $this->model()->content;
|
|
} else {
|
|
return '';
|
|
}
|
|
});
|
|
})
|
|
->when(FriendLink::TYPE_VIDEO, function($form){
|
|
$form->file('content_2', '内容')->chunked()
|
|
->accept('mp4', 'mp4/*')
|
|
->move('friend-link/'.Carbon::now()->toDateString())
|
|
->maxSize(204800)//默认最大200M
|
|
->saveFullUrl()
|
|
->removable(false)
|
|
->autoUpload()->autoSave(false)->customFormat(function () {
|
|
if ($this->model()->type == FriendLink::TYPE_VIDEO) {
|
|
return $this->model()->content;
|
|
} else {
|
|
return '';
|
|
};
|
|
});
|
|
})
|
|
->when(FriendLink::TYPE_ARTICLE, function($form){
|
|
$form->editor('content_3', '内容')->options([
|
|
'plugins' => [
|
|
'image',
|
|
'lists',
|
|
'preview',
|
|
'fullscreen',
|
|
'table',
|
|
],
|
|
'toolbar' => [
|
|
'undo redo | preview fullscreen | styleselect | fontsizeselect bold italic underline strikethrough forecolor backcolor | image blockquote removeformat codesample',
|
|
'alignleft aligncenter alignright alignjustify| indent outdent bullist numlist table subscript superscript | code',
|
|
],
|
|
])->height('300')->customFormat(function () {
|
|
if ($this->model()->type == FriendLink::TYPE_ARTICLE) {
|
|
return $this->model()->content;
|
|
} else {
|
|
return '';
|
|
}
|
|
});
|
|
Admin::style(
|
|
<<<'css'
|
|
.tox.tox-silver-sink.tox-tinymce-aux{
|
|
z-index:99999999;
|
|
}
|
|
css
|
|
);
|
|
});
|
|
$form->hidden('content');
|
|
|
|
$form->number('sort');
|
|
$form->switch('is_recommend');
|
|
$form->switch('is_show');
|
|
|
|
$form->saving(function ($form) {
|
|
$content = 'content_'.$form->type;
|
|
$form->content = $form->$content;
|
|
|
|
$form->deleteInput('content_1');
|
|
$form->deleteInput('content_2');
|
|
$form->deleteInput('content_3');
|
|
});
|
|
|
|
$form->display('created_at');
|
|
$form->display('updated_at');
|
|
});
|
|
}
|
|
}
|