| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159 |
- <?php
- /**
- * Created by PhpStorm.
- * User: maliang
- * Date: 2019-03-30
- * Time: 21:13
- */
- namespace Modules\Admin\Auxiliary\View;
- use Closure;
- class TableAuxiliary
- {
- /**
- * 增删查改前缀路由
- * @var string
- */
- public $path = '';
- /**
- * 标题
- * @var string
- */
- public $title = '';
- /**
- * 显示数据
- * @var
- */
- public $items;
- /**
- * 主键
- * @var string
- */
- public $primaryKey = 'id';
- /**
- * 主视图显示字段
- * @var
- */
- public $columns = [];
- /**
- * 搜索字段
- * @var array
- */
- public $searchColumns = [];
- /**
- * 个别不显示操作按钮
- * 例如
- * ['name' => 'title', 'value' => ['admin']]
- * 显示端 结果为 true 则不显示
- * in_array($item['title'], ['admin']);
- * item
- * @var array
- */
- public $displayActions = ['name' => 0, 'value' => [1]];
- /**
- * 每行的自定义按钮
- * $displayActionOthers = [
- * [
- * 'name' => '撤销',
- * 'path' => 'order/list/check',
- * 'class' => 'layui-btn-normal',
- * 'isShow' => function($item) {},
- * 'isJump' => 1,
- * ]
- * ];
- * @var null
- */
- public $displayActionOthers = null;
- /**
- * 头部的自定义按钮
- * $displayActionOthers = [
- * [
- * 'name' => '撤销',
- * 'path' => 'order/list/check',
- * 'class' => 'layui-btn-normal',
- * 'isShow' => function($item) {},
- * 'isJump' => 1,
- * ]
- * ];
- * @var null
- */
- public $topActionOthers = null;
- /**
- * 顶部操作按钮
- * @var array
- */
- public $topActions = ['add'];
- /**
- * 显示的操作按钮
- * @var array
- */
- public $actionBtns = ['view', 'edit', 'del'];
- public $actionBtnsAttribute = ['view' => '', 'edit' => '', 'del' => ''];
- /**
- * 当前字段
- * @var string
- */
- protected $currentColumn = '';
- public function __construct($path = '', $items = '')
- {
- $this->items = $items;
- $this->path = $path;
- }
- /**
- * 显示字段
- * @param $varName
- * @param string $showName
- * @param Closure|null $callback
- * @return $this
- */
- public function column($varName, $showName = '', Closure $callback = null)
- {
- $this->columns[$varName]['name'] = $showName;
- $this->currentColumn = $varName; // 记录当前字段
- if (isset($callback)) {
- $this->display($callback);
- }
- return $this;
- }
- /**
- * 搜索字段
- * @param $varName
- * @param string $showName
- * @param Closure|null $callback
- * @return $this
- */
- public function search($type, $varName, $label = '', $assist = [])
- {
- $this->searchColumns[$varName]['type'] = $type;
- $this->searchColumns[$varName]['label'] = $label;
- $this->searchColumns[$varName]['assist'] = $assist;
- return $this;
- }
- /**
- * 处理字段结果
- * @param Closure $callback
- * @return $this
- */
- public function display(Closure $callback)
- {
- $this->columns[$this->currentColumn]['value'] = $callback;
- return $this;
- }
- }
|