Data.php 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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']) ? 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. # 是否保留html代码,1是保留,2是不保留
  106. $html = Dever::input('html', '', '', 1);
  107. if (isset($v['_id'])) {
  108. $result['id'] = $v['_id'];
  109. } elseif (isset($v['id'])) {
  110. $result['id'] = $v['id'];
  111. }
  112. $result['cdate'] = $v['cdate'];
  113. foreach ($this->field as $value) {
  114. $key = $value['key'];
  115. if (isset($v[$key])) {
  116. $result[$key] = $this->getValue($key, $v[$key], $v, $value);
  117. } elseif (strpos($key, '/')) {
  118. $other = $this->getOther($key, $value, $v);
  119. if ($other) {
  120. $otherName = [];
  121. foreach ($other as $k1 => $v1) {
  122. if (isset($v1['name'])) {
  123. $otherName[] = $v1['name'];
  124. }
  125. }
  126. if ($otherName) {
  127. $result[$key] = implode('、', $otherName);
  128. } else {
  129. $result[$key] = $other;
  130. }
  131. }
  132. } elseif (isset($value['show'])) {
  133. $result[$key] = $this->getShow($value['show'], $v);
  134. }
  135. if ($html == 2) {
  136. $result[$key] = strip_tags($result[$key]);
  137. }
  138. }
  139. if (isset($this->config['expand']) && $this->config['expand']) {
  140. $result['expand'] = Dever::call($this->config['expand'], [$v]);
  141. $this->expand = true;
  142. }
  143. return $result;
  144. }
  145. private function export()
  146. {
  147. $result = false;
  148. if (isset($this->config['export']) && $this->config['export']) {
  149. $result = [];
  150. foreach ($this->config['export'] as $k => $v) {
  151. $func = $this->getFunc($k, $v, 300);
  152. if ($func) {
  153. $result[$k] = $v;
  154. }
  155. }
  156. }
  157. return $result;
  158. }
  159. }