Data.php 6.0 KB

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