123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138 |
- <?php namespace Manage\Api\Page;
- use Dever;
- use Manage\Lib\Page;
- # 数据获取
- class Data extends Page
- {
- public function __construct()
- {
- parent::__construct('list');
- }
- public function list()
- {
- $where = $data['head'] = array();
- $data['field'] = $this->setting('field', $data['head']);
- $data['search'] = $this->search($where);
- $data['button'] = $this->button();
- $data['body_button'] = $this->button('data_button');
- $data['body'] = $this->data($where);
- $data['total'] = Dever::page('total');
- $data['height'] = $this->config['height'] ?? '100%';
- $data['filter'] = $this->config['filter'] ?? 'name';
- $data['desc'] = $this->config['desc'] ?? '';
- return $data;
- }
- private function data($where)
- {
- $set['num'] = Dever::input('pgnum', '', '', 10);
- $data = $this->db->select($where, $set);
- if ($data) {
- foreach ($data as $k => $v) {
- foreach ($v as $key => $value) {
- if (isset($this->config['field'][$key]) && $show = Dever::isset($this->config['field'][$key], 'show')) {
- $data[$k][$key] = $this->getShow($show, $v);
- } elseif ($value && isset($this->db->config['struct'][$key]['value']) && $this->db->config['struct'][$key]['value']) {
- $data[$k][$key] = $this->db->value($key, $value);
- } elseif ($key == 'cdate') {
- $data[$k][$key] = date('Y-m-d H:i', $value);
- }
- }
- }
- }
- return $data;
- }
- private function search(&$where)
- {
- $search = Dever::input('search');
- $list_search = $result = array();
- $this->setting('search', $list_search, false, 'text');
- if ($list_search && $search) {
- foreach ($list_search as $v) {
- if ($v['type'] != 'hidden') {
- $result[] = $v;
- }
- if ($value = Dever::isset($search, $v['key'])) {
- if ($v['type'] == 'group') {
- $where[$v['key']] = array('group', $value);
- } elseif ($v['type'] == 'selects') {
- $where[$v['key']] = array('group', $value);
- } elseif ($v['type'] == 'like') {
- $where[$v['key']] = array('like', $value);
- } elseif ($v['type'] == 'in') {
- $where[$v['key']] = array('in', $value);
- } else {
- $where[$v['key']] = $value;
- }
- }
- }
- } else {
- $result = $list_search;
- }
- return $result;
- }
- private function button($key = 'button')
- {
- $result = array();
- if (empty($this->config[$key])) {
- if ($key == 'list_button') {
- $this->config[$key] = array('新增' => 'fastadd', '删除' => 'del');
- } else {
- $this->config[$key] = array('编辑' => 'fastedit', '删除' => 'del');
- }
- }
- foreach ($this->config[$key] as $k => $v) {
- $p = '';
- $i = '';
- if (is_array($v)) {
- if (isset($v[2])) {
- $i = $v[2];
- }
- if (isset($v[1])) {
- $p = $v[1];
- }
- $v = $v[0];
- }
- if (strstr($v, 'add')) {
- $icon = 'Plus';
- $button = 'primary';
- } elseif (strstr($v, 'edit')) {
- $icon = 'Edit';
- $button = 'primary';
- } elseif (strstr($v, 'view')) {
- $icon = 'View';
- $button = '';
- } elseif ($v == 'del') {
- $icon = 'Delete';
- $button = 'danger';
- } elseif ($v == 'oper') {
- $icon = 'Notification';
- $button = 'warning';
- } elseif ($v == 'link') {
- $icon = 'Link';
- $button = 'success';
- } elseif ($v == 'recover') {
- $icon = 'HelpFilled';
- $button = 'info';
- } elseif ($v == 'recycler') {
- $icon = 'HelpFilled';
- $button = 'info';
- }
- if ($i) {
- $icon = $i;
- }
- $result[] = array
- (
- 'name' => $k,
- 'type' => $v,
- 'param' => $p,
- 'icon' => $icon,
- 'button' => $button,
- );
- }
- return $result;
- }
- }
|