controller-reduced.txt 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <?php
  2. declare (strict_types = 1);
  3. namespace <#namespace#>;
  4. use app\common\controller\Backend;
  5. use think\annotation\route\Group;
  6. <#if (!table && !form) || methods || relation || isTree || summary#>
  7. use think\annotation\route\Route;
  8. <#endif#>
  9. <#if table || form#>
  10. use app\admin\traits\Actions;
  11. <#endif#>
  12. use <#model#> as <#modelName#>Model;
  13. <#if isTree#>
  14. use app\common\library\Tree;
  15. <#endif#>
  16. #[Group("<#group#>")]
  17. class <#controllerName#> extends Backend
  18. {
  19. <#if table || form#>
  20. <#if relation && !isTree && !summary#>
  21. use Actions{
  22. index as private _index;
  23. }
  24. <#endif#>
  25. <#if !(relation && !isTree && !summary)#>
  26. use Actions;
  27. <#endif#>
  28. <#endif#>
  29. protected function _initialize()
  30. {
  31. parent::_initialize();
  32. $this->model = new <#modelName#>Model();
  33. <#if isTree#>
  34. if(!$this->request->isPost()){
  35. $list=$this->model->select()->toArray();
  36. $parentList=$this->toTree($list);
  37. $this->assign('parentList',$parentList);
  38. }
  39. <#endif#>
  40. <#if table && isset(actionList['recyclebin'])#>
  41. $this->recyclebinColumns=[
  42. <#recyclebinField#>
  43. ];
  44. $this->recyclebinColumnsType=[
  45. <#recyclebinType#>
  46. ];
  47. <#endif#>
  48. }
  49. <#if relation || isTree || summary#>
  50. #[Route("GET,JSON","index")]
  51. public function index()
  52. {
  53. <#if relation#>
  54. $this->relationField=<#relation#>;
  55. <#endif#>
  56. <#if !isTree && !summary#>
  57. return $this->_index();
  58. <#endif#>
  59. <#if isTree || summary#>
  60. if (false === $this->request->isAjax()) {
  61. return $this->fetch();
  62. }
  63. if($this->request->post('selectpage')){
  64. return $this->selectpage();
  65. }
  66. [$where, $order, $limit, $with] = $this->buildparams();
  67. $list = $this->model
  68. ->withJoin($with,'left')
  69. ->where($where)
  70. ->order($order)
  71. ->paginate($limit);
  72. $result = [
  73. <#if summary#>
  74. 'summary' => '自定义统计信息',
  75. <#endif#>
  76. 'total' => $list->total(),
  77. <#if isTree#>
  78. 'rows' => $this->toTree($list->items())
  79. <#endif#>
  80. <#if !isTree#>
  81. 'rows' => $list->items()
  82. <#endif#>
  83. ];
  84. return json($result);
  85. <#endif#>
  86. }
  87. <#endif#>
  88. <#if isTree#>
  89. private function toTree($list)
  90. {
  91. $tree = Tree::instance();
  92. $tree->init($list, 'pid');
  93. return $tree->getTreeList($tree->getTreeArray(0), '<#treeTitle#>');
  94. }
  95. <#endif#>
  96. <#if methods#>
  97. <#methods#>
  98. <#endif#>
  99. }