TreeAuxiliary.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: maliang
  5. * Date: 2019-03-30
  6. * Time: 10:00
  7. */
  8. namespace Modules\Admin\Auxiliary\View;
  9. use Closure;
  10. class TreeAuxiliary
  11. {
  12. /**
  13. * 增删查改前缀路由
  14. * @var string
  15. */
  16. public $path = '';
  17. /**
  18. * 显示数据
  19. * @var
  20. */
  21. public $items;
  22. /**
  23. * 主视图显示字段
  24. * @var
  25. */
  26. public $columns = [];
  27. /**
  28. * 顶部操作按钮
  29. * @var array
  30. */
  31. public $topActions = [];
  32. /**
  33. * 头部自定义按钮
  34. * $displayActionOthers = [
  35. * [
  36. * 'name' => '撤销',
  37. * 'path' => 'order/list/check',
  38. * 'class' => 'layui-btn-normal',
  39. * 'isShow' => function($item) {},
  40. * 'isJump' => 1,
  41. * ]
  42. * ];
  43. * @var null
  44. */
  45. public $displayActionOthers = null;
  46. /**
  47. * 显示操作按钮定义
  48. * @var array
  49. */
  50. public $actionBtns = ['edit', 'del'];
  51. /**
  52. * 当前字段
  53. * @var string
  54. */
  55. protected $currentColumn = '';
  56. public function __construct($path = '', $items = '')
  57. {
  58. $this->items = $items;
  59. $this->path = $path;
  60. }
  61. /**
  62. * 显示字段
  63. * @param $varName
  64. * @param string $showName
  65. * @param Closure|null $callback
  66. * @return $this
  67. */
  68. public function column($varName, $showName = '', Closure $callback = null)
  69. {
  70. $this->columns[$varName]['name'] = $showName;
  71. $this->currentColumn = $varName; // 记录当前字段
  72. if (isset($callback)) {
  73. $this->display($callback);
  74. }
  75. return $this;
  76. }
  77. /**
  78. * 处理字段结果
  79. * @param Closure $callback
  80. * @return $this
  81. */
  82. public function display(Closure $callback)
  83. {
  84. $this->columns[$this->currentColumn]['value'] = $callback;
  85. return $this;
  86. }
  87. }