| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108 |
- <?php
- namespace App\Admin\Controllers;
- use App\Admin\Repositories\User;
- use App\Models\UserLock;
- use Dcat\Admin\Form;
- use Dcat\Admin\Grid;
- use Dcat\Admin\Show;
- use Dcat\Admin\Http\Controllers\AdminController;
- class UserController extends AdminController
- {
- /**
- * Make a grid builder.
- *
- * @return Grid
- */
- protected function grid()
- {
- return Grid::make(new User(), function (Grid $grid) {
- $grid->model()->orderByDesc('id');
- $grid->column('id')->sortable();
- $grid->column('name');
- $grid->column('account');
- $grid->column('avatar')->image('',40);
- $grid->column('email');
- $grid->column('mobile');
- $grid->column('online')->using(config('map.online'))->label(['gray', 'success']);
- $grid->column('member_type',admin_trans_field('member_type'))->using([
- 1=>'一般会员',
- 2=>'企业会员'
- ])->label(['success','gray']);
- $grid->column('status')->switch();
- $grid->column('created_at')->sortable();
- $grid->disableCreateButton();
- $grid->filter(function (Grid\Filter $filter) {
- $filter->panel();
- $filter->like('name', admin_trans_field('name'))->width(4);
- $filter->like('mobile', admin_trans_field('mobile'))->width(4);
- $filter->like('email', admin_trans_field('email'))->width(4);
- $filter->equal('member_type', admin_trans_field('member_type'))->select([
- 1=>'一般会员',
- 2=>'企业会员',
- ])->width(4);
- $filter->between('created_at', admin_trans_field('created_at'))->datetime()->width(4);
- });
- });
- }
- /**
- * Make a show builder.
- *
- * @param mixed $id
- *
- * @return Show
- */
- protected function detail($id)
- {
- return Show::make($id, new User(), function (Show $show) {
- $show->field('id')->width(4);
- $show->field('name')->width(4);
- $show->field('email')->width(4);
- $show->field('mobile')->width(4);
- $show->field('jpush_reg_id')->width(4);
- $show->field('last_login_ip')->width(4);
- $show->field('last_login_time')->width(4);
- $show->field('register_ip')->width(4);
- $show->field('created_at')->width(4);
- $show->field('updated_at')->width(4);
- });
- }
- /**
- * Make a form builder.
- *
- * @return Form
- */
- protected function form()
- {
- return Form::make(new User(), function (Form $form) {
- $form->display('id')->width(4);
- $form->text('name')->required()->width(4);
- $form->text('account')->required()->width(4);
- $form->email('email')->required()->width(4);
- $form->password('password')->default('')
- ->placeholder('不修改时,默认为空。')
- ->minLength(6)
- ->maxLength(20)
- ->customFormat(function ($v) {
- if ($v == $this->password) {
- return;
- }
- return $v;
- })->width(4);
- $form->switch('status')->width(4);
- $form->display('created_at')->width(4);
- $form->display('updated_at')->width(4);
- $form->saving(function (Form $form) {
- if(!$form->input('password')){
- $form->deleteInput('password');
- }
- });
- });
- }
- }
|