ShowHelperTrait.php 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <?php
  2. namespace App\Module\Dev\AdminControllers\Helper;
  3. use App\Module\Dev\Enums\DEV_LOG_TYPE;
  4. use App\Module\Dev\Enums\DEV_STATUS;
  5. use Dcat\Admin\Show;
  6. /**
  7. * 详情页辅助特性
  8. *
  9. * 提供开发工具模块后台控制器的详情页构建功能的具体实现
  10. */
  11. trait ShowHelperTrait
  12. {
  13. /**
  14. * 显示开发工具状态
  15. *
  16. * @param string $field 字段名
  17. * @param string $label 标签名
  18. * @return Show\Field
  19. */
  20. public function fieldDevStatus(string $field = 'status', string $label = '状态'): Show\Field
  21. {
  22. return $this->show->field($field, $label)->as(function ($value) {
  23. return DEV_STATUS::getAll()[$value] ?? '未知';
  24. });
  25. }
  26. /**
  27. * 显示开发日志类型
  28. *
  29. * @param string $field 字段名
  30. * @param string $label 标签名
  31. * @return Show\Field
  32. */
  33. public function fieldDevLogType(string $field = 'type', string $label = '日志类型'): Show\Field
  34. {
  35. return $this->show->field($field, $label)->as(function ($value) {
  36. return DEV_LOG_TYPE::getAll()[$value] ?? '未知';
  37. });
  38. }
  39. /**
  40. * 显示开发日志内容
  41. *
  42. * @param string $field 字段名
  43. * @param string $label 标签名
  44. * @return Show\Field
  45. */
  46. public function fieldDevLogContent(string $field = 'content', string $label = '日志内容'): Show\Field
  47. {
  48. return $this->show->field($field, $label);
  49. }
  50. /**
  51. * 显示开发日志额外数据
  52. *
  53. * @param string $field 字段名
  54. * @param string $label 标签名
  55. * @return Show\Field
  56. */
  57. public function fieldDevLogExtraData(string $field = 'extra_data', string $label = '额外数据'): Show\Field
  58. {
  59. return $this->show->field($field, $label)->json();
  60. }
  61. /**
  62. * 显示开发配置值
  63. *
  64. * @param string $field 字段名
  65. * @param string $label 标签名
  66. * @return Show\Field
  67. */
  68. public function fieldDevConfigValue(string $field = 'value', string $label = '配置值'): Show\Field
  69. {
  70. return $this->show->field($field, $label);
  71. }
  72. /**
  73. * 显示系统信息
  74. *
  75. * @param array $systemInfo 系统信息
  76. * @return Show\Field
  77. */
  78. public function fieldSystemInfo(array $systemInfo): void
  79. {
  80. $this->show->divider('系统信息');
  81. foreach ($systemInfo as $key => $value) {
  82. $label = ucwords(str_replace('_', ' ', $key));
  83. $this->show->field($key, $label)->as(function () use ($value) {
  84. return $value;
  85. });
  86. }
  87. }
  88. }