index.html 29 KB

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