xiaogang 3 年之前
父節點
當前提交
27182b9f67

+ 68 - 0
app/Admin/Actions/Users/SetUserInfo.php

xqd
@@ -0,0 +1,68 @@
+<?php
+
+
+namespace App\Admin\Actions\Users;
+
+use App\Models\UserInfoModel;
+use Dcat\Admin\Admin;
+use Dcat\Admin\Grid\RowAction;
+use Dcat\Admin\Widgets\Modal;
+use Dcat\Admin\Widgets\Table;
+
+class SetUserInfo extends RowAction
+{
+    protected $title = '设置资料';
+
+    protected $model;
+
+    public function __construct(string $model = null)
+    {
+        $this->model = $model;
+    }
+
+    /**
+     * 设置确认弹窗信息,如果返回空值,则不会弹出弹窗
+     *
+     * 允许返回字符串或数组类型
+     *
+     * @return array|string|void
+     */
+    public function confirm()
+    {
+
+    }
+
+    /**
+     * 处理请求
+     *
+     * @param Request $request
+     *
+     * @return \Dcat\Admin\Actions\Response
+     */
+    public function handle(Request $request)
+    {
+        return $this->response()
+            ->success('Processed successfully: '.$this->getKey())
+            ->redirect('/');
+    }
+
+    /**
+     * 设置要POST到接口的数据
+     *
+     * @return array
+     */
+    public function parameters()
+    {
+        return [];
+    }
+
+    public function render()
+    {
+        $form = UsersInfoForm::make()->payload(['id'=>$this->getKey()]);
+        return Modal::make()
+            ->lg()
+            ->title($this->title)
+            ->body($form)
+            ->button('<i class="feather icon-settings"></i> '.$this->title);
+    }
+}

+ 50 - 0
app/Admin/Actions/Users/UsersInfoForm.php

xqd
@@ -0,0 +1,50 @@
+<?php
+namespace App\Admin\Actions\Users;
+
+use App\Models\User;
+use App\Models\UserInfoModel;
+use Dcat\Admin\Contracts\LazyRenderable;
+use Dcat\Admin\Traits\LazyWidget;
+use Dcat\Admin\Widgets\Form;
+use PHPUnit\Util\Exception;
+
+class UsersInfoForm extends Form implements LazyRenderable
+{
+    use LazyWidget;
+
+
+    public function __construct($data = [], $key = null)
+    {
+        parent::__construct($data, $key);
+    }
+
+    public function handle(array $input)
+    {
+        $user = User::query()->find($input['id']);
+        if(!$user){
+
+            return $this->response()->error('请刷新后重试');
+        }
+        if($input['mobile']!=$user->mobile && User::query()->where('mobile',$input['mobile'])->first()){
+            return $this->response()->error('该手机号码已被使用');
+        }else{
+            $user->mobile = $input['mobile'];
+        }
+        if($input['password']!=''){
+            $user->password = $input['password'];
+
+        }
+        $user->save();
+        return $this->response()->success('保存成功')->refresh();
+    }
+
+
+    public function form()
+    {
+        $user_info = UserInfoModel::query()->where('user_id',$this->payload['id'])->first();
+        $this->text('user_id')->value($this->payload['id'])->readOnly();
+        $this->text('nickname', '昵称')->value($user_info->nickname);
+        $this->image('avatar', '头像')->value($user_info->avatar);
+
+    }
+}

+ 2 - 0
app/Admin/Controllers/UserController.php

xqd xqd
@@ -2,6 +2,7 @@
 
 namespace App\Admin\Controllers;
 
+use App\Admin\Actions\Users\SetUserInfo;
 use App\Admin\Actions\Users\UserAction;
 use App\Admin\Actions\Users\UserAuth;
 use App\Admin\Actions\Users\UserChange;
@@ -58,6 +59,7 @@ class UserController extends AdminController
         $grid->actions(function (Grid\Displayers\Actions $actions) {
             $actions->disableView();
             $actions->disableEdit();
+            $actions->append(new SetUserInfo(User::class));
             $actions->append(new UserAction(User::class));
             $actions->append(new UserChange(User::class));
 //            if ($actions->row->is_auth == 0) {