ShowHelperTrait.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. <?php
  2. namespace App\Module\User\AdminControllers\Helper;
  3. use App\Module\User\Enums\STATUS2;
  4. use Dcat\Admin\Show;
  5. /**
  6. * 详情页辅助特性
  7. *
  8. * 提供用户模块后台控制器的详情页构建功能的具体实现
  9. * 只保留具有复用价值的方法
  10. */
  11. trait ShowHelperTrait
  12. {
  13. /**
  14. * 显示用户ID
  15. *
  16. * 复用价值:高 - 在多个控制器中使用,提供统一的用户ID显示
  17. *
  18. * @param string $field 字段名
  19. * @param string $label 标签名
  20. * @return Show\Field
  21. */
  22. public function fieldUserId(string $field = 'id', string $label = '用户ID'): Show\Field
  23. {
  24. return $this->show->field($field, $label);
  25. }
  26. /**
  27. * 显示用户名
  28. *
  29. * 复用价值:高 - 在多个控制器中使用,提供统一的用户名显示
  30. *
  31. * @param string $field 字段名
  32. * @param string $label 标签名
  33. * @return Show\Field
  34. */
  35. public function fieldUsername(string $field = 'username', string $label = '用户名'): Show\Field
  36. {
  37. return $this->show->field($field, $label);
  38. }
  39. /**
  40. * 显示用户状态
  41. *
  42. * 复用价值:高 - 统一处理用户状态的显示,使用枚举类型
  43. *
  44. * @param string $field 字段名
  45. * @param string $label 标签名
  46. * @return Show\Field
  47. */
  48. public function fieldStatus(string $field = 'status2', string $label = '状态'): Show\Field
  49. {
  50. return $this->show->field($field, $label)->as(function ($value) {
  51. return STATUS2::getName($value);
  52. });
  53. }
  54. /**
  55. * 显示用户头像
  56. *
  57. * 复用价值:高 - 统一处理用户头像的显示
  58. *
  59. * @param string $field 字段名
  60. * @param string $label 标签名
  61. * @return Show\Field
  62. */
  63. public function fieldAvatar(string $field = 'avatar', string $label = '头像'): Show\Field
  64. {
  65. return $this->show->field($field, $label)->image();
  66. }
  67. /**
  68. * 显示用户安全密码
  69. *
  70. * 复用价值:高 - 统一处理用户安全密码的显示,隐藏实际密码
  71. *
  72. * @param string $field 字段名
  73. * @param string $label 标签名
  74. * @return Show\Field
  75. */
  76. public function fieldSecretPassword(string $field = 'secret_password', string $label = '安全密码'): Show\Field
  77. {
  78. return $this->show->field($field, $label)->as(function ($value) {
  79. return $value ? '已设置' : '未设置';
  80. });
  81. }
  82. /**
  83. * 添加用户基本信息面板
  84. *
  85. * 复用价值:高 - 提供完整的用户基本信息面板
  86. *
  87. * @return void
  88. */
  89. public function addUserBasicPanel(): void
  90. {
  91. $this->show->divider('基本信息');
  92. $this->fieldUserId();
  93. $this->fieldUsername();
  94. $this->show->field('nickname', '昵称');
  95. $this->fieldAvatar();
  96. $this->fieldStatus();
  97. }
  98. /**
  99. * 添加用户联系信息面板
  100. *
  101. * 复用价值:高 - 提供完整的用户联系信息面板
  102. *
  103. * @return void
  104. */
  105. public function addUserContactPanel(): void
  106. {
  107. $this->show->divider('联系信息');
  108. $this->show->field('phone', '手机号');
  109. $this->show->field('email', '邮箱');
  110. $this->show->field('wx_id', '微信号');
  111. }
  112. /**
  113. * 添加用户安全信息面板
  114. *
  115. * 复用价值:高 - 提供完整的用户安全信息面板
  116. *
  117. * @return void
  118. */
  119. public function addUserSecurityPanel(): void
  120. {
  121. $this->show->divider('安全信息');
  122. $this->fieldSecretPassword();
  123. $this->show->field('last_check_at', '最后验证时间');
  124. }
  125. /**
  126. * 添加用户时间信息面板
  127. *
  128. * 复用价值:高 - 提供完整的用户时间信息面板
  129. *
  130. * @return void
  131. */
  132. public function addUserTimePanel(): void
  133. {
  134. $this->show->divider('时间信息');
  135. $this->show->field('created_at', '创建时间');
  136. $this->show->field('updated_at', '更新时间');
  137. $this->show->field('deleted_at', '删除时间');
  138. }
  139. }