TableAuxiliary.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: maliang
  5. * Date: 2019-03-30
  6. * Time: 21:13
  7. */
  8. namespace Modules\Admin\Auxiliary\View;
  9. use Closure;
  10. class TableAuxiliary
  11. {
  12. /**
  13. * 增删查改前缀路由
  14. * @var string
  15. */
  16. public $path = '';
  17. /**
  18. * 标题
  19. * @var string
  20. */
  21. public $title = '';
  22. /**
  23. * 显示数据
  24. * @var
  25. */
  26. public $items;
  27. /**
  28. * 主键
  29. * @var string
  30. */
  31. public $primaryKey = 'id';
  32. /**
  33. * 主视图显示字段
  34. * @var
  35. */
  36. public $columns = [];
  37. /**
  38. * 搜索字段
  39. * @var array
  40. */
  41. public $searchColumns = [];
  42. /**
  43. * 个别不显示操作按钮
  44. * 例如
  45. * ['name' => 'title', 'value' => ['admin']]
  46. * 显示端 结果为 true 则不显示
  47. * in_array($item['title'], ['admin']);
  48. * item
  49. * @var array
  50. */
  51. public $displayActions = ['name' => 0, 'value' => [1]];
  52. /**
  53. * 每行的自定义按钮
  54. * $displayActionOthers = [
  55. * [
  56. * 'name' => '撤销',
  57. * 'path' => 'order/list/check',
  58. * 'class' => 'layui-btn-normal',
  59. * 'isShow' => function($item) {},
  60. * 'isJump' => 1,
  61. * ]
  62. * ];
  63. * @var null
  64. */
  65. public $displayActionOthers = null;
  66. /**
  67. * 头部的自定义按钮
  68. * $displayActionOthers = [
  69. * [
  70. * 'name' => '撤销',
  71. * 'path' => 'order/list/check',
  72. * 'class' => 'layui-btn-normal',
  73. * 'isShow' => function($item) {},
  74. * 'isJump' => 1,
  75. * ]
  76. * ];
  77. * @var null
  78. */
  79. public $topActionOthers = null;
  80. /**
  81. * 顶部操作按钮
  82. * @var array
  83. */
  84. public $topActions = ['add'];
  85. /**
  86. * 显示的操作按钮
  87. * @var array
  88. */
  89. public $actionBtns = ['view', 'edit', 'del'];
  90. public $actionBtnsAttribute = ['view' => '', 'edit' => '', 'del' => ''];
  91. /**
  92. * 当前字段
  93. * @var string
  94. */
  95. protected $currentColumn = '';
  96. public function __construct($path = '', $items = '')
  97. {
  98. $this->items = $items;
  99. $this->path = $path;
  100. }
  101. /**
  102. * 显示字段
  103. * @param $varName
  104. * @param string $showName
  105. * @param Closure|null $callback
  106. * @return $this
  107. */
  108. public function column($varName, $showName = '', Closure $callback = null)
  109. {
  110. $this->columns[$varName]['name'] = $showName;
  111. $this->currentColumn = $varName; // 记录当前字段
  112. if (isset($callback)) {
  113. $this->display($callback);
  114. }
  115. return $this;
  116. }
  117. /**
  118. * 搜索字段
  119. * @param $varName
  120. * @param string $showName
  121. * @param Closure|null $callback
  122. * @return $this
  123. */
  124. public function search($type, $varName, $label = '', $assist = [])
  125. {
  126. $this->searchColumns[$varName]['type'] = $type;
  127. $this->searchColumns[$varName]['label'] = $label;
  128. $this->searchColumns[$varName]['assist'] = $assist;
  129. return $this;
  130. }
  131. /**
  132. * 处理字段结果
  133. * @param Closure $callback
  134. * @return $this
  135. */
  136. public function display(Closure $callback)
  137. {
  138. $this->columns[$this->currentColumn]['value'] = $callback;
  139. return $this;
  140. }
  141. }