From 00c0fa5054ec00e32f11e593b067ff7e7714b6a8 Mon Sep 17 00:00:00 2001 From: panliang <1163816051@qq.com> Date: Tue, 27 May 2025 15:47:14 +0800 Subject: [PATCH] =?UTF-8?q?tudo=20=E5=9B=BE=E7=89=87=E5=BA=93=E9=80=89?= =?UTF-8?q?=E6=8B=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 19 +++++++++++++++++++ app/Admin/Components.php | 13 ++++++++++++- app/Admin/Controllers/UserController.php | 19 ++++++++++++++++++- 3 files changed, 49 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 59101af..7f1e93e 100644 --- a/README.md +++ b/README.md @@ -76,6 +76,25 @@ public function update($primaryKey, $data) } ``` +### 图片上传(图片库选择) + +```php +amis()->ImageControl()->name('avatar')->label(__('users.avatar'))->id('user_avatar'); +amis()->DialogAction()->label("选择图片库")->dialog( + amis()->Dialog()->title('图片库')->body( + amis()->ListControl()->name('_library_images')->options([ + ['value' => 'xxx.png', 'image' => 'xxx.png'], + ]) + )->onEvent([ + 'confirm' => [ + 'actions' => [ + ['actionType' => 'setValue', 'componentId' => 'user_avatar', 'args' => ['value' => '${_library_images}']], + ] + ] + ]) +); +``` + ## TODO - 表单验证: 服务端返回 `errors` 错误信息, 未在输入框上显示, 示例文件: `app\Services\UserService.php`, [组件文档](https://aisuda.bce.baidu.com/amis/zh-CN/components/form/formitem#%E6%9C%8D%E5%8A%A1%E7%AB%AF%E6%A0%A1%E9%AA%8C) diff --git a/app/Admin/Components.php b/app/Admin/Components.php index 0517ee9..86d153a 100644 --- a/app/Admin/Components.php +++ b/app/Admin/Components.php @@ -16,6 +16,17 @@ class Components public function keywordTreeSelectControl($params = []) { $url = amis()->BaseApi()->url(admin_url('api/keywords/tree-list'))->data($params); - return amis()->TreeSelectControl()->source($url)->labelField('name')->valueField('id'); + return amis()->TreeSelectControl()->source($url)->labelField('name')->valueField('id')->showIcon(false); + } + + /** + * 字典表-下拉框 + * + * @param array $params 查询参数 + */ + public function keywordSelectControl($params = []) + { + $url = amis()->BaseApi()->url(admin_url('api/keywords/tree-list'))->data($params); + return amis()->SelectControl()->source($url)->labelField('name')->valueField('id')->showIcon(false); } } diff --git a/app/Admin/Controllers/UserController.php b/app/Admin/Controllers/UserController.php index 2ae7edb..666009c 100644 --- a/app/Admin/Controllers/UserController.php +++ b/app/Admin/Controllers/UserController.php @@ -52,7 +52,24 @@ class UserController extends AdminController public function form() { return $this->baseForm()->mode('horizontal')->body([ - amis()->ImageControl()->name('avatar')->label(__('users.avatar')), + amis()->GroupControl()->body([ + amis()->ImageControl()->name('avatar')->label(__('users.avatar'))->id('user_avatar'), + // amis()->DialogAction()->label("选择图片库")->dialog( + // amis()->Dialog()->title('图片库')->body( + // amis()->ListControl()->name('_library_images')->options([ + // ['value' => 'http://local.owl-admin-starter.host/storage/images/8U1JI1aJv7ltL8wTywPwxcApRVJOKdDRZi4s0jtd.jpg', 'image' => 'http://local.owl-admin-starter.host/storage/images/8U1JI1aJv7ltL8wTywPwxcApRVJOKdDRZi4s0jtd.jpg'], + // ['value' => 'http://local.owl-admin-starter.host/storage/images/eA5fHnnWYMkgot1Xcj5Erfbq3uPgayLzgBzaNVdw.jpg', 'image' => 'http://local.owl-admin-starter.host/storage/images/eA5fHnnWYMkgot1Xcj5Erfbq3uPgayLzgBzaNVdw.jpg'], + // ['value' => 'http://local.owl-admin-starter.host/admin-assets/default-avatar.png', 'image' => 'http://local.owl-admin-starter.host/admin-assets/default-avatar.png'] + // ]) + // )->onEvent([ + // 'confirm' => [ + // 'actions' => [ + // ['actionType' => 'setValue', 'componentId' => 'user_avatar', 'args' => ['value' => '${_library_images}']], + // ] + // ] + // ]) + // ), + ]), amis()->TextControl()->name('phone')->label(__('users.phone'))->required(), amis()->TextControl()->name('name')->label(__('users.name')), ]);