| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154 |
- <?php
- namespace App\Module\User\AdminControllers\Helper;
- use App\Module\User\Enums\STATUS2;
- use Dcat\Admin\Show;
- /**
- * 详情页辅助特性
- *
- * 提供用户模块后台控制器的详情页构建功能的具体实现
- * 只保留具有复用价值的方法
- */
- trait ShowHelperTrait
- {
- /**
- * 显示用户ID
- *
- * 复用价值:高 - 在多个控制器中使用,提供统一的用户ID显示
- *
- * @param string $field 字段名
- * @param string $label 标签名
- * @return Show\Field
- */
- public function fieldUserId(string $field = 'id', string $label = '用户ID'): Show\Field
- {
- return $this->show->field($field, $label);
- }
- /**
- * 显示用户名
- *
- * 复用价值:高 - 在多个控制器中使用,提供统一的用户名显示
- *
- * @param string $field 字段名
- * @param string $label 标签名
- * @return Show\Field
- */
- public function fieldUsername(string $field = 'username', string $label = '用户名'): Show\Field
- {
- return $this->show->field($field, $label);
- }
- /**
- * 显示用户状态
- *
- * 复用价值:高 - 统一处理用户状态的显示,使用枚举类型
- *
- * @param string $field 字段名
- * @param string $label 标签名
- * @return Show\Field
- */
- public function fieldStatus(string $field = 'status2', string $label = '状态'): Show\Field
- {
- return $this->show->field($field, $label)->as(function ($value) {
- return STATUS2::getName($value);
- });
- }
- /**
- * 显示用户头像
- *
- * 复用价值:高 - 统一处理用户头像的显示
- *
- * @param string $field 字段名
- * @param string $label 标签名
- * @return Show\Field
- */
- public function fieldAvatar(string $field = 'avatar', string $label = '头像'): Show\Field
- {
- return $this->show->field($field, $label)->image();
- }
- /**
- * 显示用户安全密码
- *
- * 复用价值:高 - 统一处理用户安全密码的显示,隐藏实际密码
- *
- * @param string $field 字段名
- * @param string $label 标签名
- * @return Show\Field
- */
- public function fieldSecretPassword(string $field = 'secret_password', string $label = '安全密码'): Show\Field
- {
- return $this->show->field($field, $label)->as(function ($value) {
- return $value ? '已设置' : '未设置';
- });
- }
- /**
- * 添加用户基本信息面板
- *
- * 复用价值:高 - 提供完整的用户基本信息面板
- *
- * @return void
- */
- public function addUserBasicPanel(): void
- {
- $this->show->divider('基本信息');
- $this->fieldUserId();
- $this->fieldUsername();
- $this->show->field('nickname', '昵称');
- $this->fieldAvatar();
- $this->fieldStatus();
- }
- /**
- * 添加用户联系信息面板
- *
- * 复用价值:高 - 提供完整的用户联系信息面板
- *
- * @return void
- */
- public function addUserContactPanel(): void
- {
- $this->show->divider('联系信息');
- $this->show->field('phone', '手机号');
- $this->show->field('email', '邮箱');
- $this->show->field('wx_id', '微信号');
- }
- /**
- * 添加用户安全信息面板
- *
- * 复用价值:高 - 提供完整的用户安全信息面板
- *
- * @return void
- */
- public function addUserSecurityPanel(): void
- {
- $this->show->divider('安全信息');
- $this->fieldSecretPassword();
- $this->show->field('last_check_at', '最后验证时间');
- }
- /**
- * 添加用户时间信息面板
- *
- * 复用价值:高 - 提供完整的用户时间信息面板
- *
- * @return void
- */
- public function addUserTimePanel(): void
- {
- $this->show->divider('时间信息');
- $this->show->field('created_at', '创建时间');
- $this->show->field('updated_at', '更新时间');
- $this->show->field('deleted_at', '删除时间');
- }
- }
|