120 lines
3.2 KiB
PHP
120 lines
3.2 KiB
PHP
<?php
|
|
|
|
namespace App\Admin\Controllers;
|
|
|
|
use Encore\Admin\Controllers\HasResourceActions;
|
|
use Encore\Admin\Form;
|
|
use Encore\Admin\Grid;
|
|
use Encore\Admin\Layout\Content;
|
|
use Encore\Admin\Widgets\Table;
|
|
use RuLong\Identity\Models\Identity;
|
|
|
|
class IdentityController extends Controller
|
|
{
|
|
use HasResourceActions;
|
|
|
|
/**
|
|
* Index interface.
|
|
*
|
|
* @param Content $content
|
|
* @return Content
|
|
*/
|
|
public function index(Content $content)
|
|
{
|
|
return $content
|
|
->header('用户身份管理')
|
|
->description('仅供超级管理员管理')
|
|
->body($this->grid());
|
|
}
|
|
|
|
/**
|
|
* Edit interface.
|
|
*
|
|
* @param mixed $id
|
|
* @param Content $content
|
|
* @return Content
|
|
*/
|
|
public function edit($id, Content $content)
|
|
{
|
|
return $content
|
|
->header('编辑身份')
|
|
->body($this->form()->edit($id));
|
|
}
|
|
|
|
/**
|
|
* Make a grid builder.
|
|
*
|
|
* @return Grid
|
|
*/
|
|
protected function grid()
|
|
{
|
|
$identity_model = new Identity();
|
|
$grid = new Grid(new Identity);
|
|
$grid->disableCreateButton();
|
|
$grid->disableFilter();
|
|
$grid->disableExport();
|
|
$grid->disableRowSelector();
|
|
$grid->tools(function ($tools) {
|
|
$tools->batch(function ($batch) {
|
|
$batch->disableDelete();
|
|
});
|
|
});
|
|
$grid->actions(function ($actions) {
|
|
$actions->disableDelete();
|
|
$actions->disableView();
|
|
});
|
|
$grid->column('id', '身份编号');
|
|
$grid->column('title', '身份名称');
|
|
|
|
$grid->useridentitys('人数')->count()->modal('详细信息', function ($model) {
|
|
$users = $model->useridentitys->map(function ($useridentity) {
|
|
return [$useridentity->user_id, $useridentity->user->info->nickname, $useridentity->user->info->mobile, $useridentity->user->created_at];
|
|
});
|
|
return new Table(['ID', '昵称', '手机号', '注册时间'], $users->toArray());
|
|
});
|
|
|
|
$grid->column('配置项')->display(function () {
|
|
return $this->config_text;
|
|
});
|
|
|
|
$grid->created_at('创建时间');
|
|
$grid->updated_at('更新时间');
|
|
|
|
return $grid;
|
|
}
|
|
|
|
/**
|
|
* Make a form builder.
|
|
*
|
|
* @return Form
|
|
*/
|
|
protected function form()
|
|
{
|
|
$form = new Form(new Identity);
|
|
$form->display('id', 'ID');
|
|
$form->text('title', '身份名称')->rules('required');
|
|
|
|
$form->embeds('configs', '配置项', function ($form) {
|
|
$configArray = config('rulong_identity.configs');
|
|
foreach ($configArray as $key => $config) {
|
|
$name = $config['name'];
|
|
$rule = $config['rule'];
|
|
$form->rate($key, $name)->rules($rule['rules'], $rule['prompt'])->setWidth(1);
|
|
}
|
|
});
|
|
|
|
$form->tools(function (Form\Tools $tools) {
|
|
$tools->disableDelete();
|
|
$tools->disableView();
|
|
});
|
|
|
|
$form->footer(function ($footer) {
|
|
$footer->disableReset();
|
|
$footer->disableViewCheck();
|
|
$footer->disableCreatingCheck();
|
|
});
|
|
|
|
return $form;
|
|
}
|
|
}
|