From 372f19fc0caa704d2322c5714b6beb00f7240b23 Mon Sep 17 00:00:00 2001 From: panliang <1163816051@qq.com> Date: Fri, 26 May 2023 23:30:38 +0800 Subject: [PATCH 1/2] region --- app/Admin/Controllers/AdminUserController.php | 2 +- app/Admin/Controllers/CropPlantController.php | 28 +++++++++++-------- .../Controllers/CustomRegionController.php | 26 +++++++++-------- app/Admin/Controllers/RegionController.php | 2 +- lang/zh_CN/region.php | 1 + 5 files changed, 34 insertions(+), 25 deletions(-) diff --git a/app/Admin/Controllers/AdminUserController.php b/app/Admin/Controllers/AdminUserController.php index fda26ea..b017c2b 100644 --- a/app/Admin/Controllers/AdminUserController.php +++ b/app/Admin/Controllers/AdminUserController.php @@ -53,7 +53,7 @@ class AdminUserController extends AdminController amisMake()->TextControl('username', __('admin.username'))->required(), amisMake()->TextControl('name', __('admin.admin_user.name'))->required(), amisMake()->TextControl('password', __('admin.password'))->type('input-password')->required()->validations(['minLength' => 6]), - amisMake()->TextControl('confirm_password', __('admin.confirm_password'))->type('input-password')->validations(['minLength' => 6]), + amisMake()->TextControl('confirm_password', __('admin.confirm_password'))->type('input-password')->required()->validations(['minLength' => 6]), amisMake()->SelectControl('roles', __('admin.admin_user.roles')) ->searchable() ->multiple() diff --git a/app/Admin/Controllers/CropPlantController.php b/app/Admin/Controllers/CropPlantController.php index c9d580a..1f89ba2 100644 --- a/app/Admin/Controllers/CropPlantController.php +++ b/app/Admin/Controllers/CropPlantController.php @@ -44,17 +44,23 @@ class CropPlantController extends AdminController amisMake()->TableColumn()->name('area')->label('收获面积m²'), amisMake()->TableColumn()->name('output')->label('收获产量kg'), amisMake()->TableColumn()->name('harvest_at')->label('收获时间'), - ])->itemActions([ - \amisMake()->DialogAction()->label('编辑')->dialog( - Dialog::make()->title('编辑种植记录')->body($this->harvestEditForm()) - ), - \amisMake()->AjaxAction()->label('删除')->level('link') - ->actionType('ajax') - ->confirmText(__('admin.confirm_delete')) - ->api([ - 'method' => 'delete', - 'url' => admin_url('crop-harvestes/${id}') - ]) + amisMake()->Operation()->label(__('admin.actions'))->buttons([ + \amisMake() + ->DialogAction() + ->label('编辑') + ->level('link') + ->dialog(Dialog::make()->title('编辑种植记录')->body($this->harvestEditForm())), + \amisMake() + ->AjaxAction() + ->label('删除') + ->level('link') + ->actionType('ajax') + ->confirmText(__('admin.confirm_delete')) + ->api([ + 'method' => 'delete', + 'url' => admin_url('crop-harvestes/${id}') + ]) + ]), ]) ]), ]), diff --git a/app/Admin/Controllers/CustomRegionController.php b/app/Admin/Controllers/CustomRegionController.php index 4df28ef..d76ef66 100644 --- a/app/Admin/Controllers/CustomRegionController.php +++ b/app/Admin/Controllers/CustomRegionController.php @@ -108,6 +108,20 @@ class CustomRegionController extends AdminController 1 => ['label' => '种植中','icon' => 'fa fa-warning','color' => '#ff9326'], 2 => ['label' => '已结束','icon' => 'fa fa-check-circle','color' => '#ffb6b3'] ])->label('种植状态'), + amisMake()->Operation()->label(__('admin.actions'))->buttons([ + amisMake() + ->DialogAction() + ->label('编辑') + ->level('link') + ->dialog(Dialog::make()->title('编辑种植记录')->body($this->plantEditForm())), + amisMake()->AjaxAction()->label('删除')->level('link') + ->actionType('ajax') + ->confirmText(__('admin.confirm_delete')) + ->api([ + 'method' => 'delete', + 'url' => admin_url('crop-plants/${id}') + ]) + ]), ]) ->itemAction([ 'type'=>'button', @@ -136,18 +150,6 @@ class CustomRegionController extends AdminController ]) ]) ]) - ->itemActions([ - \amisMake()->DialogAction()->label('编辑')->dialog( - Dialog::make()->title('编辑种植记录')->body($this->plantEditForm()) - ), - \amisMake()->AjaxAction()->label('删除')->level('link') - ->actionType('ajax') - ->confirmText(__('admin.confirm_delete')) - ->api([ - 'method' => 'delete', - 'url' => admin_url('crop-plants/${id}') - ]) - ]) ]) ]), ]) diff --git a/app/Admin/Controllers/RegionController.php b/app/Admin/Controllers/RegionController.php index e2b9e58..dc941d9 100644 --- a/app/Admin/Controllers/RegionController.php +++ b/app/Admin/Controllers/RegionController.php @@ -79,7 +79,7 @@ class RegionController extends AdminController Components::make()->decimalControl('area', '面积m²'), Components::make()->sortControl(), \amisMake()->SwitchControl()->name('is_enable')->value(1)->label('显示'), - \amisMake()->TransferControl()->name('monitorModes')->label('关联监测') + \amisMake()->TransferControl()->name('monitorModes')->label(__('region.monitor')) ->selectMode('chained')->searchable(true) ->joinValues(false)->extractValue(true) ->options($monitorModeType), diff --git a/lang/zh_CN/region.php b/lang/zh_CN/region.php index 58730e7..f4d2ed8 100644 --- a/lang/zh_CN/region.php +++ b/lang/zh_CN/region.php @@ -2,4 +2,5 @@ return [ 'cover' => '封面图', + 'monitor' => '关联监测点位', ]; From 9eca0a82cafee1471c4793e1acec5863c34cc65e Mon Sep 17 00:00:00 2001 From: panliang <1163816051@qq.com> Date: Sat, 27 May 2023 09:57:32 +0800 Subject: [PATCH 2/2] auth --- app/Admin/Controllers/AuthController.php | 67 ++++++++++++++++++++++++ app/Admin/routes.php | 4 ++ lang/zh_CN/admin.php | 2 +- 3 files changed, 72 insertions(+), 1 deletion(-) diff --git a/app/Admin/Controllers/AuthController.php b/app/Admin/Controllers/AuthController.php index 594631f..c8f61a0 100644 --- a/app/Admin/Controllers/AuthController.php +++ b/app/Admin/Controllers/AuthController.php @@ -2,9 +2,76 @@ namespace App\Admin\Controllers; +use Illuminate\Support\Arr; +use Illuminate\Validation\Rule; +use Illuminate\Support\Facades\Hash; use Slowlyo\OwlAdmin\Controllers\AuthController as AdminAuthController; +use Slowlyo\OwlAdmin\Renderers\{Page, Form, TextControl, ImageControl}; class AuthController extends AdminAuthController { + public function userSetting(): \Illuminate\Http\JsonResponse|\Illuminate\Http\Resources\Json\JsonResource + { + $user = $this->user(); + $form = Form::make() + ->title() + ->panelClassName('px-48 m:px-0') + ->mode('horizontal') + ->data(Arr::only($user->toArray(), ['avatar', 'name'])) + ->api('put:' . admin_url('/user_setting')) + // ->persistDataKeys(['avatar', 'name']) + // ->resetAfterSubmit() + ->body([ + ImageControl::make() + ->label(__('admin.admin_user.avatar')) + ->name('avatar') + ->receiver($this->uploadImagePath()), + TextControl::make() + ->label(__('admin.admin_user.name')) + ->name('name') + ->required(), + TextControl::make() + ->type('input-password') + ->label(__('admin.old_password')) + ->name('old_password'), + TextControl::make() + ->type('input-password') + ->label('新密码') + ->name('password') + ->validations(['minLength' => 6]) + ->requiredOn('!!this.old_password'), + TextControl::make() + ->type('input-password') + ->label(__('admin.confirm_password')) + ->name('confirm_password') + ->validations(['minLength' => 6]) + ->requiredOn('!!this.old_password'), + ]); + + return $this->response()->success(Page::make()->body($form)); + } + + public function saveUserSetting(): \Illuminate\Http\JsonResponse|\Illuminate\Http\Resources\Json\JsonResource + { + $request = request(); + $request->validate([ + 'old_password' => ['nullable', 'current_password:sanctum'], + 'password' => Rule::requiredIf($request->filled('old_password')), + 'confirm_password' => [Rule::requiredIf($request->filled('old_password')), 'same:password'], + ], [ + 'password.required' => '新密码必填', + 'confirm_password.required' => '确认密码必填', + 'old_password.current_password' => __('admin.admin_user.old_password_error'), + 'confirm_password.same' => __('admin.admin_user.password_confirmation'), + ]); + $user = $this->user(); + $attributes = $request->only(['avatar', 'name']); + if ($request->filled('old_password')) { + $attributes['password'] + = Hash::make($request->input('password')); + } + $user->update($attributes); + return $this->response()->successMessage(__('admin.action_success')); + } } diff --git a/app/Admin/routes.php b/app/Admin/routes.php index b69e2be..ceb4338 100644 --- a/app/Admin/routes.php +++ b/app/Admin/routes.php @@ -12,6 +12,10 @@ Route::group([ $router->get('/_settings', '\App\Admin\Controllers\IndexController@settings'); $router->resource('system/admin_users', App\Admin\Controllers\AdminUserController::class); + // 用户设置 + $router->get('user_setting', [App\Admin\Controllers\AuthController::class, 'userSetting']); + $router->put('user_setting', [App\Admin\Controllers\AuthController::class, 'saveUserSetting']); + $router->group([ 'prefix' => 'api', ], function (Router $router) { diff --git a/lang/zh_CN/admin.php b/lang/zh_CN/admin.php index 6f7bf78..7b6786b 100644 --- a/lang/zh_CN/admin.php +++ b/lang/zh_CN/admin.php @@ -6,7 +6,7 @@ return [ 'logout' => '退出登录', 'username' => '用户名', 'password' => '密码', - 'old_password' => '旧密码', + 'old_password' => '原密码', 'confirm_password' => '确认密码', 'captcha' => '验证码', 'captcha_error' => '验证码有误',