getFunc('list', '列表', 1)) { Dever::error('无访问权限'); } $data['title'] = ''; $data['button'] = $this->button(); $data['bodyButton'] = $this->button('data_button'); $data['recycler'] = $this->recycler; $data = array_merge($data, $this->out()); $data['total'] = Dever::page('total'); $data['height'] = $this->config['height'] ?? '100%'; $data['type'] = $this->config['type'] ?? 'table'; $data['desc'] = $this->config['desc'] ?? ''; $data['layout'] = $this->config['layout'] ?? array(); $data['exportButton'] = $this->export(); $data['show'] = array ( 'selection' => $this->selection, 'expand' => $this->expand, 'index' => $this->config['index'] ?? false, ); $this->column($data); return $data; } public function out() { $where = $this->config['where'] ?? array(); $data['field'] = $data['head'] = array(); $data['search'] = $this->search($where); if (isset($this->config['data'])) { $result = Dever::call($this->config['data'], $where); $data = array_merge($data, $result); } else { $data['field'] = $this->setting('field', $data['head'], true, 'show'); $data['body'] = $this->data($where); } $method = Dever::input('method'); if ($method && strstr($method, '.')) { $result = Dever::call($method, $data); unset($data); $data['field'] = $result['head']; $data['body'] = $result['body']; } $data['stat'] = array(); if (isset($this->config['stat'])) { $data['stat'] = Dever::call($this->config['stat'], $where); } return $data; } private function data($where) { $set['num'] = Dever::input('pgnum', '', '', 10); $order_col = Dever::input('order_col'); if ($order_col) { $order_value = Dever::input('order_value'); if ($order_value) { $set['order'] = $order_col . ' ' . $order_value . ', id desc'; } } if (isset($this->config['tree'])) { return $this->db->tree($where, $this->config['tree'], array($this, 'handleData')); } $data = $this->db->select($where, $set); $result = array(); if ($data) { foreach ($data as $k => $v) { $result[$k] = $this->handleData($v); } } return $result; } public function handleData($v) { $result['id'] = $v['id']; $result['cdate'] = $v['cdate']; foreach ($this->field as $value) { $key = $value['key']; if (isset($v[$key])) { $result[$key] = $this->getValue($key, $v[$key], $v, $value); } elseif (strpos($key, '/')) { $other = $this->getOther($key, $value['where'], $v); if ($other) { $otherName = array(); foreach ($other as $k1 => $v1) { if (isset($v1['name'])) { $otherName[] = $v1['name']; } } if ($otherName) { $result[$key] = implode('、', $otherName); } else { $result[$key] = $other; } } } } if (isset($this->config['expand']) && $this->config['expand']) { $result['expand'] = Dever::call($this->config['expand'], $result); $this->expand = true; } return $result; } private function export() { $result = false; if (isset($this->config['export'])) { $result = array(); foreach ($this->config['export'] as $k => $v) { $func = $this->getFunc($k, $v, 300); if ($func) { $result[$k] = $v; } } } return $result; } private function search(&$where) { $search = Dever::input('search'); $list_search = $result = array(); $this->setting('search', $list_search, false, 'text'); if ($list_search) { foreach ($list_search as $v) { if ($v['type'] != 'hidden') { $result[] = $v; } if ($search) { 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; } } } } } return $result; } private function button($key = 'button') { $result = array(); if (empty($this->config[$key])) { $num = 0; if (isset($this->db->config['manage']['update']['field'])) { $num = count($this->db->config['manage']['update']['field']); } elseif (isset($this->db->config['struct']) && $this->db->config['struct']) { $num = count($this->db->config['struct']); } $fast = 'fast'; if ($num > 8) { $fast = ''; } if ($key == 'button') { $this->config[$key] = array('新增' => $fast . 'add'); } else { $this->config[$key] = array('编辑' => $fast . 'edit', '删除' => 'recycle'); } } $sort = 1; 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 == 'delete') { if ($key == 'button') { if (isset($this->config['layout'])) { continue; } $this->selection = true; } $icon = 'Delete'; $button = 'danger'; } elseif ($v == 'recycle') { if ($key == 'button') { if (isset($this->config['layout'])) { continue; } $this->selection = true; } $icon = 'Delete'; $button = 'danger'; } elseif ($v == 'oper') { if ($key == 'button') { if (isset($this->config['layout'])) { continue; } $this->selection = true; } $icon = 'Notification'; $button = 'warning'; } elseif ($v == 'api') { if ($key == 'button') { if (isset($this->config['layout'])) { continue; } $this->selection = true; } $icon = 'Notification'; $button = 'warning'; } elseif ($v == 'link') { $icon = 'Link'; $button = 'success'; } elseif ($v == 'route') { $icon = 'Link'; $button = 'success'; } elseif ($v == 'recover') { $icon = 'CirclePlus'; $button = 'info'; } else { continue; } # 权限验证 $sort++; $func = $this->getFunc($v, $k, $sort, $p); if (!$func) { continue; } if ($i) { $icon = $i; } $result[] = array ( 'name' => $k, 'type' => $v, 'param' => $p, 'icon' => $icon, 'button' => $button, 'func' => $func, ); if (!$this->recycler && $v == 'recycle') { $this->recycler = true; } } return $result; } }