123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123 |
- <?php
- namespace app\doc\controller;
- class Index
- {
- private $config = [];
- private $token = '';
- public function __construct()
- {
- $this->config = require_once($this->app_path().'/Config.php');
- $this->docModel = new \app\doc\Doc($this->config);
- $this->copyPlugin();
- $token = cache('ajaxToken');
- if(empty($token)){
- $token = md5(md5(date('Y-m-d H:i:s').GetRandStr(8)));
- cache('ajaxToken',$token,1800);
- }
- $this->token = $token;
- }
- /**
- * @title: 检查是否有文档所需的js和css,没有则复制到static目录下
- * @desc: 描述
- * @return {*}
- * @author: Rock
- * @method: POST
- * @Date: 2022-12-15 11:44:21
- */
- private function copyPlugin()
- {
- $docPluginPath = $this->app_path().'plugin';
- $publicPath = $this->root_path().'public'.DS;
- if(!file_exists($publicPath.'plugin')){
- CopyDir($docPluginPath,$publicPath.'plugin');
- }
- }
- /**
- * @title: 文档访问地址
- * @desc: 描述
- * @param {*} $path
- * @return {*}
- * @author: Rock
- * @method: POST
- * @Date: 2022-12-15 11:45:06
- */
- public function index($path='admin')
- {
- return view('index/index',['path'=>$path,'token'=>$this->token]);
- }
- /**
- * @title: 获取文件下的控制器
- * @desc: 描述
- * @param {*} $path
- * @param {*} $type
- * @param {*} $token
- * @return {*}
- * @author: Rock
- * @method: POST
- * @Date: 2022-12-15 11:45:27
- */
- public function getList($path='',$type='folder',$token='')
- {
- if($token!=$this->token){
- return res(2,"无效请求,获取失败");
- }
- if(empty($path)){
- $path = $this->app_path().'controller';
- }elseif(false === strpos($path,$this->root_path())){
- $path = $this->root_path().'app/'.$path.'/controller';
- }
- $list = $this->docModel->getList($path,$type);
- return json($list);
- }
- /**
- * @title: 获取接口详细信息
- * @desc: 描述
- * @param {*} $class
- * @param {*} $action
- * @param {*} $token
- * @return {*}
- * @author: Rock
- * @method: POST
- * @Date: 2022-12-15 11:45:43
- */
- public function getInfo($class,$action,$token='')
- {
- if($token!=$this->token){
- return res(2,"无效请求,获取失败");
- }
- $info = $this->docModel->get_api_detail($class,$action);
- return json($info);
- }
- /**
- * @title: 定义APP目录
- * @desc: 描述
- * @return {*}
- * @author: Rock
- * @method: POST
- * @Date: 2022-12-15 11:45:57
- */
- private function app_path()
- {
- if(function_exists('app_path')){
- return app_path();
- }else{
- return APP_PATH;
- }
- }
- /**
- * @title: 定义根目录
- * @desc: 描述
- * @return {*}
- * @author: Rock
- * @method: POST
- * @Date: 2022-12-15 11:46:13
- */
- private function root_path()
- {
- if(function_exists('root_path')){
- return root_path();
- }else{
- ROOT_PATH;
- }
- }
- }
|