index.html 29 KB

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