Data.php 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. <?php namespace Manage\Api\Page;
  2. use Dever;
  3. use Manage\Lib\Page;
  4. use Manage\Lib\Util;
  5. # 数据获取
  6. class Data extends Page
  7. {
  8. private $expand = false;
  9. public function __construct($load = '')
  10. {
  11. parent::__construct('list', $load);
  12. }
  13. public function list()
  14. {
  15. if ($this->menu && $this->menu['show'] == 1 && !$this->getFunc('list', '列表', 1)) {
  16. Dever::error('无访问权限');
  17. }
  18. $data['title'] = $this->config['title'] ?? '';
  19. $data['recycler'] = $this->recycler;
  20. $where = [];
  21. if (isset($this->config['where']) && $this->config['where']) {
  22. foreach ($this->config['where'] as $k => $v) {
  23. if (is_numeric($k) || $k == $v) {
  24. $where[$v] = Dever::load(Util::class)->request($v);
  25. } else {
  26. $where[$k] = $this->getShow($v, []);
  27. }
  28. }
  29. }
  30. $data['button'] = $this->button('button', $where);
  31. $data = array_merge($data, $this->out($where));
  32. $data['total'] = Dever::page('total');
  33. $data['height'] = $this->config['height'] ?? '100%';
  34. $data['type'] = $this->config['type'] ?? 'table';
  35. $data['desc'] = $this->config['desc'] ?? '';
  36. $data['layout'] = $this->config['layout'] ?? [];
  37. $data['exportButton'] = $this->export();
  38. $data['show'] = [
  39. 'selection' => $this->config['selection'] ?? false,
  40. 'expand' => $this->expand,
  41. 'index' => $this->config['index'] ?? false,
  42. ];
  43. $this->column($data);
  44. return $data;
  45. }
  46. public function out($where)
  47. {
  48. $set = $this->config['set'] ?? [];
  49. $data['field'] = $data['head'] = [];
  50. $data['search'] = $this->search($where);
  51. $ids = Dever::input('ids');
  52. if ($ids) {
  53. $where['id'] = ['in', $ids];
  54. }
  55. $set['num'] = Dever::input('pgnum', '', '', 10);
  56. $order_col = Dever::input('order_col');
  57. if ($order_col) {
  58. $order_value = Dever::input('order_value');
  59. if ($order_value) {
  60. $set['order'] = $order_col . ' ' . $order_value . ', id desc';
  61. }
  62. }
  63. $data['filter'] = [];
  64. if (isset($this->config['filter'])) {
  65. $data['filter'] = Dever::call($this->config['filter'], [$where]);
  66. if ($data['filter']) {
  67. $filter = Dever::input('filter', '', '', 0);
  68. if (isset($data['filter'][$filter])) {
  69. $where = array_merge($where, $data['filter'][$filter]['where']);
  70. }
  71. }
  72. }
  73. if (isset($this->config['data'])) {
  74. $result = Dever::call($this->config['data'], [$where, $set]);
  75. $data = array_merge($data, $result);
  76. } else {
  77. $data['field'] = $this->setting('field', $data['head'], true, 'show');
  78. $data['body'] = $this->data($where, $set);
  79. }
  80. $method = Dever::input('method');
  81. if ($method && strstr($method, '.')) {
  82. $result = Dever::call($method, [$data]);
  83. unset($data);
  84. $data['field'] = $result['head'];
  85. $data['body'] = $result['body'];
  86. }
  87. $data['stat'] = [];
  88. if (isset($this->config['stat'])) {
  89. $data['stat'] = Dever::call($this->config['stat'], [$where]);
  90. }
  91. $data['bodyButton'] = (isset($this->config['data_button']) && $this->config['data_button']) || isset($this->config['data_button_list']) ? true : false;
  92. return $data;
  93. }
  94. private function data($where, $set = [])
  95. {
  96. if (isset($this->config['tree'])) {
  97. return $this->db->tree($where, $this->config['tree'], [$this, 'handleData']);
  98. }
  99. $data = $this->db->select($where, $set);
  100. $result = [];
  101. if ($data) {
  102. foreach ($data as $k => $v) {
  103. $result[$k] = $this->handleData($k, $v);
  104. }
  105. }
  106. return $result;
  107. }
  108. public function handleData($k, $v)
  109. {
  110. $result = $v;
  111. $result['index'] = $k+1*Dever::input('pg', '', '', 1);
  112. $button = $this->button('data_button', $v);
  113. if ($button) {
  114. $result['button'] = $button;
  115. }
  116. $button = $this->button('data_button_list', $v, false);
  117. if ($button) {
  118. $result['button_list'] = $button;
  119. }
  120. # 是否保留html代码,1是保留,2是不保留
  121. $html = Dever::input('html', '', '', 1);
  122. if (isset($v['_id'])) {
  123. $result['id'] = $v['_id'];
  124. } elseif (isset($v['id'])) {
  125. $result['id'] = $v['id'];
  126. }
  127. $result['cdate'] = $v['cdate'];
  128. foreach ($this->field as $value) {
  129. $key = $value['key'];
  130. if (isset($v[$key])) {
  131. $result[$key] = $this->getValue($key, $v[$key], $v, $value);
  132. } elseif (strpos($key, '/')) {
  133. $other = $this->getOther($key, $value, $v);
  134. if ($other) {
  135. $otherName = [];
  136. foreach ($other as $k1 => $v1) {
  137. if (isset($v1['name'])) {
  138. $otherName[] = $v1['name'];
  139. }
  140. }
  141. if ($otherName) {
  142. $result[$key] = implode('、', $otherName);
  143. } else {
  144. $result[$key] = $other;
  145. }
  146. }
  147. } elseif (isset($value['show'])) {
  148. $result[$key] = $this->getShow($value['show'], $v);
  149. }
  150. if ($html == 2 && is_string($result[$key])) {
  151. $result[$key] = strip_tags($result[$key]);
  152. }
  153. }
  154. if (isset($this->config['expand']) && $this->config['expand']) {
  155. $result['expand'] = Dever::call($this->config['expand'], [$v]);
  156. $this->expand = true;
  157. }
  158. return $result;
  159. }
  160. private function export()
  161. {
  162. $result = false;
  163. if (isset($this->config['export']) && $this->config['export']) {
  164. $result = [];
  165. foreach ($this->config['export'] as $k => $v) {
  166. $func = $this->getFunc($k, $v, 300);
  167. if ($func) {
  168. $result[$k] = $v;
  169. }
  170. }
  171. }
  172. return $result;
  173. }
  174. }