Data.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. <?php namespace Manage\Api\Page;
  2. use Dever;
  3. use Manage\Lib\Page;
  4. # 数据获取
  5. class Data extends Page
  6. {
  7. public function __construct()
  8. {
  9. parent::__construct('list');
  10. }
  11. public function list()
  12. {
  13. $where = $data['head'] = array();
  14. $data['field'] = $this->setting('field', $data['head']);
  15. $data['search'] = $this->search($where);
  16. $data['button'] = $this->button();
  17. $data['body_button'] = $this->button('data_button');
  18. $data['body'] = $this->data($where);
  19. $data['total'] = Dever::page('total');
  20. $data['height'] = $this->config['height'] ?? '100%';
  21. $data['filter'] = $this->config['filter'] ?? 'name';
  22. $data['desc'] = $this->config['desc'] ?? '';
  23. return $data;
  24. }
  25. private function data($where)
  26. {
  27. $set['num'] = Dever::input('pgnum', '', '', 10);
  28. $data = $this->db->select($where, $set);
  29. if ($data) {
  30. foreach ($data as $k => $v) {
  31. foreach ($v as $key => $value) {
  32. if (isset($this->config['field'][$key]) && $show = Dever::isset($this->config['field'][$key], 'show')) {
  33. $data[$k][$key] = $this->getShow($show, $v);
  34. } elseif ($value && isset($this->db->config['struct'][$key]['value']) && $this->db->config['struct'][$key]['value']) {
  35. $data[$k][$key] = $this->db->value($key, $value);
  36. } elseif ($key == 'cdate') {
  37. $data[$k][$key] = date('Y-m-d H:i', $value);
  38. }
  39. }
  40. }
  41. }
  42. return $data;
  43. }
  44. private function search(&$where)
  45. {
  46. $search = Dever::input('search');
  47. $list_search = $result = array();
  48. $this->setting('search', $list_search, false, 'text');
  49. if ($list_search && $search) {
  50. foreach ($list_search as $v) {
  51. if ($v['type'] != 'hidden') {
  52. $result[] = $v;
  53. }
  54. if ($value = Dever::isset($search, $v['key'])) {
  55. if ($v['type'] == 'group') {
  56. $where[$v['key']] = array('group', $value);
  57. } elseif ($v['type'] == 'selects') {
  58. $where[$v['key']] = array('group', $value);
  59. } elseif ($v['type'] == 'like') {
  60. $where[$v['key']] = array('like', $value);
  61. } elseif ($v['type'] == 'in') {
  62. $where[$v['key']] = array('in', $value);
  63. } else {
  64. $where[$v['key']] = $value;
  65. }
  66. }
  67. }
  68. } else {
  69. $result = $list_search;
  70. }
  71. return $result;
  72. }
  73. private function button($key = 'button')
  74. {
  75. $result = array();
  76. if (empty($this->config[$key])) {
  77. if ($key == 'list_button') {
  78. $this->config[$key] = array('新增' => 'fastadd', '删除' => 'del');
  79. } else {
  80. $this->config[$key] = array('编辑' => 'fastedit', '删除' => 'del');
  81. }
  82. }
  83. foreach ($this->config[$key] as $k => $v) {
  84. $p = '';
  85. $i = '';
  86. if (is_array($v)) {
  87. if (isset($v[2])) {
  88. $i = $v[2];
  89. }
  90. if (isset($v[1])) {
  91. $p = $v[1];
  92. }
  93. $v = $v[0];
  94. }
  95. if (strstr($v, 'add')) {
  96. $icon = 'Plus';
  97. $button = 'primary';
  98. } elseif (strstr($v, 'edit')) {
  99. $icon = 'Edit';
  100. $button = 'primary';
  101. } elseif (strstr($v, 'view')) {
  102. $icon = 'View';
  103. $button = '';
  104. } elseif ($v == 'del') {
  105. $icon = 'Delete';
  106. $button = 'danger';
  107. } elseif ($v == 'oper') {
  108. $icon = 'Notification';
  109. $button = 'warning';
  110. } elseif ($v == 'link') {
  111. $icon = 'Link';
  112. $button = 'success';
  113. } elseif ($v == 'recover') {
  114. $icon = 'HelpFilled';
  115. $button = 'info';
  116. } elseif ($v == 'recycler') {
  117. $icon = 'HelpFilled';
  118. $button = 'info';
  119. }
  120. if ($i) {
  121. $icon = $i;
  122. }
  123. $result[] = array
  124. (
  125. 'name' => $k,
  126. 'type' => $v,
  127. 'param' => $p,
  128. 'icon' => $icon,
  129. 'button' => $button,
  130. );
  131. }
  132. return $result;
  133. }
  134. }