UserController.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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()->orderByDesc('id');
  20. $grid->column('id')->sortable();
  21. $grid->column('name');
  22. $grid->column('account');
  23. $grid->column('avatar')->image('',40);
  24. $grid->column('email');
  25. $grid->column('mobile');
  26. $grid->column('online')->using(config('map.online'))->label(['gray', 'success']);
  27. $grid->column('member_type',admin_trans_field('member_type'))->using([
  28. 1=>'一般会员',
  29. 2=>'企业会员'
  30. ])->label(['success','gray']);
  31. $grid->column('status')->switch();
  32. $grid->column('created_at')->sortable();
  33. $grid->disableCreateButton();
  34. $grid->filter(function (Grid\Filter $filter) {
  35. $filter->panel();
  36. $filter->like('name', admin_trans_field('name'))->width(4);
  37. $filter->like('mobile', admin_trans_field('mobile'))->width(4);
  38. $filter->like('email', admin_trans_field('email'))->width(4);
  39. $filter->equal('member_type', admin_trans_field('member_type'))->select([
  40. 1=>'一般会员',
  41. 2=>'企业会员',
  42. ])->width(4);
  43. $filter->between('created_at', admin_trans_field('created_at'))->datetime()->width(4);
  44. });
  45. });
  46. }
  47. /**
  48. * Make a show builder.
  49. *
  50. * @param mixed $id
  51. *
  52. * @return Show
  53. */
  54. protected function detail($id)
  55. {
  56. return Show::make($id, new User(), function (Show $show) {
  57. $show->field('id')->width(4);
  58. $show->field('name')->width(4);
  59. $show->field('email')->width(4);
  60. $show->field('mobile')->width(4);
  61. $show->field('jpush_reg_id')->width(4);
  62. $show->field('last_login_ip')->width(4);
  63. $show->field('last_login_time')->width(4);
  64. $show->field('register_ip')->width(4);
  65. $show->field('created_at')->width(4);
  66. $show->field('updated_at')->width(4);
  67. });
  68. }
  69. /**
  70. * Make a form builder.
  71. *
  72. * @return Form
  73. */
  74. protected function form()
  75. {
  76. return Form::make(new User(), function (Form $form) {
  77. $form->display('id')->width(4);
  78. $form->text('name')->required()->width(4);
  79. $form->text('account')->required()->width(4);
  80. $form->email('email')->required()->width(4);
  81. $form->password('password')->default('')
  82. ->placeholder('不修改时,默认为空。')
  83. ->minLength(6)
  84. ->maxLength(20)
  85. ->customFormat(function ($v) {
  86. if ($v == $this->password) {
  87. return;
  88. }
  89. return $v;
  90. })->width(4);
  91. $form->switch('status')->width(4);
  92. $form->display('created_at')->width(4);
  93. $form->display('updated_at')->width(4);
  94. $form->saving(function (Form $form) {
  95. if(!$form->input('password')){
  96. $form->deleteInput('password');
  97. }
  98. });
  99. });
  100. }
  101. }