您好,欢迎访问一九零五行业门户网

表格输出组件

跳至 [1] [全屏预览] [ [ 'type' => 'checkbox' , 'name' => 'uid', 'id' => 'user', 'htmloptions' => [ 'style' => 'color:green', ] ], ['name' => 'visitid', 'header' => '随访id', 'value' => '$data[visitid]'], ['name' => 'visitname', 'header' => '方案名称', 'value' => '$data[visitname]'], ['name' => 'joiner_nums', 'header' => '参与人', 'value' => 'visitdbmodel::getjoiner_nums($data)'], ['name' => 'realname', 'header' => '创建人', 'value' => '$data[realname]'], ['name' => 'department_name', 'header' => '科室', 'value' => '$data[department_name]'], ['name' => 'ques_nums', 'header' => '问题', 'value' => '$data[ques_nums]'], [ 'type' => 'button' , 'header' => '操作' , 'template'=>'{invitation} {detail}', 操作模板配置 'htmloptions' => [ 'class' => 'doit' ], 'buttons' => [ 'invitation' => [ 'label' => '邀请参与人', 'url' => '/admin/visit/invitation/?visitid=$data[visitid]', 'htmloptions' => ['class' => 'fllow_add_btn'], 'visible' => 'isset($_get[type]) && $_get[type] == myvisit ? true : false', ], 'detail' => [ 'label' => '详情', 'url' => '/admin/visit/detail/?visitid=$data[visitid]', 'htmloptions' => ['class' => 'fllow_add_btn'], 'visible' => 'visitdbmodel::test($data)', 权限控制表达式,结果为true按钮将会显示,否则不显示 ] ], ], ], ]);?> * 带多选框和操作列的使用 * $data['datas'], 'columns' => [ [ 'type' => 'checkbox' , 'name' => 'uid', 'id' => 'uid', 'htmloptions' => [ 'style' => 'color:green', ] ], ['name' => 'visitid', 'header' => '随访id', 'value' => '$data[visitid]'], ['name' => 'visitname', 'header' => '方案名称', 'value' => '$data[visitname]'], ['name' => 'joiner_nums', 'header' => '参与人', 'value' => 'visitdbmodel::getjoiner_nums($data)'], ['name' => 'realname', 'header' => '创建人', 'value' => '$data[realname]'], ['name' => 'department_name', 'header' => '科室', 'value' => '$data[department_name]'], ['name' => 'ques_nums', 'header' => '问题', 'value' => '$data[ques_nums]'], [ 'type' => 'button' , 'header' => '操作' , 'template'=>'{invitation} {detail}', 'buttons' => [ 'invitation' => [ 'label' => '邀请参与人', 'url' => '/admin/visit/invitation/?doctor_id=$data[doctor_id]', 'htmloptions' => ['class' => 'fllow_add_btn'], 'visible' => 'true', ], 'detail' => [ 'label' => '详情', 'url' => '/admin/visit/detail/?visitid=$data[visitid]', 'htmloptions' => ['class' => 'fllow_add_btn'], 'visible' => 'false', ] ], ], ], ]);?> * * @author 风居住的地方 */class listview { /** * 接收数据,将会进行数据处理 * @var type */ public $datas; /** * 表格的html选项 * @var type */ public $htmloptions; /** * 数据字段 * @var type */ public $columns; /** * 数据为空显示的消息 * @var type */ public $emptymessage = '暂无数据'; public function __construct($datas) { foreach ($datas as $k => $v) $this->$k = $v; $this->initdata(); } public function run() { $html = ''; $html .= html::tag('table', $this->htmloptions , false); ob_start(); ob_implicit_flush(false); $this->renderstart(); $this->rendercontent(); $html .= ob_get_clean(); $html .= html::endtag('table'); return $html; } /** * 渲染头 */ protected function renderstart() { $html = ''; $html .= html::tag('thead'); $html .= html::tag('tr'); $html .= $this->_renderstart('th'); $html .= html::endtag('tr'); $html .= html::endtag('thead'); echo $html; } protected function _renderstart($tag) { if (empty($this->columns)) return ''; $html = ''; foreach($this->columns as $data) { if (isset($data['type']) && $data['type'] == 'checkbox') { if (isset($data['htmloptions']['type'])) unset($data['htmloptions']['type']); if (isset($data['htmloptions']['name'])) unset($data['htmloptions']['name']); if (isset($data['htmloptions']['id'])) unset($data['htmloptions']['id']); if (isset($data['htmloptions']['value'])) unset($data['htmloptions']['value']); $data['htmloptions']['type'] = $data['type']; $data['htmloptions']['name'] = $data['name'].'[]'; $data['htmloptions']['id'] = $data['id']; $data['htmloptions']['value'] = ''; $data['htmloptions']['onclick'] = 'selectall()'; $checkbox = html::tag('input', $data['htmloptions']); $html .= html::tag($tag, [], $checkbox); $html .= $this->regsterjs($data['id'] , $data['name'].'[]'); } else { if (isset($data['raw']) && $data['raw'] == 'false') { eval('$header = '.$data['header'].';'); if (isset($header)) { $data['header'] = $header; } } $html .= html::tag($tag, [], isset($data['header']) ? $data['header'] : ''); } } return $html; } /** * 渲染内容 */ protected function rendercontent() { $html = ''; $html .= html::tag('tbody'); $html .= $this->_rendercontent('td'); $html .= html::endtag('tbody'); echo $html; } /** * 初始化原始数据 */ protected function initdata() { if (empty($this->datas)) return ; foreach($this->datas as $i => &$data) { foreach ($this->columns as $value) { if (isset($value['type']) && $value['type'] == 'checkbox') { $data['checkbox'] = $this->_checkdata($value , $data); } if (isset($value['type']) && isset($value['header']) && isset($value['template']) && isset($value['buttons'])) $data['actions'] = $this->_initdata($value , $data); } } } protected function _checkdata($value , &$data) { if (!isset($value['htmloptions'])) $value['htmloptions'] = []; $value['htmloptions']['type'] = 'checkbox'; $value['htmloptions']['name'] = $value['name'].'[]'; $value['htmloptions']['value'] = ''; return html::tag('input', $value['htmloptions']); } /** * 具体初始化执行 * @param type $value * @param array $data * @return array */ protected function _initdata($value , &$data) { $data['actions'] = []; foreach($value['buttons'] as $key => $v) { if (isset($v['visible'])) { eval('$visible = '.$v['visible'].';'); if (!$visible) { $value['template'] = str_replace({{$key}}, '' , $value['template']); unset($value['buttons'][$key]); continue; } } eval('$url = '.str_replace('', '', $v['url']).';'); $v['htmloptions']['href'] = $url; $data['actions'][$key] = html::tag('a', $v['htmloptions'], $v['label']); } foreach($data['actions'] as $k => $v) { $value['template'] = str_replace({{$k}}, $v, $value['template']); } return $value['template']; } /** * 渲染具体内容 * @param type $tag * @return string */ public function _rendercontent($tag) { $html = ''; if (empty($this->datas)) { $html .= html::tag('tr'); $html .= html::tag($tag, ['colspan' => count($this->columns)], $this->emptymessage); $html .= html::endtag('tr'); return $html; } foreach($this->datas as $data) { $html .= html::tag('tr'); foreach($this->columns as $value) { if (!isset($value['htmloptions'])) $value['htmloptions'] = []; if (isset($value['type'])) { if ($value['type'] == 'checkbox' || $value['type'] == 'button') { if ($value['type'] == 'checkbox') { if (isset($value['htmloptions']['type'])) unset($value['htmloptions']['type']); if (isset($value['htmloptions']['name'])) unset($value['htmloptions']['name']); $value['htmloptions']['type'] = $value['type']; $value['htmloptions']['name'] = $value['name'].'[]'; $value['htmloptions']['value'] = $data[$value['name']]; $checkbox = html::tag('input', $value['htmloptions']); $html .= html::tag($tag, [], $checkbox); } else { $html .= html::tag($tag, $value['htmloptions'], !isset($data['actions']) ? false : $data['actions']); } } } else { eval('$v = '.$value['value'].';'); $html .= html::tag($tag, $value['htmloptions'], $v); } } $html .= html::endtag('tr'); } return $html; } /** * 注册js代码 * @param type $id */ protected function regsterjs($id , $name) { $js =<<
其它类似信息

推荐信息