DataTableLists.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | likeadmin快速开发前后端分离管理后台(PHP版)
  4. // +----------------------------------------------------------------------
  5. // | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
  6. // | 开源版本可自由商用,可去除界面版权logo
  7. // | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
  8. // | github下载:https://github.com/likeshop-github/likeadmin
  9. // | 访问官网:https://www.likeadmin.cn
  10. // | likeadmin团队 版权所有 拥有最终解释权
  11. // +----------------------------------------------------------------------
  12. // | author: likeadminTeam
  13. // +----------------------------------------------------------------------
  14. namespace app\adminapi\lists\tools;
  15. use app\adminapi\lists\BaseAdminDataLists;
  16. use think\facade\Db;
  17. /**
  18. * 数据表列表
  19. * Class GeneratorLists
  20. * @package app\adminapi\lists\tools
  21. */
  22. class DataTableLists extends BaseAdminDataLists
  23. {
  24. /**
  25. * @notes 查询结果
  26. * @return mixed
  27. * @author 段誉
  28. * @date 2022/6/13 18:54
  29. */
  30. public function queryResult()
  31. {
  32. $sql = 'SHOW TABLE STATUS WHERE 1=1 ';
  33. if (!empty($this->params['name'])) {
  34. $sql .= "AND name LIKE '%" . $this->params['name'] . "%'";
  35. }
  36. if (!empty($this->params['comment'])) {
  37. $sql .= "AND comment LIKE '%" . $this->params['comment'] . "%'";
  38. }
  39. return Db::query($sql);
  40. }
  41. /**
  42. * @notes 处理列表
  43. * @return array
  44. * @author 段誉
  45. * @date 2022/6/13 18:54
  46. */
  47. public function lists(): array
  48. {
  49. $lists = array_map("array_change_key_case", $this->queryResult());
  50. $offset = max(0, ($this->pageNo - 1) * $this->pageSize);
  51. $lists = array_slice($lists, $offset, $this->pageSize, true);
  52. return array_values($lists);
  53. }
  54. /**
  55. * @notes 获取数量
  56. * @return int
  57. * @author 段誉
  58. * @date 2022/6/13 18:54
  59. */
  60. public function count(): int
  61. {
  62. return count($this->queryResult());
  63. }
  64. }