api.html 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347
  1. <!DOCTYPE html><html lang="zh-cn"><head><meta charset="utf-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="description" content=""><title>测试的API文档</title><!-- Bootstrap Core CSS --><link href="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"><!-- Plugin CSS --><link href="https://cdn.staticfile.org/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"><!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries --><!--[if lt IE 9]><script src="https://cdn.staticfile.org/html5shiv/3.7.3/html5shiv.min.js"></script><script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script><![endif]--><style type="text/css">
  2. body {
  3. padding-top: 70px; margin-bottom: 15px;
  4. -webkit-font-smoothing: antialiased;
  5. -moz-osx-font-smoothing: grayscale;
  6. 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;
  7. font-weight: 400;
  8. }
  9. h2 { font-size: 1.2em; }
  10. hr { margin-top: 10px; }
  11. .tab-pane { padding-top: 10px; }
  12. .mt0 { margin-top: 0px; }
  13. .footer { font-size: 12px; color: #666; }
  14. .docs-list .label { display: inline-block; min-width: 65px; padding: 0.3em 0.6em 0.3em; }
  15. .string { color: green; }
  16. .number { color: darkorange; }
  17. .boolean { color: blue; }
  18. .null { color: magenta; }
  19. .key { color: red; }
  20. .popover { max-width: 400px; max-height: 400px; overflow-y: auto;}
  21. .list-group.panel > .list-group-item {
  22. }
  23. .panel-title>a{color:#777;}
  24. .label-success{background-color:#49cc90;}
  25. .panel-success{border-color: #49cc90;}
  26. .panel-success>.panel-heading{background: rgba(73,204,144,.1);}
  27. .label-primary{background-color:#61affe;}
  28. .panel-primary{border-color: #61affe;}
  29. .panel-primary>.panel-heading{background: rgba(97,175,254,.1);}
  30. .label-warning{background-color:#fca130;}
  31. .panel-warning{border-color: #fca130;}
  32. .panel-warning>.panel-heading{background: rgba(252,161,48,.1);}
  33. .label-danger{background-color:#f93e3e;}
  34. .panel-danger{border-color: #f93e3e;}
  35. .panel-danger>.panel-heading{background: rgba(249,62,62,.1);}
  36. a:focus, a:hover{text-decoration:none;}
  37. .list-group-item:last-child {
  38. border-radius:0;
  39. }
  40. h4.panel-title a {
  41. font-weight:normal;
  42. font-size:14px;
  43. }
  44. h4.panel-title a .text-muted {
  45. font-size:12px;
  46. font-weight:normal;
  47. font-family: 'Verdana';
  48. color:#3b4151;font-weight:600;
  49. }
  50. #sidebar {
  51. width: 220px;
  52. position: fixed;
  53. margin-left: -240px;
  54. overflow-y:auto;
  55. }
  56. #sidebar > .list-group {
  57. margin-bottom:0;
  58. }
  59. #sidebar > .list-group > a{
  60. text-indent:0;
  61. }
  62. #sidebar .child > a .tag{
  63. position: absolute;
  64. right: 10px;
  65. top: 11px;
  66. }
  67. #sidebar .child > a .pull-right{
  68. margin-left:3px;
  69. }
  70. #sidebar .child {
  71. border:1px solid #ddd;
  72. border-bottom:none;
  73. }
  74. #sidebar .child:last-child {
  75. border-bottom:1px solid #ddd;
  76. }
  77. #sidebar .child > a {
  78. border:0;
  79. min-height: 40px;
  80. }
  81. #sidebar .list-group a.current {
  82. background:#f5f5f5;
  83. }
  84. @media (max-width: 1620px){
  85. #sidebar {
  86. margin:0;
  87. }
  88. #accordion {
  89. padding-left:235px;
  90. }
  91. }
  92. @media (max-width: 768px){
  93. #sidebar {
  94. display: none;
  95. }
  96. #accordion {
  97. padding-left:0px;
  98. }
  99. }
  100. .label-primary {
  101. background-color: #248aff;
  102. }
  103. .docs-list .panel .panel-body .table {
  104. margin-bottom: 0;
  105. }
  106. .navbar-default{
  107. background-color:#1b1b1b;
  108. color:#fff;
  109. }
  110. .navbar-brand{
  111. color:#fff!important;
  112. }
  113. .panel-heading > strong{
  114. color:#3b4151;
  115. }
  116. .alert{padding:10px!important}
  117. </style></head><body><!-- Fixed navbar --><div class="navbar navbar-default navbar-fixed-top" role="navigation"><div class="container"><div class="navbar-header"><button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse"><span class="sr-only">Toggle navigation</span><span class="icon-bar"></span><span class="icon-bar"></span><span class="icon-bar"></span></button><a class="navbar-brand" href="./" target="_blank">测试的API文档</a></div><div class="navbar-collapse collapse"><form class="navbar-form navbar-right"><div class="form-group">
  118. Apiurl:
  119. </div><div class="form-group"><input id="apiUrl" type="text" class="form-control input-sm" data-toggle="tooltip" title="" placeholder="https://api.mydomain.com" value="" /></div><div class="form-group"><button type="button" class="btn btn-success btn-sm" data-toggle="tooltip" title="" id="save_data"><span class="glyphicon glyphicon-floppy-disk" aria-hidden="true"></span></button></div></form></div><!--/.nav-collapse --></div></div><div class="container"><!-- menu --><div id="sidebar"><div class="list-group panel"></div></div><div class="panel-group docs-list" id="accordion"></div><hr><div class="row mt0 footer"><div class="col-md-6" align="left"></div><div class="col-md-6" align="right">
  120. Generated on 2022-11-07 15:22:28<a href="./" target="_blank"></a></div></div></div><!-- /container --><!-- jQuery --><script src="https://cdn.staticfile.org/jquery/2.1.4/jquery.min.js"></script><!-- Bootstrap Core JavaScript --><script src="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script><script type="text/javascript">
  121. function syntaxHighlight(json) {
  122. if (typeof json != 'string') {
  123. json = JSON.stringify(json, undefined, 2);
  124. }
  125. json = json.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
  126. return json.replace(/("(\\u[a-zA-Z0-9]{4}|\\[^u]|[^\\"])*"(\s*:)?|\b(true|false|null)\b|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?)/g, function (match) {
  127. var cls = 'number';
  128. if (/^"/.test(match)) {
  129. if (/:$/.test(match)) {
  130. cls = 'key';
  131. } else {
  132. cls = 'string';
  133. }
  134. } else if (/true|false/.test(match)) {
  135. cls = 'boolean';
  136. } else if (/null/.test(match)) {
  137. cls = 'null';
  138. }
  139. return '<span class="' + cls + '">' + match + '</span>';
  140. });
  141. }
  142. function prepareStr(str) {
  143. try {
  144. return syntaxHighlight(JSON.stringify(JSON.parse(str.replace(/'/g, '"')), null, 2));
  145. } catch (e) {
  146. return str;
  147. }
  148. }
  149. var storage = (function () {
  150. var uid = new Date;
  151. var storage;
  152. var result;
  153. try {
  154. (storage = window.localStorage).setItem(uid, uid);
  155. result = storage.getItem(uid) == uid;
  156. storage.removeItem(uid);
  157. return result && storage;
  158. } catch (exception) {
  159. }
  160. }());
  161. $.fn.serializeObject = function ()
  162. {
  163. var o = {};
  164. var a = this.serializeArray();
  165. $.each(a, function () {
  166. if (!this.value) {
  167. return;
  168. }
  169. if (o[this.name] !== undefined) {
  170. if (!o[this.name].push) {
  171. o[this.name] = [o[this.name]];
  172. }
  173. o[this.name].push(this.value || '');
  174. } else {
  175. o[this.name] = this.value || '';
  176. }
  177. });
  178. return o;
  179. };
  180. $(document).ready(function () {
  181. if (storage) {
  182. storage.getItem('token') && $('#token').val(storage.getItem('token'));
  183. storage.getItem('apiUrl') && $('#apiUrl').val(storage.getItem('apiUrl'));
  184. }
  185. $('[data-toggle="tooltip"]').tooltip({
  186. placement: 'bottom'
  187. });
  188. $(window).on("resize", function(){
  189. $("#sidebar").css("max-height", $(window).height()-80);
  190. });
  191. $(window).trigger("resize");
  192. $(document).on("click", "#sidebar .list-group > .list-group-item", function(){
  193. $("#sidebar .list-group > .list-group-item").removeClass("current");
  194. $(this).addClass("current");
  195. });
  196. $(document).on("click", "#sidebar .child a", function(){
  197. var heading = $("#heading-"+$(this).data("id"));
  198. if(!heading.next().hasClass("in")){
  199. $("a", heading).trigger("click");
  200. }
  201. $("html,body").animate({scrollTop:heading.offset().top-70});
  202. });
  203. $('code[id^=response]').hide();
  204. $.each($('pre[id^=sample_response],pre[id^=sample_post_body]'), function () {
  205. if ($(this).html() == 'NA') {
  206. return;
  207. }
  208. var str = prepareStr($(this).html());
  209. $(this).html(str);
  210. });
  211. $("[data-toggle=popover]").popover({placement: 'right'});
  212. $('[data-toggle=popover]').on('shown.bs.popover', function () {
  213. var $sample = $(this).parent().find(".popover-content"),
  214. str = $(this).data('content');
  215. if (typeof str == "undefined" || str === "") {
  216. return;
  217. }
  218. var str = prepareStr(str);
  219. $sample.html('<pre>' + str + '</pre>');
  220. });
  221. $(document).on('click', '#save_data', function (e) {
  222. if (storage) {
  223. storage.setItem('token', $('#token').val());
  224. storage.setItem('apiUrl', $('#apiUrl').val());
  225. } else {
  226. alert('Your browser does not support local storage');
  227. }
  228. });
  229. $(document).on('click', '.btn-append', function (e) {
  230. $($("#appendtpl").html()).insertBefore($(this).closest(".panel").find(".form-group-submit"));
  231. return false;
  232. });
  233. $(document).on('click', '.btn-remove', function (e) {
  234. $(this).closest(".form-group").remove();
  235. return false;
  236. });
  237. $(document).on('keyup', '.input-custom-name', function (e) {
  238. $(this).closest(".row").find(".input-custom-value").attr("name", $(this).val());
  239. return false;
  240. });
  241. $(document).on('click', '.send', function (e) {
  242. e.preventDefault();
  243. var form = $(this).closest('form');
  244. //added /g to get all the matched params instead of only first
  245. var matchedParamsInRoute = $(form).attr('action').match(/[^{]+(?=\})/g);
  246. var theId = $(this).attr('rel');
  247. //keep a copy of action attribute in order to modify the copy
  248. //instead of the initial attribute
  249. var url = $(form).attr('action');
  250. var method = $(form).prop('method').toLowerCase() || 'get';
  251. var formData = new FormData();
  252. $(form).find('input').each(function (i, input) {
  253. if ($(input).attr('type').toLowerCase() == 'file') {
  254. formData.append($(input).attr('name'), $(input)[0].files[0]);
  255. method = 'post';
  256. } else {
  257. formData.append($(input).attr('name'), $(input).val())
  258. }
  259. });
  260. var index, key, value;
  261. if (matchedParamsInRoute) {
  262. var params = {};
  263. formData.forEach(function(value, key){
  264. params[key] = value;
  265. });
  266. for (index = 0; index < matchedParamsInRoute.length; ++index) {
  267. try {
  268. key = matchedParamsInRoute[index];
  269. value = params[key];
  270. if (typeof value == "undefined")
  271. value = "";
  272. url = url.replace("\{" + key + "\}", value);
  273. formData.delete(key);
  274. } catch (err) {
  275. console.log(err);
  276. }
  277. }
  278. }
  279. var headers = {};
  280. var token = $('#token').val();
  281. if (token.length > 0) {
  282. headers['token'] = token;
  283. }
  284. $("#sandbox" + theId + " .headers input[type=text]").each(function () {
  285. val = $(this).val();
  286. if (val.length > 0) {
  287. headers[$(this).prop('name')] = val;
  288. }
  289. });
  290. $.ajax({
  291. url: $('#apiUrl').val() + url,
  292. data: method == 'get' ? $(form).serialize() : formData,
  293. type: method,
  294. dataType: 'json',
  295. contentType: false,
  296. processData: false,
  297. headers: headers,
  298. xhrFields: {
  299. withCredentials: true
  300. },
  301. success: function (data, textStatus, xhr) {
  302. if (typeof data === 'object') {
  303. var str = JSON.stringify(data, null, 2);
  304. $('#response' + theId).html(syntaxHighlight(str));
  305. } else {
  306. $('#response' + theId).html(data || '');
  307. }
  308. $('#response_headers' + theId).html('HTTP ' + xhr.status + ' ' + xhr.statusText + '<br/><br/>' + xhr.getAllResponseHeaders());
  309. $('#response' + theId).show();
  310. },
  311. error: function (xhr, textStatus, error) {
  312. try {
  313. var str = JSON.stringify($.parseJSON(xhr.responseText), null, 2);
  314. } catch (e) {
  315. var str = xhr.responseText;
  316. }
  317. $('#response_headers' + theId).html('HTTP ' + xhr.status + ' ' + xhr.statusText + '<br/><br/>' + xhr.getAllResponseHeaders());
  318. $('#response' + theId).html(syntaxHighlight(str));
  319. $('#response' + theId).show();
  320. }
  321. });
  322. return false;
  323. });
  324. });
  325. </script><script type="text/html" id="appendtpl"><div class="form-group"><label class="control-label">自定义</label><div class="row"><div class="col-xs-4"><input type="text" class="form-control input-sm input-custom-name" placeholder="名称"></div><div class="col-xs-6"><input type="text" class="form-control input-sm input-custom-value" placeholder="值"></div><div class="col-xs-2 text-center"><a href="javascript:" class="btn btn-sm btn-danger btn-remove">删除</a></div></div></div></script></body></html>