Index.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. <?php
  2. namespace app\doc\controller;
  3. class Index
  4. {
  5. private $config = [];
  6. private $token = '';
  7. public function __construct()
  8. {
  9. $this->config = require_once($this->app_path().'/Config.php');
  10. $this->docModel = new \app\doc\Doc($this->config);
  11. $this->copyPlugin();
  12. $token = cache('ajaxToken');
  13. if(empty($token)){
  14. $token = md5(md5(date('Y-m-d H:i:s').GetRandStr(8)));
  15. cache('ajaxToken',$token,1800);
  16. }
  17. $this->token = $token;
  18. }
  19. /**
  20. * @title: 检查是否有文档所需的js和css,没有则复制到static目录下
  21. * @desc: 描述
  22. * @return {*}
  23. * @author: Rock
  24. * @method: POST
  25. * @Date: 2022-12-15 11:44:21
  26. */
  27. private function copyPlugin()
  28. {
  29. $docPluginPath = $this->app_path().'plugin';
  30. $publicPath = $this->root_path().'public'.DS;
  31. if(!file_exists($publicPath.'plugin')){
  32. CopyDir($docPluginPath,$publicPath.'plugin');
  33. }
  34. }
  35. /**
  36. * @title: 文档访问地址
  37. * @desc: 描述
  38. * @param {*} $path
  39. * @return {*}
  40. * @author: Rock
  41. * @method: POST
  42. * @Date: 2022-12-15 11:45:06
  43. */
  44. public function index($path='admin')
  45. {
  46. return view('index/index',['path'=>$path,'token'=>$this->token]);
  47. }
  48. /**
  49. * @title: 获取文件下的控制器
  50. * @desc: 描述
  51. * @param {*} $path
  52. * @param {*} $type
  53. * @param {*} $token
  54. * @return {*}
  55. * @author: Rock
  56. * @method: POST
  57. * @Date: 2022-12-15 11:45:27
  58. */
  59. public function getList($path='',$type='folder',$token='')
  60. {
  61. if($token!=$this->token){
  62. return res(2,"无效请求,获取失败");
  63. }
  64. if(empty($path)){
  65. $path = $this->app_path().'controller';
  66. }elseif(false === strpos($path,$this->root_path())){
  67. $path = $this->root_path().'app/'.$path.'/controller';
  68. }
  69. $list = $this->docModel->getList($path,$type);
  70. return json($list);
  71. }
  72. /**
  73. * @title: 获取接口详细信息
  74. * @desc: 描述
  75. * @param {*} $class
  76. * @param {*} $action
  77. * @param {*} $token
  78. * @return {*}
  79. * @author: Rock
  80. * @method: POST
  81. * @Date: 2022-12-15 11:45:43
  82. */
  83. public function getInfo($class,$action,$token='')
  84. {
  85. if($token!=$this->token){
  86. return res(2,"无效请求,获取失败");
  87. }
  88. $info = $this->docModel->get_api_detail($class,$action);
  89. return json($info);
  90. }
  91. /**
  92. * @title: 定义APP目录
  93. * @desc: 描述
  94. * @return {*}
  95. * @author: Rock
  96. * @method: POST
  97. * @Date: 2022-12-15 11:45:57
  98. */
  99. private function app_path()
  100. {
  101. if(function_exists('app_path')){
  102. return app_path();
  103. }else{
  104. return APP_PATH;
  105. }
  106. }
  107. /**
  108. * @title: 定义根目录
  109. * @desc: 描述
  110. * @return {*}
  111. * @author: Rock
  112. * @method: POST
  113. * @Date: 2022-12-15 11:46:13
  114. */
  115. private function root_path()
  116. {
  117. if(function_exists('root_path')){
  118. return root_path();
  119. }else{
  120. ROOT_PATH;
  121. }
  122. }
  123. }