api.html.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. <?php
  2. /**
  3. * The api view file of dev module of ZenTaoPMS.
  4. * @copyright Copyright 2009-2023 禅道软件(青岛)有限公司(ZenTao Software (Qingdao) Co., Ltd. www.zentao.net)
  5. * @license ZPL(https://zpl.pub/page/zplv12.html) or AGPL(https://www.gnu.org/licenses/agpl-3.0.en.html)
  6. * @author Wang Yidong<yidong@easycorp.ltd>
  7. * @package dev
  8. * @link https://www.zentao.net
  9. */
  10. namespace zin;
  11. $featureBarItems = array();
  12. foreach($lang->dev->featureBar['api'] as $key => $label)
  13. {
  14. $featureBarItems[] = array
  15. (
  16. 'text' => $label,
  17. 'active' => ($selectedModule == $key || ($key == 'index' and $selectedModule != 'restapi')),
  18. 'url' => inlink('api', "module=$key")
  19. );
  20. }
  21. $fnBuildAPIContent = function() use($selectedModule, $apis)
  22. {
  23. global $lang, $config, $app;
  24. $app->loadLang($selectedModule);
  25. $app->loadConfig($selectedModule);
  26. $contents = array();
  27. foreach($apis as $api)
  28. {
  29. $methodName = zget($api, 'name', '');
  30. $params = array();
  31. $paramTR = array();
  32. if(isset($api['param']))
  33. {
  34. foreach($api['param'] as $param)
  35. {
  36. $params[] = "{$param['var']}=[{$param['var']}]";
  37. $paramTR[] = h::tr
  38. (
  39. h::td($param['var']),
  40. h::td($param['type']),
  41. h::td($param['desc'])
  42. );
  43. }
  44. }
  45. $params = implode('&', $params);
  46. $postTR = array();
  47. if(isset($config->dev->postParams[$selectedModule][$methodName]))
  48. {
  49. foreach($config->dev->postParams[$selectedModule][$methodName] as $paramName => $paramType)
  50. {
  51. $paramDesc = '';
  52. $listKey = $paramName . 'List';
  53. if(isset($lang->$selectedModule->$paramName)) $paramDesc .= $lang->$selectedModule->$paramName . ' ';
  54. if(isset($lang->$selectedModule->$listKey)) $paramDesc .= sprintf($lang->dev->paramRange, join(' | ', array_keys($lang->$selectedModule->$listKey)));
  55. if($paramType == 'date') $paramDesc .= $lang->dev->paramDate;
  56. if($paramName == 'color') $paramDesc .= $lang->dev->paramColor;
  57. if(isset($config->$selectedModule->$methodName->requiredFields) and strpos($config->$selectedModule->$methodName->requiredFields, $paramName) !== false) $paramDesc .= "<span class='red'>*{$lang->required}</span>";
  58. if($paramName == 'product') $paramDesc .= "<span class='red'>*{$lang->required}</span>";
  59. if($paramName == 'mailto') $paramDesc .= $lang->dev->paramMailto;
  60. $postTR[] = h::tr
  61. (
  62. h::td($paramName),
  63. h::td($paramType),
  64. h::td(html($paramDesc))
  65. );
  66. }
  67. }
  68. $contents[] = div
  69. (
  70. setClass('detail'),
  71. div
  72. (
  73. setClass('detail-title font-bold'),
  74. !empty($api['post']) ? 'GET/POST' : 'GET',
  75. ' ' . helper::createLink($selectedModule, $methodName, $params, 'json')
  76. ),
  77. div
  78. (
  79. setClass('detail-content mt-3'),
  80. html(zget($api, 'doc', '')),
  81. h::table
  82. (
  83. setClass('table bordered'),
  84. h::tr(h::th($lang->dev->params), h::th($lang->dev->type), h::th($lang->dev->desc)),
  85. isset($api['param']) ? $paramTR : h::tr(h::td(set::colspan(3), $lang->dev->noParam))
  86. ),
  87. isset($config->dev->postParams[$selectedModule][$methodName]) ? h::table
  88. (
  89. setClass('table bordered'),
  90. h::caption(setClass('text-left'), $lang->dev->post),
  91. h::tr
  92. (
  93. h::th($lang->dev->params),
  94. h::th($lang->dev->type),
  95. h::th($lang->dev->desc)
  96. ),
  97. $postTR
  98. ) : null
  99. )
  100. );
  101. }
  102. return $contents;
  103. };
  104. $activeGroup = '';
  105. foreach($moduleTree as $module)
  106. {
  107. if($module->active) $activeGroup = $module->id;
  108. }
  109. h::css("
  110. .sidebar .tree [data-level=\"0\"][id=\"{$activeGroup}\"] {color: var(--color-primary-600); font-weight:bolder}
  111. .sidebar .tree [data-level=\"1\"][id=\"{$selectedModule}\"] {color: var(--color-primary-600); font-weight:bolder}
  112. ");
  113. featureBar
  114. (
  115. set::items($featureBarItems),
  116. icon(set('title', $lang->dev->apiTips), 'help')
  117. );
  118. sidebar
  119. (
  120. setClass('bg-white'),
  121. h::header(setClass('h-10 flex items-center pl-4 flex-none gap-3'), div(setClass('text-lg font-semibold flex items-center'), icon(setClass('pr-2'), 'list'), span($lang->dev->moduleList))),
  122. treeEditor(set(array('items' => $moduleTree, 'canEdit' => false, 'canDelete' => false, 'canSplit' => false)))
  123. );
  124. div
  125. (
  126. setClass('bg-white p-3'),
  127. $selectedModule ? div(setClass("module-content"), $fnBuildAPIContent()) : null
  128. );