Skip to content

Commit

Permalink
refactor: 统一页面渲染
Browse files Browse the repository at this point in the history
  • Loading branch information
slowlyo committed Oct 31, 2024
1 parent 8241a7e commit 31869e4
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 35 deletions.
8 changes: 3 additions & 5 deletions src/Controllers/AdminMenuController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
namespace Slowlyo\OwlAdmin\Controllers;

use Slowlyo\OwlAdmin\Admin;
use Slowlyo\OwlAdmin\Renderers\Page;
use Slowlyo\OwlAdmin\Renderers\Form;
use Slowlyo\OwlAdmin\Services\AdminMenuService;
use Slowlyo\OwlAdmin\Traits\IconifyPickerTrait;
use Slowlyo\OwlAdmin\Services\AdminPageService;
Expand All @@ -18,7 +16,7 @@ class AdminMenuController extends AdminController

protected string $serviceName = AdminMenuService::class;

public function list(): Page
public function list()
{
$crud = $this->baseCRUD()
->perPage(999)
Expand Down Expand Up @@ -66,7 +64,7 @@ public function list(): Page
return $this->baseList($crud);
}

public function form(): Form
public function form()
{
return $this->baseForm()->body([
amis()->GroupControl()->body([
Expand Down Expand Up @@ -156,7 +154,7 @@ public function form(): Form
]);
}

public function detail(): Form
public function detail()
{
return $this->baseDetail()->body([]);
}
Expand Down
8 changes: 3 additions & 5 deletions src/Controllers/AdminPermissionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
use Slowlyo\OwlAdmin\Admin;
use Illuminate\Support\Facades\DB;
use Slowlyo\OwlAdmin\Renderers\Tag;
use Slowlyo\OwlAdmin\Renderers\Page;
use Slowlyo\OwlAdmin\Renderers\Form;
use Slowlyo\OwlAdmin\Services\AdminMenuService;
use Slowlyo\OwlAdmin\Services\AdminPermissionService;

Expand All @@ -18,7 +16,7 @@ class AdminPermissionController extends AdminController
{
protected string $serviceName = AdminPermissionService::class;

public function list(): Page
public function list()
{
$autoBtn = '';
if (Admin::config('admin.show_auto_generate_permission_button')) {
Expand Down Expand Up @@ -65,7 +63,7 @@ public function list(): Page
return $this->baseList($crud);
}

public function form(): Form
public function form()
{
return $this->baseForm()->body([
amis()->TextControl('name', admin_trans('admin.admin_permission.name'))->required(),
Expand Down Expand Up @@ -101,7 +99,7 @@ public function form(): Form
]);
}

public function detail(): Form
public function detail()
{
return $this->baseDetail()->body([]);
}
Expand Down
6 changes: 3 additions & 3 deletions src/Controllers/AdminRoleController.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class AdminRoleController extends AdminController
{
protected string $serviceName = AdminRoleService::class;

public function list(): Page
public function list()
{
$crud = $this->baseCRUD()
->headerToolbar([
Expand Down Expand Up @@ -100,7 +100,7 @@ public function savePermissions()
return $this->autoResponse($result, admin_trans('admin.save'));
}

public function form(): Form
public function form()
{
return $this->baseForm()->body([
amis()->TextControl()->label(admin_trans('admin.admin_role.name'))->name('name')->required(),
Expand All @@ -112,7 +112,7 @@ public function form(): Form
]);
}

public function detail(): Form
public function detail()
{
return $this->baseDetail()->body([]);
}
Expand Down
6 changes: 3 additions & 3 deletions src/Controllers/AdminUserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class AdminUserController extends AdminController
{
protected string $serviceName = AdminUserService::class;

public function list(): Page
public function list()
{
$crud = $this->baseCRUD()
->headerToolbar([
Expand Down Expand Up @@ -47,7 +47,7 @@ public function list(): Page
return $this->baseList($crud);
}

public function form(): Form
public function form()
{
return $this->baseForm()->body([
amis()->ImageControl('avatar', admin_trans('admin.admin_user.avatar'))->receiver($this->uploadImagePath()),
Expand All @@ -72,7 +72,7 @@ public function form(): Form
]);
}

public function detail(): Form
public function detail()
{
return $this->baseDetail()->body([]);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Controllers/DevTools/CodeGeneratorController.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function index()
}

return $this->response()->success(
amis()->Page()->css($this->css())->body($this->list())
$this->basePage()->css($this->css())->body($this->list())
);
}

Expand Down
47 changes: 29 additions & 18 deletions src/Traits/ElementTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ protected function backButton()
$path = str_replace(Admin::config('admin.route.prefix'), '', request()->path());
$script = sprintf('window.$owl.hasOwnProperty(\'closeTabByPath\') && window.$owl.closeTabByPath(\'%s\')', $path);

$action = amis()->OtherAction()
$action = amis()
->OtherAction()
->label(admin_trans('admin.back'))
->icon('fa-solid fa-chevron-left')
->level('primary')
Expand All @@ -44,11 +45,13 @@ protected function backButton()
*/
protected function bulkDeleteButton()
{
$action = amis()->DialogAction()
$action = amis()
->DialogAction()
->label(admin_trans('admin.delete'))
->icon('fa-solid fa-trash-can')
->dialog(
amis()->Dialog()
amis()
->Dialog()
->title(admin_trans('admin.delete'))
->className('py-2')
->actions([
Expand Down Expand Up @@ -113,7 +116,8 @@ protected function rowEditButton(bool|string $dialog = false, string $dialogSize
$action = amis()->LinkAction()->link($this->getEditPath());

if ($dialog) {
$form = $this->form(true)
$form = $this
->form(true)
->api($this->getUpdatePath())
->initApi($this->getEditGetDataPath())
->redirect('')
Expand Down Expand Up @@ -152,7 +156,8 @@ protected function rowShowButton(bool|string $dialog = false, string $dialogSize
if ($dialog) {
if ($dialog === 'drawer') {
$action = amis()->DrawerAction()->drawer(
amis()->Drawer()
amis()
->Drawer()
->title($title)
->body($this->detail('$id'))
->size($dialogSize)
Expand All @@ -162,7 +167,8 @@ protected function rowShowButton(bool|string $dialog = false, string $dialogSize
);
} else {
$action = amis()->DialogAction()->dialog(
amis()->Dialog()
amis()
->Dialog()
->title($title)
->body($this->detail('$id'))
->size($dialogSize)
Expand All @@ -187,12 +193,14 @@ protected function rowShowButton(bool|string $dialog = false, string $dialogSize
*/
protected function rowDeleteButton(string $title = '')
{
$action = amis()->DialogAction()
$action = amis()
->DialogAction()
->label($title ?: admin_trans('admin.delete'))
->level('link')
->className('text-danger')
->dialog(
amis()->Dialog()
amis()
->Dialog()
->title()
->className('py-2')
->actions([
Expand Down Expand Up @@ -239,7 +247,8 @@ protected function rowActions(bool|array|string $dialog = false, string $dialogS
*/
protected function baseFilter()
{
$schema = amis()->Form()
$schema = amis()
->Form()
->panelClassName('base-filter')
->title('')
->actions([
Expand Down Expand Up @@ -267,7 +276,8 @@ protected function baseCRUD()
{
$crudId = str_replace('/', '.', request()->path()) . '.crud';

$crud = amis()->CRUDTable()
$crud = amis()
->CRUDTable()
->id($crudId)
->perPage(20)
->alwaysShowPagination()
Expand All @@ -282,7 +292,8 @@ protected function baseCRUD()
'statistics',
// 重写实现 CRUD 自带的页码切换组件, 解决下拉被遮挡的问题
amis()->Form()->wrapWithPanel(false)->body([
amis()->SelectControl('perPage')
amis()
->SelectControl('perPage')
->options(array_map(
fn($i) => ['label' => $i . ' ' . admin_trans('admin.per_page_suffix'), 'value' => $i],
[10, 20, 30, 50, 100, 200]
Expand Down Expand Up @@ -365,7 +376,8 @@ protected function baseForm(bool $back = true)
*/
protected function baseDetail()
{
$schema = amis()->Form()
$schema = amis()
->Form()
->panelClassName('px-48 m:px-0')
->title(' ')
->mode('horizontal')
Expand All @@ -384,10 +396,7 @@ protected function baseDetail()
*/
protected function baseList($crud)
{
return AdminPipeline::handle(
AdminPipeline::PIPE_BASE_LIST,
amis()->Page()->className('m:overflow-auto')->body($crud)
);
return AdminPipeline::handle(AdminPipeline::PIPE_BASE_LIST, $this->basePage()->body($crud));
}

/**
Expand Down Expand Up @@ -431,13 +440,15 @@ protected function exportAction($disableSelectedItem = false)
);
}

$action = amis()->Service()
$action = amis()
->Service()
->id('export-action')
->set('align', 'right')
->set('data', ['showExportLoading' => false])
->body(
amis()->Spinner()->set('showOn', '${showExportLoading}')->overlay()->body(
amis()->DropdownButton()
amis()
->DropdownButton()
->label(admin_trans('admin.export.title'))
->set('icon', 'fa-solid fa-download')
->buttons($buttons)
Expand Down

0 comments on commit 31869e4

Please sign in to comment.