UserController.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <?php
  2. namespace App\Admin\Controllers;
  3. use App\Admin\Repositories\User;
  4. use App\Models\UserLock;
  5. use Dcat\Admin\Form;
  6. use Dcat\Admin\Grid;
  7. use Dcat\Admin\Show;
  8. use Dcat\Admin\Http\Controllers\AdminController;
  9. class UserController extends AdminController
  10. {
  11. /**
  12. * Make a grid builder.
  13. *
  14. * @return Grid
  15. */
  16. protected function grid()
  17. {
  18. return Grid::make(new User(), function (Grid $grid) {
  19. $grid->model()->with('member:id,title');
  20. $grid->column('id')->sortable();
  21. $grid->column('name');
  22. $grid->column('account');
  23. $grid->column('email');
  24. $grid->column('online')->using(config('map.online'))->label(['gray', 'success']);
  25. $grid->column('member.title',admin_trans_field('member_type'))->label(['gray', 'success']);
  26. $grid->column('status')->switch();
  27. $grid->column('created_at')->sortable();
  28. $grid->disableCreateButton();
  29. $grid->filter(function (Grid\Filter $filter) {
  30. $filter->panel();
  31. $filter->like('name', admin_trans_field('name'))->width(4);
  32. $filter->like('mobile', admin_trans_field('mobile'))->width(4);
  33. $filter->like('email', admin_trans_field('email'))->width(4);
  34. $filter->between('created_at', admin_trans_field('created_at'))->datetime()->width(4);
  35. });
  36. });
  37. }
  38. /**
  39. * Make a show builder.
  40. *
  41. * @param mixed $id
  42. *
  43. * @return Show
  44. */
  45. protected function detail($id)
  46. {
  47. return Show::make($id, new User(), function (Show $show) {
  48. $show->field('id')->width(4);
  49. $show->field('name')->width(4);
  50. $show->field('email')->width(4);
  51. $show->field('mobile')->width(4);
  52. $show->field('jpush_reg_id')->width(4);
  53. $show->field('last_login_ip')->width(4);
  54. $show->field('last_login_time')->width(4);
  55. $show->field('register_ip')->width(4);
  56. $show->field('created_at')->width(4);
  57. $show->field('updated_at')->width(4);
  58. });
  59. }
  60. /**
  61. * Make a form builder.
  62. *
  63. * @return Form
  64. */
  65. protected function form()
  66. {
  67. return Form::make(new User(), function (Form $form) {
  68. $form->display('id')->width(4);
  69. $form->text('name')->required()->width(4);
  70. $form->text('account')->required()->width(4);
  71. $form->email('email')->required()->width(4);
  72. $form->password('password')->default('')
  73. ->placeholder('不修改时,默认为空。')
  74. ->minLength(6)
  75. ->maxLength(20)
  76. ->customFormat(function ($v) {
  77. if ($v == $this->password) {
  78. return;
  79. }
  80. return $v;
  81. })->width(4);
  82. $form->switch('status')->width(4);
  83. $form->display('created_at')->width(4);
  84. $form->display('updated_at')->width(4);
  85. $form->saving(function (Form $form) {
  86. if(!$form->input('password')){
  87. $form->deleteInput('password');
  88. }
  89. });
  90. });
  91. }
  92. }