* Optimize api page style.

This commit is contained in:
caoyanyi
2023-04-03 17:11:27 +08:00
parent 489ae36491
commit ec2e0276de
8 changed files with 169 additions and 142 deletions
+1 -1
View File
@@ -165,7 +165,7 @@ $lang->admin->menuList->message['menuOrder']['10'] = 'webhook';
$lang->admin->menuList->message['menuOrder']['20'] = 'browser';
$lang->admin->menuList->message['menuOrder']['25'] = 'setting';
$lang->admin->menuList->dev['subMenu']['api'] = array('link' => "{$lang->api->doc}|dev|api|module=index");
$lang->admin->menuList->dev['subMenu']['api'] = array('link' => "{$lang->api->doc}|dev|api|module=restapi");
$lang->admin->menuList->dev['subMenu']['db'] = array('link' => "{$lang->database}|dev|db|table=" . trim(TABLE_EFFORT, '`'));
$lang->admin->menuList->dev['subMenu']['langItem'] = array('link' => "{$lang->langItem}|dev|langitem|");
$lang->admin->menuList->dev['subMenu']['editor'] = array('link' => "{$lang->editor->common}|dev|editor|", 'subModule' => 'editor');
+2 -2
View File
@@ -889,10 +889,10 @@ class apiModel extends model
*
* @param string $table
* @param stirng $version
* @access private
* @access public
* @return array
*/
private function getDemoData($table, $version)
public function getDemoData($table, $version)
{
$file = $this->app->getAppRoot() . 'db' . DS . 'api' . DS . $version . DS . $table;
return unserialize(preg_replace_callback('#s:(\d+):"(.*?)";#s', function($match){return 's:'.strlen($match[2]).':"'.$match[2].'";';}, file_get_contents($file)));
+1 -1
View File
@@ -20,7 +20,7 @@ class dev extends control
* @access public
* @return void
*/
public function api($module = '', $apiID = 1)
public function api($module = 'restapi', $apiID = 1)
{
if($module == 'restapi') return print($this->fetch('dev', 'restAPI', "apiID=$apiID"));
+3
View File
@@ -159,3 +159,6 @@ form .table-data, #content .table-data {border: 1px solid #e2e2e3;}
.paramsTable th {text-align: left!important; font-size: 14px;}
.paramsTable td {text-align: left;}
.module-content {overflow-y: auto; padding-top: 10px;}
.module-col {padding: 0 0 0 10px;}
+17
View File
@@ -0,0 +1,17 @@
$(function()
{
setHeight();
$(window).resize(setHeight);
});
/**
* Set pane height.
*
* @access public
* @return void
*/
function setHeight()
{
var paneHeight = $(window).height() - 90;
$('#sidebar .module-tree,#mainContent .module-content').css('height', paneHeight);
}
+1 -1
View File
@@ -1169,7 +1169,7 @@ class devModel extends model
$treeMenu = array();
foreach($modules as $module) $this->doc->buildTree($treeMenu, 'restapi', 0, 853, $module, $moduleAPIs, $apiID, 0);
$menu = "<ul id='modules' class='tree' data-ride='tree' data-name='tree-lib'>" . $treeMenu[0] . '</ul>';
$menu = "<ul id='modules' class='tree menu-active-primary menu-hover-primary' data-ride='tree' data-name='tree-lib'>" . $treeMenu[0] . '</ul>';
return array($restApi, $typeList, $menu);
}
}
+126 -131
View File
@@ -9,143 +9,138 @@
* @version $Id$
* @link http://www.zentao.net
*/
include '../../common/view/header.html.php';
js::set('confirmDelete', $lang->api->confirmDelete);
?>
<?php include '../../common/view/header.html.php';?>
<?php js::set('confirmDelete', $lang->api->confirmDelete);?>
<div class="fade main-row split-row" id="mainRow">
<?php $sideWidth = common::checkNotCN() ? '270' : '238';?>
<div class="side-col" style="width:<?php echo $sideWidth;?>px" data-min-width="<?php echo $sideWidth;?>">
<div class="cell" style="min-height: 286px; overflow: visible;">
<div id='title'>
<li class='menu-title'>
<div class="title"><?php echo $this->lang->api->module;?></div>
</li>
<div class="main-row" id="mainContent">
<div class='side-col' id='sidebar'>
<div class='cell module-tree'>
<div class="panel panel-sm with-list">
<div class='panel-heading'><i class='icon-list'></i> <strong><?php echo $lang->dev->moduleList?></strong></div>
<?php echo $moduleTree;?>
</div>
<?php echo $moduleTree;?>
</div>
</div>
<div class="main-col" data-min-width="500">
<div id="mainContent" class="main-row in">
<div class="main-col col-8">
<div class="cell" id="content">
<div class="no-padding">
<div class="detail-title no-padding doc-title">
<div class="http-method label"><?php echo $api->method;?></div>
<div class="path" title="<?php echo $api->path;?>"><?php echo $api->path;?></div>
</div>
<div class="main-col main-content module-col">
<div class="main-col module-content">
<div class="cell" id="content">
<div class="no-padding">
<div class="detail-title no-padding doc-title">
<div class="http-method label"><?php echo $api->method;?></div>
<div class="path" title="<?php echo $api->path;?>"><?php echo $api->path;?></div>
</div>
<div>
<h2 class="title" title="<?php echo $api->title;?>"><?php echo $api->title;?></h2>
<div class="desc"><?php echo $api->desc;?></div>
<?php if($api->params['header']):?>
<h3 class="title"><?php echo $lang->api->header;?></h3>
<table class="table table-data paramsTable">
<thead>
<tr>
<th><?php echo $lang->api->req->name;?></th>
<th><?php echo $lang->api->req->type;?></th>
<th><?php echo $lang->api->req->required;?></th>
<th><?php echo $lang->api->req->desc;?></th>
</tr>
</thead>
<tbody>
<?php foreach($api->params['header'] as $param):?>
<tr>
<td><?php echo $param['field'];?></td>
<td>String</td>
<td><?php echo $lang->api->boolList[$param['required']];?></td>
<td><?php echo $param['desc'];?></td>
<tr>
<?php endforeach;
;?>
</tbody>
</table>
<?php endif;?>
<?php if($api->params['query']):?>
<h3 class="title"><?php echo $lang->api->query;?></h3>
<table class="table table-data paramsTable">
<thead>
<tr>
<th><?php echo $lang->api->req->name;?></th>
<th><?php echo $lang->api->req->type;?></th>
<th><?php echo $lang->api->req->required;?></th>
<th><?php echo $lang->api->req->desc;?></th>
</tr>
</thead>
<tbody>
<?php foreach($api->params['query'] as $param):?>
<tr>
<td><?php echo $param['field'];?></td>
<td>String</td>
<td><?php echo $lang->api->boolList[$param['required']];?></td>
<td><?php echo $param['desc'];?></td>
<tr>
<?php endforeach;
;?>
</tbody>
</table>
<?php endif;?>
<?php
function parseTree($data, $typeList, $level = 0)
{
global $lang;
</div>
<div>
<h2 class="title" title="<?php echo $api->title;?>"><?php echo $api->title;?></h2>
<div class="desc"><?php echo $api->desc;?></div>
<?php if($api->params['header']):?>
<h3 class="title"><?php echo $lang->api->header;?></h3>
<table class="table table-data paramsTable">
<thead>
<tr>
<th><?php echo $lang->api->req->name;?></th>
<th><?php echo $lang->api->req->type;?></th>
<th><?php echo $lang->api->req->required;?></th>
<th><?php echo $lang->api->req->desc;?></th>
</tr>
</thead>
<tbody>
<?php foreach($api->params['header'] as $param):?>
<tr>
<td><?php echo $param['field'];?></td>
<td>String</td>
<td><?php echo $lang->api->boolList[$param['required']];?></td>
<td><?php echo $param['desc'];?></td>
<tr>
<?php endforeach;
;?>
</tbody>
</table>
<?php endif;?>
<?php if($api->params['query']):?>
<h3 class="title"><?php echo $lang->api->query;?></h3>
<table class="table table-data paramsTable">
<thead>
<tr>
<th><?php echo $lang->api->req->name;?></th>
<th><?php echo $lang->api->req->type;?></th>
<th><?php echo $lang->api->req->required;?></th>
<th><?php echo $lang->api->req->desc;?></th>
</tr>
</thead>
<tbody>
<?php foreach($api->params['query'] as $param):?>
<tr>
<td><?php echo $param['field'];?></td>
<td>String</td>
<td><?php echo $lang->api->boolList[$param['required']];?></td>
<td><?php echo $param['desc'];?></td>
<tr>
<?php endforeach;
;?>
</tbody>
</table>
<?php endif;?>
<?php
function parseTree($data, $typeList, $level = 0)
{
global $lang;
$str = '<tr>';
$field = '';
for($i = 0; $i < $level; $i++) $field .= '&nbsp;&nbsp;'. ($i == $level-1 ? '∟' : '&nbsp;') . '&nbsp;&nbsp;';
$field .= $data['field'];
$str .= '<td>' . $field . '</td>';
$str .= '<td>' . zget($typeList, $data['paramsType'], '') . '</td>';
$str .= '<td class="text-center">' . zget($lang->api->boolList, $data['required'], '') . '</td>';
$str .= '<td>' . $data['desc'] . '</td>';
$str .= '</tr>';
if(isset($data['children']) && count($data['children']) > 0)
{
$level++;
foreach($data['children'] as $item) $str .= parseTree($item, $typeList, $level);
}
return $str;
}
?>
<?php if($api->params['params']):?>
<h3 class="title"><?php echo $lang->api->params;?></h3>
<table class="table table-data paramsTable">
<thead>
<tr>
<th><?php echo $lang->api->req->name;?></th>
<th class="w-50px"><?php echo $lang->api->req->type;?></th>
<th class="w-50px text-center"><?php echo $lang->api->req->required;?></th>
<th class="w-300px"><?php echo $lang->api->req->desc;?></th>
</tr>
</thead>
<tbody><?php foreach($api->params['params'] as $item) echo parseTree($item, $typeList);?></tbody>
</table>
<?php endif;?>
<?php if($api->paramsExample):?>
<h3 class="title"><?php echo $lang->api->paramsExample;?></h3>
<pre><code><?php echo $api->paramsExample;?></code></pre>
<?php endif;?>
<?php if($api->response):?>
<h3 class="title"><?php echo $lang->api->response;?></h3>
<table class="table table-data">
<thead>
<tr>
<th><?php echo $lang->api->req->name;?></th>
<th class="w-50px"><?php echo $lang->api->req->type;?></th>
<th class="w-50px text-center"><?php echo $lang->api->req->required;?></th>
<th class="w-300px"><?php echo $lang->api->req->desc;?></th>
</tr>
</thead>
<tbody>
<?php foreach($api->response as $item) echo parseTree($item, $typeList);?>
</tbody>
</table>
<?php endif;?>
<?php if($api->responseExample):?>
<h3 class='title'><?php echo $lang->api->responseExample;?></h3>
<pre><code><?php echo $api->responseExample;?></code></pre>
<?php endif;?>
</div>
$str = '<tr>';
$field = '';
for($i = 0; $i < $level; $i++) $field .= '&nbsp;&nbsp;'. ($i == $level-1 ? '∟' : '&nbsp;') . '&nbsp;&nbsp;';
$field .= $data['field'];
$str .= '<td>' . $field . '</td>';
$str .= '<td>' . zget($typeList, $data['paramsType'], '') . '</td>';
$str .= '<td class="text-center">' . zget($lang->api->boolList, $data['required'], '') . '</td>';
$str .= '<td>' . $data['desc'] . '</td>';
$str .= '</tr>';
if(isset($data['children']) && count($data['children']) > 0)
{
$level++;
foreach($data['children'] as $item) $str .= parseTree($item, $typeList, $level);
}
return $str;
}
?>
<?php if($api->params['params']):?>
<h3 class="title"><?php echo $lang->api->params;?></h3>
<table class="table table-data paramsTable">
<thead>
<tr>
<th><?php echo $lang->api->req->name;?></th>
<th class="w-50px"><?php echo $lang->api->req->type;?></th>
<th class="w-50px text-center"><?php echo $lang->api->req->required;?></th>
<th class="w-300px"><?php echo $lang->api->req->desc;?></th>
</tr>
</thead>
<tbody><?php foreach($api->params['params'] as $item) echo parseTree($item, $typeList);?></tbody>
</table>
<?php endif;?>
<?php if($api->paramsExample):?>
<h3 class="title"><?php echo $lang->api->paramsExample;?></h3>
<pre><code><?php echo $api->paramsExample;?></code></pre>
<?php endif;?>
<?php if($api->response):?>
<h3 class="title"><?php echo $lang->api->response;?></h3>
<table class="table table-data">
<thead>
<tr>
<th><?php echo $lang->api->req->name;?></th>
<th class="w-50px"><?php echo $lang->api->req->type;?></th>
<th class="w-50px text-center"><?php echo $lang->api->req->required;?></th>
<th class="w-300px"><?php echo $lang->api->req->desc;?></th>
</tr>
</thead>
<tbody>
<?php foreach($api->response as $item) echo parseTree($item, $typeList);?>
</tbody>
</table>
<?php endif;?>
<?php if($api->responseExample):?>
<h3 class='title'><?php echo $lang->api->responseExample;?></h3>
<pre><code><?php echo $api->responseExample;?></code></pre>
<?php endif;?>
</div>
</div>
</div>
+18 -6
View File
@@ -19,7 +19,8 @@ class docModel extends model
public $action;
// api doc type
const DOC_TYPE_API = 'api';
const DOC_TYPE_API = 'api';
const DOC_TYPE_REST = 'restapi';
/**
* Get library by id.
@@ -2473,10 +2474,10 @@ class docModel extends model
* @param array $moduleDocs
* @param pointer $docID
* @param int $moduleID
* @access private
* @access public
* @return string
*/
private function buildTree(&$treeMenu, $type, $objectID, $libID, $module, $moduleDocs, &$docID, $moduleID = 0)
public function buildTree(&$treeMenu, $type, $objectID, $libID, $module, $moduleDocs, &$docID, $moduleID = 0)
{
if(!isset($treeMenu[$module->id])) $treeMenu[$module->id] = '';
@@ -2490,9 +2491,13 @@ class docModel extends model
if($type == static::DOC_TYPE_API)
{
$treeMenu[$module->id] .= '<li' . ($doc->id == $docID ? ' class="active"' : ' class="doc"') . '>';
$treeMenu[$module->id] .= html::a(inlink('index', "libID=0&moduleID=0&apiID={$doc->id}"), "<i class='icon icon-file-text text-muted'></i> &nbsp;" . $doc->title, '', "data-app='{$this->app->tab}' class='doc-title' title='{$doc->title}'");
$treeMenu[$module->id] .= '</li>';
}
elseif($type == static::DOC_TYPE_REST)
{
$treeMenu[$module->id] .= '<li' . ($doc->id == $docID ? ' class="active"' : ' class="doc"') . '>';
$treeMenu[$module->id] .= html::a(inlink('api', "type=restapi&apiID={$doc->id}"), "<i class='icon icon-file-text text-muted'></i> &nbsp;" . $doc->title, '', "data-app='{$this->app->tab}' class='doc-title' title='{$doc->title}'");
$treeMenu[$module->id] .= '</li>';
}
else
@@ -2535,6 +2540,10 @@ class docModel extends model
{
$li = html::a(inlink('index', "libID=$libID&moduleID={$module->id}"), $module->name, '', "data-app='{$this->app->tab}' class='doc-title' title='{$module->name}'");
}
elseif($type == static::DOC_TYPE_REST)
{
$li = html::a('#', $module->name, '', "data-app='{$this->app->tab}' class='doc-title' title='{$module->name}'");
}
else
{
$moduleClass = common::hasPriv('tree', 'updateOrder') ? 'sort-module' : '';
@@ -2554,7 +2563,10 @@ class docModel extends model
}
if($treeMenu[$module->id])
{
$li .= '<ul>' . $treeMenu[$module->id] . '</ul>';
$class = '';
if($type == static::DOC_TYPE_REST) $class = 'class="menu-active-primary menu-hover-primary"';
$li .= "<ul $class>" . $treeMenu[$module->id] . '</ul>';
}
if(!isset($treeMenu[$module->parent])) $treeMenu[$module->parent] = '';