优化API生成提示

优化后台菜单刷新
pull/294/MERGE
Karson 2021-07-21 14:51:42 +08:00
parent 80a25c9749
commit 8925cbc9f7
4 changed files with 40 additions and 52 deletions

View File

@ -22,7 +22,7 @@ class Api extends Command
->addOption('output', 'o', Option::VALUE_OPTIONAL, 'output index file name', 'api.html') ->addOption('output', 'o', Option::VALUE_OPTIONAL, 'output index file name', 'api.html')
->addOption('template', 'e', Option::VALUE_OPTIONAL, '', 'index.html') ->addOption('template', 'e', Option::VALUE_OPTIONAL, '', 'index.html')
->addOption('force', 'f', Option::VALUE_OPTIONAL, 'force override general file', false) ->addOption('force', 'f', Option::VALUE_OPTIONAL, 'force override general file', false)
->addOption('title', 't', Option::VALUE_OPTIONAL, 'document title', $site['name']) ->addOption('title', 't', Option::VALUE_OPTIONAL, 'document title', $site['name'] ?? '')
->addOption('class', 'c', Option::VALUE_OPTIONAL | Option::VALUE_IS_ARRAY, 'extend class', null) ->addOption('class', 'c', Option::VALUE_OPTIONAL | Option::VALUE_IS_ARRAY, 'extend class', null)
->addOption('language', 'l', Option::VALUE_OPTIONAL, 'language', 'zh-cn') ->addOption('language', 'l', Option::VALUE_OPTIONAL, 'language', 'zh-cn')
->addOption('addon', 'a', Option::VALUE_OPTIONAL, 'addon name', null) ->addOption('addon', 'a', Option::VALUE_OPTIONAL, 'addon name', null)
@ -83,16 +83,7 @@ class Api extends Command
} }
if (version_compare(PHP_VERSION, '7.0.0', '<')) { if (version_compare(PHP_VERSION, '7.0.0', '<')) {
if (extension_loaded('Zend OPcache')) { throw new Exception("Requires PHP version 7.0 or newer");
$configuration = opcache_get_configuration();
$directives = $configuration['directives'];
$configName = request()->isCli() ? 'opcache.enable_cli' : 'opcache.enable';
if (!$directives[$configName]) {
throw new Exception("Please make sure {$configName} is turned on, Get help:https://forum.fastadmin.net/d/1321");
}
} else {
throw new Exception("Please make sure opcache already enabled, Get help:https://forum.fastadmin.net/d/1321");
}
} }
//控制器名 //控制器名
@ -127,12 +118,10 @@ class Api extends Command
'apiurl' => $url, 'apiurl' => $url,
'language' => $language, 'language' => $language,
]; ];
try {
$builder = new Builder($classes); $builder = new Builder($classes);
$content = $builder->render($template_file, ['config' => $config, 'lang' => $lang]); $content = $builder->render($template_file, ['config' => $config, 'lang' => $lang]);
} catch (\Exception $e) {
print_r($e);
}
if (!file_put_contents($output_file, $content)) { if (!file_put_contents($output_file, $content)) {
throw new Exception('Cannot save the content to ' . $output_file); throw new Exception('Cannot save the content to ' . $output_file);
} }

View File

@ -70,11 +70,11 @@ class Builder
$headerslist = array(); $headerslist = array();
foreach ($docs['ApiHeaders'] as $params) { foreach ($docs['ApiHeaders'] as $params) {
$tr = array( $tr = array(
'name' => $params['name'], 'name' => $params['name'] ?? '',
'type' => $params['type'], 'type' => $params['type'] ?? 'string',
'sample' => isset($params['sample']) ? $params['sample'] : '', 'sample' => $params['sample'] ?? '',
'required' => isset($params['required']) ? $params['required'] : false, 'required' => $params['required'] ?? false,
'description' => isset($params['description']) ? $params['description'] : '', 'description' => $params['description'] ?? '',
); );
$headerslist[] = $tr; $headerslist[] = $tr;
} }
@ -92,10 +92,10 @@ class Builder
foreach ($docs['ApiParams'] as $params) { foreach ($docs['ApiParams'] as $params) {
$tr = array( $tr = array(
'name' => $params['name'], 'name' => $params['name'],
'type' => isset($params['type']) ? $params['type'] : 'string', 'type' => $params['type'] ?? 'string',
'sample' => isset($params['sample']) ? $params['sample'] : '', 'sample' => $params['sample'] ?? '',
'required' => isset($params['required']) ? $params['required'] : true, 'required' => $params['required'] ?? true,
'description' => isset($params['description']) ? $params['description'] : '', 'description' => $params['description'] ?? '',
); );
$paramslist[] = $tr; $paramslist[] = $tr;
} }
@ -112,11 +112,11 @@ class Builder
$headerslist = array(); $headerslist = array();
foreach ($docs['ApiReturnHeaders'] as $params) { foreach ($docs['ApiReturnHeaders'] as $params) {
$tr = array( $tr = array(
'name' => $params['name'], 'name' => $params['name'] ?? '',
'type' => 'string', 'type' => 'string',
'sample' => isset($params['sample']) ? $params['sample'] : '', 'sample' => $params['sample'] ?? '',
'required' => isset($params['required']) && $params['required'] ? 'Yes' : 'No', 'required' => isset($params['required']) && $params['required'] ? 'Yes' : 'No',
'description' => isset($params['description']) ? $params['description'] : '', 'description' => $params['description'] ?? '',
); );
$headerslist[] = $tr; $headerslist[] = $tr;
} }
@ -133,10 +133,10 @@ class Builder
$paramslist = array(); $paramslist = array();
foreach ($st_params['ApiReturnParams'] as $params) { foreach ($st_params['ApiReturnParams'] as $params) {
$tr = array( $tr = array(
'name' => $params['name'], 'name' => $params['name'] ?? '',
'type' => isset($params['type']) ? $params['type'] : 'string', 'type' => $params['type'] ?? 'string',
'sample' => isset($params['sample']) ? $params['sample'] : '', 'sample' => $params['sample'] ?? '',
'description' => isset($params['description']) ? $params['description'] : '', 'description' => $params['description'] ?? '',
); );
$paramslist[] = $tr; $paramslist[] = $tr;
} }
@ -199,22 +199,22 @@ class Builder
$route = substr($route, 4); $route = substr($route, 4);
} }
$docsList[$section][$name] = [ $docsList[$section][$name] = [
'id' => $counter, 'id' => $counter,
'method' => is_array($docs['ApiMethod'][0]) ? $docs['ApiMethod'][0]['data'] : $docs['ApiMethod'][0], 'method' => is_array($docs['ApiMethod'][0]) ? $docs['ApiMethod'][0]['data'] : $docs['ApiMethod'][0],
'methodLabel' => $this->generateBadgeForMethod($docs), 'methodLabel' => $this->generateBadgeForMethod($docs),
'section' => $section, 'section' => $section,
'route' => $route, 'route' => $route,
'title' => is_array($docs['ApiTitle'][0]) ? $docs['ApiTitle'][0]['data'] : $docs['ApiTitle'][0], 'title' => is_array($docs['ApiTitle'][0]) ? $docs['ApiTitle'][0]['data'] : $docs['ApiTitle'][0],
'summary' => is_array($docs['ApiSummary'][0]) ? $docs['ApiSummary'][0]['data'] : $docs['ApiSummary'][0], 'summary' => is_array($docs['ApiSummary'][0]) ? $docs['ApiSummary'][0]['data'] : $docs['ApiSummary'][0],
'body' => isset($docs['ApiBody'][0]) ? is_array($docs['ApiBody'][0]) ? $docs['ApiBody'][0]['data'] : $docs['ApiBody'][0] : '', 'body' => isset($docs['ApiBody'][0]) ? (is_array($docs['ApiBody'][0]) ? $docs['ApiBody'][0]['data'] : $docs['ApiBody'][0]) : '',
'headersList' => $this->generateHeadersTemplate($docs), 'headersList' => $this->generateHeadersTemplate($docs),
'paramsList' => $this->generateParamsTemplate($docs), 'paramsList' => $this->generateParamsTemplate($docs),
'returnHeadersList' => $this->generateReturnHeadersTemplate($docs), 'returnHeadersList' => $this->generateReturnHeadersTemplate($docs),
'returnParamsList' => $this->generateReturnParamsTemplate($docs), 'returnParamsList' => $this->generateReturnParamsTemplate($docs),
'weigh' => is_array($docs['ApiWeigh'][0]) ? $docs['ApiWeigh'][0]['data'] : $docs['ApiWeigh'][0], 'weigh' => is_array($docs['ApiWeigh'][0]) ? $docs['ApiWeigh'][0]['data'] : $docs['ApiWeigh'][0],
'return' => isset($docs['ApiReturn']) ? is_array($docs['ApiReturn'][0]) ? $docs['ApiReturn'][0]['data'] : $docs['ApiReturn'][0] : '', 'return' => isset($docs['ApiReturn']) ? (is_array($docs['ApiReturn'][0]) ? $docs['ApiReturn'][0]['data'] : $docs['ApiReturn'][0]) : '',
'needLogin' => $docs['ApiPermissionLogin'][0], 'needLogin' => $docs['ApiPermissionLogin'][0],
'needRight' => $docs['ApiPermissionRight'][0], 'needRight' => $docs['ApiPermissionRight'][0],
]; ];
$counter++; $counter++;
} }

View File

@ -228,8 +228,8 @@ class Extractor
} }
$properties = $class->getDefaultProperties(); $properties = $class->getDefaultProperties();
$noNeedLogin = isset($properties['noNeedLogin']) ? is_array($properties['noNeedLogin']) ? $properties['noNeedLogin'] : [$properties['noNeedLogin']] : []; $noNeedLogin = isset($properties['noNeedLogin']) ? (is_array($properties['noNeedLogin']) ? $properties['noNeedLogin'] : [$properties['noNeedLogin']]) : [];
$noNeedRight = isset($properties['noNeedRight']) ? is_array($properties['noNeedRight']) ? $properties['noNeedRight'] : [$properties['noNeedRight']] : []; $noNeedRight = isset($properties['noNeedRight']) ? (is_array($properties['noNeedRight']) ? $properties['noNeedRight'] : [$properties['noNeedRight']]) : [];
preg_match_all("/\*[\s]+(.*)(\\r\\n|\\r|\\n)/U", str_replace('/**', '', $docblockMethod), $methodArr); preg_match_all("/\*[\s]+(.*)(\\r\\n|\\r|\\n)/U", str_replace('/**', '', $docblockMethod), $methodArr);
preg_match_all("/\*[\s]+(.*)(\\r\\n|\\r|\\n)/U", str_replace('/**', '', $dockblockClass), $classArr); preg_match_all("/\*[\s]+(.*)(\\r\\n|\\r|\\n)/U", str_replace('/**', '', $dockblockClass), $classArr);

View File

@ -443,7 +443,6 @@ function _init() {
//parent_li.addClass('active'); //parent_li.addClass('active');
//Fix the layout in case the sidebar stretches over the height of the window //Fix the layout in case the sidebar stretches over the height of the window
// _this.layout.fix(); // _this.layout.fix();
_this.layout.fixSidebar();
}); });
parent_li.addClass('treeview-open'); parent_li.addClass('treeview-open');
} else { } else {