ShowHelper.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. <?php
  2. namespace App\Module\Friend\AdminControllers\Helper;
  3. use Dcat\Admin\Show;
  4. use Dcat\Admin\Show\Field;
  5. /**
  6. * 详情助手类
  7. *
  8. * 用于辅助构建后台详情页
  9. */
  10. class ShowHelper
  11. {
  12. /**
  13. * Show 实例
  14. *
  15. * @var Show
  16. */
  17. protected $show;
  18. /**
  19. * 构造函数
  20. *
  21. * @param Show $show
  22. */
  23. public function __construct(Show $show)
  24. {
  25. $this->show = $show;
  26. }
  27. /**
  28. * 创建实例
  29. *
  30. * @param Show $show
  31. * @return static
  32. */
  33. public static function make(Show $show)
  34. {
  35. return new static($show);
  36. }
  37. /**
  38. * 添加字段
  39. *
  40. * @param string $name
  41. * @param string $label
  42. * @return Field
  43. */
  44. public function field(string $name, string $label): Field
  45. {
  46. return $this->show->field($name, $label);
  47. }
  48. /**
  49. * 添加分隔线
  50. *
  51. * @param string $title
  52. * @return Show
  53. */
  54. public function divider(string $title = ''): Show
  55. {
  56. return $this->show->divider($title);
  57. }
  58. /**
  59. * 添加行
  60. *
  61. * @param callable $callback
  62. * @return Show
  63. */
  64. public function row(callable $callback): Show
  65. {
  66. return $this->show->row($callback);
  67. }
  68. /**
  69. * 添加卡片
  70. *
  71. * @param string $title
  72. * @param callable $callback
  73. * @return Show
  74. */
  75. public function card(string $title, callable $callback): Show
  76. {
  77. return $this->show->card($title, $callback);
  78. }
  79. /**
  80. * 添加面板
  81. *
  82. * @param string $title
  83. * @param callable $callback
  84. * @return Show
  85. */
  86. public function panel(string $title, callable $callback): Show
  87. {
  88. return $this->show->panel($title, $callback);
  89. }
  90. /**
  91. * 添加工具
  92. *
  93. * @param callable $callback
  94. * @return Show
  95. */
  96. public function tools(callable $callback): Show
  97. {
  98. return $this->show->tools($callback);
  99. }
  100. /**
  101. * 添加关联
  102. *
  103. * @param string $name
  104. * @param string $label
  105. * @param callable $callback
  106. * @return Show
  107. */
  108. public function relation(string $name, string $label, callable $callback): Show
  109. {
  110. return $this->show->relation($name, $label, $callback);
  111. }
  112. }