index.html 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581
  1. <!DOCTYPE html>
  2. <html lang="{$config.language}">
  3. <head>
  4. <meta charset="utf-8">
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7. <meta name="description" content="">
  8. <title>{$config.title}</title>
  9. <!-- Bootstrap Core CSS -->
  10. <link href="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
  11. <!-- Plugin CSS -->
  12. <link href="https://cdn.staticfile.org/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet">
  13. <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
  14. <!--[if lt IE 9]>
  15. <script src="https://cdn.staticfile.org/html5shiv/3.7.3/html5shiv.min.js"></script>
  16. <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
  17. <![endif]-->
  18. <style type="text/css">
  19. body {
  20. padding-top: 70px; margin-bottom: 15px;
  21. -webkit-font-smoothing: antialiased;
  22. -moz-osx-font-smoothing: grayscale;
  23. font-family: "Roboto", "SF Pro SC", "SF Pro Display", "SF Pro Icons", "PingFang SC", BlinkMacSystemFont, -apple-system, "Segoe UI", "Microsoft Yahei", "Ubuntu", "Cantarell", "Fira Sans", "Droid Sans", "Helvetica Neue", "Helvetica", "Arial", sans-serif;
  24. font-weight: 400;
  25. }
  26. h2 { font-size: 1.6em; }
  27. hr { margin-top: 10px; }
  28. .tab-pane { padding-top: 10px; }
  29. .mt0 { margin-top: 0px; }
  30. .footer { font-size: 12px; color: #666; }
  31. .label { display: inline-block; min-width: 65px; padding: 0.3em 0.6em 0.3em; }
  32. .string { color: green; }
  33. .number { color: darkorange; }
  34. .boolean { color: blue; }
  35. .null { color: magenta; }
  36. .key { color: red; }
  37. .popover { max-width: 400px; max-height: 400px; overflow-y: auto;}
  38. .list-group.panel > .list-group-item {
  39. }
  40. .list-group-item:last-child {
  41. border-radius:0;
  42. }
  43. h4.panel-title a {
  44. font-weight:normal;
  45. font-size:14px;
  46. }
  47. h4.panel-title a .text-muted {
  48. font-size:12px;
  49. font-weight:normal;
  50. font-family: 'Verdana';
  51. }
  52. #sidebar {
  53. width: 220px;
  54. position: fixed;
  55. margin-left: -240px;
  56. overflow-y:auto;
  57. }
  58. #sidebar > .list-group {
  59. margin-bottom:0;
  60. }
  61. #sidebar > .list-group > a{
  62. text-indent:0;
  63. }
  64. #sidebar .child {
  65. border:1px solid #ddd;
  66. border-bottom:none;
  67. }
  68. #sidebar .child > a {
  69. border:0;
  70. }
  71. #sidebar .list-group a.current {
  72. background:#f5f5f5;
  73. }
  74. @media (max-width: 1620px){
  75. #sidebar {
  76. margin:0;
  77. }
  78. #accordion {
  79. padding-left:235px;
  80. }
  81. }
  82. @media (max-width: 768px){
  83. #sidebar {
  84. display: none;
  85. }
  86. #accordion {
  87. padding-left:0px;
  88. }
  89. }
  90. .label-primary {
  91. background-color: #248aff;
  92. }
  93. </style>
  94. </head>
  95. <body>
  96. <!-- Fixed navbar -->
  97. <div class="navbar navbar-default navbar-fixed-top" role="navigation">
  98. <div class="container">
  99. <div class="navbar-header">
  100. <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
  101. <span class="sr-only">Toggle navigation</span>
  102. <span class="icon-bar"></span>
  103. <span class="icon-bar"></span>
  104. <span class="icon-bar"></span>
  105. </button>
  106. <a class="navbar-brand" href="./" target="_blank">{$config.title}</a>
  107. </div>
  108. <div class="navbar-collapse collapse">
  109. <form class="navbar-form navbar-right">
  110. <div class="form-group">
  111. Token:
  112. </div>
  113. <div class="form-group">
  114. <input type="text" class="form-control input-sm" data-toggle="tooltip" title="{$lang.Tokentips}" placeholder="token" id="token" />
  115. </div>
  116. <div class="form-group">
  117. Apiurl:
  118. </div>
  119. <div class="form-group">
  120. <input id="apiUrl" type="text" class="form-control input-sm" data-toggle="tooltip" title="{$lang.Apiurltips}" placeholder="https://api.mydomain.com" value="{$config.apiurl}" />
  121. </div>
  122. <div class="form-group">
  123. <button type="button" class="btn btn-success btn-sm" data-toggle="tooltip" title="{$lang.Savetips}" id="save_data">
  124. <span class="glyphicon glyphicon-floppy-disk" aria-hidden="true"></span>
  125. </button>
  126. </div>
  127. </form>
  128. </div><!--/.nav-collapse -->
  129. </div>
  130. </div>
  131. <div class="container">
  132. <!-- menu -->
  133. <div id="sidebar">
  134. <div class="list-group panel">
  135. {foreach name="docslist" id="docs"}
  136. <a href="#{$key}" class="list-group-item" data-toggle="collapse" data-parent="#sidebar">{$key} <i class="fa fa-caret-down"></i></a>
  137. <div class="child collapse" id="{$key}">
  138. {foreach name="docs" id="api" }
  139. <a href="javascript:;" data-id="{$api.id}" class="list-group-item">{$api.title}</a>
  140. {/foreach}
  141. </div>
  142. {/foreach}
  143. </div>
  144. </div>
  145. <div class="panel-group" id="accordion">
  146. {foreach name="docslist" id="docs"}
  147. <h2>{$key}</h2>
  148. <hr>
  149. {foreach name="docs" id="api" }
  150. <div class="panel panel-default">
  151. <div class="panel-heading" id="heading-{$api.id}">
  152. <h4 class="panel-title">
  153. <span class="label {$api.method_label}">{$api.method|strtoupper}</span>
  154. <a data-toggle="collapse" data-parent="#accordion{$api.id}" href="#collapseOne{$api.id}"> {$api.title} <span class="text-muted">{$api.route}</span></a>
  155. </h4>
  156. </div>
  157. <div id="collapseOne{$api.id}" class="panel-collapse collapse">
  158. <div class="panel-body">
  159. <!-- Nav tabs -->
  160. <ul class="nav nav-tabs" id="doctab{$api.id}">
  161. <li class="active"><a href="#info{$api.id}" data-toggle="tab">{$lang.Info}</a></li>
  162. <li><a href="#sandbox{$api.id}" data-toggle="tab">{$lang.Sandbox}</a></li>
  163. <li><a href="#sample{$api.id}" data-toggle="tab">{$lang.Sampleoutput}</a></li>
  164. </ul>
  165. <!-- Tab panes -->
  166. <div class="tab-content">
  167. <div class="tab-pane active" id="info{$api.id}">
  168. <div class="well">
  169. {$api.summary}
  170. </div>
  171. <div class="panel panel-default">
  172. <div class="panel-heading"><strong>{$lang.Headers}</strong></div>
  173. <div class="panel-body">
  174. {if $api.headerslist}
  175. <table class="table table-hover">
  176. <thead>
  177. <tr>
  178. <th>{$lang.Name}</th>
  179. <th>{$lang.Type}</th>
  180. <th>{$lang.Required}</th>
  181. <th>{$lang.Description}</th>
  182. </tr>
  183. </thead>
  184. <tbody>
  185. {foreach name="api['headerslist']" id="header"}
  186. <tr>
  187. <td>{$header.name}</td>
  188. <td>{$header.type}</td>
  189. <td>{$header.required?'是':'否'}</td>
  190. <td>{$header.description}</td>
  191. </tr>
  192. {/foreach}
  193. </tbody>
  194. </table>
  195. {else /}
  196. {/if}
  197. </div>
  198. </div>
  199. <div class="panel panel-default">
  200. <div class="panel-heading"><strong>{$lang.Parameters}</strong></div>
  201. <div class="panel-body">
  202. {if $api.paramslist}
  203. <table class="table table-hover">
  204. <thead>
  205. <tr>
  206. <th>{$lang.Name}</th>
  207. <th>{$lang.Type}</th>
  208. <th>{$lang.Required}</th>
  209. <th>{$lang.Description}</th>
  210. </tr>
  211. </thead>
  212. <tbody>
  213. {foreach name="api['paramslist']" id="param"}
  214. <tr>
  215. <td>{$param.name}</td>
  216. <td>{$param.type}</td>
  217. <td>{:$param.required?'是':'否'}</td>
  218. <td>{$param.description}</td>
  219. </tr>
  220. {/foreach}
  221. </tbody>
  222. </table>
  223. {else /}
  224. {/if}
  225. </div>
  226. </div>
  227. <div class="panel panel-default">
  228. <div class="panel-heading"><strong>{$lang.Body}</strong></div>
  229. <div class="panel-body">
  230. {$api.body|default='无'}
  231. </div>
  232. </div>
  233. </div><!-- #info -->
  234. <div class="tab-pane" id="sandbox{$api.id}">
  235. <div class="row">
  236. <div class="col-md-12">
  237. {if $api.headerslist}
  238. <div class="panel panel-default">
  239. <div class="panel-heading"><strong>{$lang.Headers}</strong></div>
  240. <div class="panel-body">
  241. <div class="headers">
  242. {foreach name="api['headerslist']" id="param"}
  243. <div class="form-group">
  244. <label class="control-label" for="{$param.name}">{$param.name}</label>
  245. <input type="{$param.type}" class="form-control input-sm" id="{$param.name}" {if $param.required}required{/if} placeholder="{$param.description} - Ex: {$param.sample}" name="{$param.name}">
  246. </div>
  247. {/foreach}
  248. </div>
  249. </div>
  250. </div>
  251. {/if}
  252. <div class="panel panel-default">
  253. <div class="panel-heading"><strong>{$lang.Parameters}</strong></div>
  254. <div class="panel-body">
  255. <form enctype="application/x-www-form-urlencoded" role="form" action="{$api.route}" method="{$api.method}" name="form{$api.id}" id="form{$api.id}">
  256. {if $api.paramslist}
  257. {foreach name="api['paramslist']" id="param"}
  258. <div class="form-group">
  259. <label class="control-label" for="{$param.name}">{$param.name}</label>
  260. <input type="{$param.type}" class="form-control input-sm" id="{$param.name}" {if $param.required}required{/if} placeholder="{$param.description}{if $param.sample} - 例: {$param.sample}{/if}" name="{$param.name}">
  261. </div>
  262. {/foreach}
  263. {else /}
  264. <div class="form-group">
  265. </div>
  266. {/if}
  267. <div class="form-group">
  268. <button type="submit" class="btn btn-success send" rel="{$api.id}">{$lang.Send}</button>
  269. <button type="reset" class="btn btn-info" rel="{$api.id}">{$lang.Reset}</button>
  270. </div>
  271. </form>
  272. </div>
  273. </div>
  274. <div class="panel panel-default">
  275. <div class="panel-heading"><strong>{$lang.Response}</strong></div>
  276. <div class="panel-body">
  277. <div class="row">
  278. <div class="col-md-12" style="overflow-x:auto">
  279. <pre id="response_headers{$api.id}"></pre>
  280. <pre id="response{$api.id}"></pre>
  281. </div>
  282. </div>
  283. </div>
  284. </div>
  285. <div class="panel panel-default">
  286. <div class="panel-heading"><strong>{$lang.ReturnParameters}</strong></div>
  287. <div class="panel-body">
  288. {if $api.returnparamslist}
  289. <table class="table table-hover">
  290. <thead>
  291. <tr>
  292. <th>{$lang.Name}</th>
  293. <th>{$lang.Type}</th>
  294. <th>{$lang.Description}</th>
  295. </tr>
  296. </thead>
  297. <tbody>
  298. {foreach name="api['returnparamslist']" id="param"}
  299. <tr>
  300. <td>{$param.name}</td>
  301. <td>{$param.type}</td>
  302. <td>{$param.description}</td>
  303. </tr>
  304. {/foreach}
  305. </tbody>
  306. </table>
  307. {else /}
  308. {/if}
  309. </div>
  310. </div>
  311. </div>
  312. </div>
  313. </div><!-- #sandbox -->
  314. <div class="tab-pane" id="sample{$api.id}">
  315. <div class="row">
  316. <div class="col-md-12">
  317. <pre id="sample_response{$api.id}">{$api.return|default='无'}</pre>
  318. </div>
  319. </div>
  320. </div><!-- #sample -->
  321. </div><!-- .tab-content -->
  322. </div>
  323. </div>
  324. </div>
  325. {/foreach}
  326. {/foreach}
  327. </div>
  328. <hr>
  329. <div class="row mt0 footer">
  330. <div class="col-md-6" align="left">
  331. Generated on {:date('Y-m-d H:i:s')}
  332. </div>
  333. <div class="col-md-6" align="right">
  334. <a href="./" target="_blank">{$config.sitename}</a>
  335. </div>
  336. </div>
  337. </div> <!-- /container -->
  338. <!-- jQuery -->
  339. <script src="https://cdn.staticfile.org/jquery/2.1.4/jquery.min.js"></script>
  340. <!-- Bootstrap Core JavaScript -->
  341. <script src="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>
  342. <script type="text/javascript">
  343. function syntaxHighlight(json) {
  344. if (typeof json != 'string') {
  345. json = JSON.stringify(json, undefined, 2);
  346. }
  347. json = json.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
  348. return json.replace(/("(\\u[a-zA-Z0-9]{4}|\\[^u]|[^\\"])*"(\s*:)?|\b(true|false|null)\b|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?)/g, function (match) {
  349. var cls = 'number';
  350. if (/^"/.test(match)) {
  351. if (/:$/.test(match)) {
  352. cls = 'key';
  353. } else {
  354. cls = 'string';
  355. }
  356. } else if (/true|false/.test(match)) {
  357. cls = 'boolean';
  358. } else if (/null/.test(match)) {
  359. cls = 'null';
  360. }
  361. return '<span class="' + cls + '">' + match + '</span>';
  362. });
  363. }
  364. function prepareStr(str) {
  365. try {
  366. return syntaxHighlight(JSON.stringify(JSON.parse(str.replace(/'/g, '"')), null, 2));
  367. } catch (e) {
  368. return str;
  369. }
  370. }
  371. var storage = (function () {
  372. var uid = new Date;
  373. var storage;
  374. var result;
  375. try {
  376. (storage = window.localStorage).setItem(uid, uid);
  377. result = storage.getItem(uid) == uid;
  378. storage.removeItem(uid);
  379. return result && storage;
  380. } catch (exception) {
  381. }
  382. }());
  383. $.fn.serializeObject = function ()
  384. {
  385. var o = {};
  386. var a = this.serializeArray();
  387. $.each(a, function () {
  388. if (!this.value) {
  389. return;
  390. }
  391. if (o[this.name] !== undefined) {
  392. if (!o[this.name].push) {
  393. o[this.name] = [o[this.name]];
  394. }
  395. o[this.name].push(this.value || '');
  396. } else {
  397. o[this.name] = this.value || '';
  398. }
  399. });
  400. return o;
  401. };
  402. $(document).ready(function () {
  403. if (storage) {
  404. storage.getItem('token') && $('#token').val(storage.getItem('token'));
  405. storage.getItem('apiUrl') && $('#apiUrl').val(storage.getItem('apiUrl'));
  406. }
  407. $('[data-toggle="tooltip"]').tooltip({
  408. placement: 'bottom'
  409. });
  410. $(window).on("resize", function(){
  411. $("#sidebar").css("max-height", $(window).height()-80);
  412. });
  413. $(window).trigger("resize");
  414. $(document).on("click", "#sidebar .list-group > .list-group-item", function(){
  415. $("#sidebar .list-group > .list-group-item").removeClass("current");
  416. $(this).addClass("current");
  417. });
  418. $(document).on("click", "#sidebar .child a", function(){
  419. var heading = $("#heading-"+$(this).data("id"));
  420. if(!heading.next().hasClass("in")){
  421. $("a", heading).trigger("click");
  422. }
  423. $("html,body").animate({scrollTop:heading.offset().top-70});
  424. });
  425. $('code[id^=response]').hide();
  426. $.each($('pre[id^=sample_response],pre[id^=sample_post_body]'), function () {
  427. if ($(this).html() == 'NA') {
  428. return;
  429. }
  430. var str = prepareStr($(this).html());
  431. $(this).html(str);
  432. });
  433. $("[data-toggle=popover]").popover({placement: 'right'});
  434. $('[data-toggle=popover]').on('shown.bs.popover', function () {
  435. var $sample = $(this).parent().find(".popover-content"),
  436. str = $(this).data('content');
  437. if (typeof str == "undefined" || str === "") {
  438. return;
  439. }
  440. var str = prepareStr(str);
  441. $sample.html('<pre>' + str + '</pre>');
  442. });
  443. $('body').on('click', '#save_data', function (e) {
  444. if (storage) {
  445. storage.setItem('token', $('#token').val());
  446. storage.setItem('apiUrl', $('#apiUrl').val());
  447. } else {
  448. alert('Your browser does not support local storage');
  449. }
  450. });
  451. $('body').on('click', '.send', function (e) {
  452. e.preventDefault();
  453. var form = $(this).closest('form');
  454. //added /g to get all the matched params instead of only first
  455. var matchedParamsInRoute = $(form).attr('action').match(/[^{]+(?=\})/g);
  456. var theId = $(this).attr('rel');
  457. //keep a copy of action attribute in order to modify the copy
  458. //instead of the initial attribute
  459. var url = $(form).attr('action');
  460. var method = $(form).prop('method').toLowerCase() || 'get';
  461. var formData = new FormData();
  462. $(form).find('input').each(function (i, input) {
  463. if ($(input).attr('type').toLowerCase() == 'file') {
  464. formData.append($(input).attr('name'), $(input)[0].files[0]);
  465. method = 'post';
  466. } else {
  467. formData.append($(input).attr('name'), $(input).val())
  468. }
  469. });
  470. var index, key, value;
  471. if (matchedParamsInRoute) {
  472. var params = {};
  473. formData.forEach(function(value, key){
  474. params[key] = value;
  475. });
  476. for (index = 0; index < matchedParamsInRoute.length; ++index) {
  477. try {
  478. key = matchedParamsInRoute[index];
  479. value = params[key];
  480. if (typeof value == "undefined")
  481. value = "";
  482. url = url.replace("\{" + key + "\}", value);
  483. formData.delete(key);
  484. } catch (err) {
  485. console.log(err);
  486. }
  487. }
  488. }
  489. var headers = {};
  490. var token = $('#token').val();
  491. if (token.length > 0) {
  492. headers['token'] = token;
  493. }
  494. $("#sandbox" + theId + " .headers input[type=text]").each(function () {
  495. val = $(this).val();
  496. if (val.length > 0) {
  497. headers[$(this).prop('name')] = val;
  498. }
  499. });
  500. $.ajax({
  501. url: $('#apiUrl').val() + url,
  502. data: method == 'get' ? $(form).serialize() : formData,
  503. type: method,
  504. dataType: 'json',
  505. contentType: false,
  506. processData: false,
  507. headers: headers,
  508. xhrFields: {
  509. withCredentials: true
  510. },
  511. success: function (data, textStatus, xhr) {
  512. if (typeof data === 'object') {
  513. var str = JSON.stringify(data, null, 2);
  514. $('#response' + theId).html(syntaxHighlight(str));
  515. } else {
  516. $('#response' + theId).html(data || '');
  517. }
  518. $('#response_headers' + theId).html('HTTP ' + xhr.status + ' ' + xhr.statusText + '<br/><br/>' + xhr.getAllResponseHeaders());
  519. $('#response' + theId).show();
  520. },
  521. error: function (xhr, textStatus, error) {
  522. try {
  523. var str = JSON.stringify($.parseJSON(xhr.responseText), null, 2);
  524. } catch (e) {
  525. var str = xhr.responseText;
  526. }
  527. $('#response_headers' + theId).html('HTTP ' + xhr.status + ' ' + xhr.statusText + '<br/><br/>' + xhr.getAllResponseHeaders());
  528. $('#response' + theId).html(syntaxHighlight(str));
  529. $('#response' + theId).show();
  530. }
  531. });
  532. return false;
  533. });
  534. });
  535. </script>
  536. </body>
  537. </html>