From 1d41b6b3a7048b8c37750277c2401444c4752493 Mon Sep 17 00:00:00 2001 From: Argo-Lenovo Date: Thu, 22 Dec 2016 15:23:44 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E4=B8=80=E4=B8=AA=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=E8=87=AA=E5=8A=A8=E7=94=9F=E6=88=90=E6=96=87=E6=A1=A3?= =?UTF-8?q?=E9=A1=B5=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Bootstrap.Admin/Bootstrap.Admin.csproj | 2 + Bootstrap.Admin/Content/html/api.html | 50 ++++++++++++++ Bootstrap.Admin/Scripts/_references.js | Bin 4072 -> 4144 bytes Bootstrap.Admin/Scripts/apidoc.js | 92 +++++++++++++++++++++++++ 4 files changed, 144 insertions(+) create mode 100644 Bootstrap.Admin/Content/html/api.html create mode 100644 Bootstrap.Admin/Scripts/apidoc.js diff --git a/Bootstrap.Admin/Bootstrap.Admin.csproj b/Bootstrap.Admin/Bootstrap.Admin.csproj index bbe3c979..e02265f1 100644 --- a/Bootstrap.Admin/Bootstrap.Admin.csproj +++ b/Bootstrap.Admin/Bootstrap.Admin.csproj @@ -108,6 +108,7 @@ + @@ -215,6 +216,7 @@ + diff --git a/Bootstrap.Admin/Content/html/api.html b/Bootstrap.Admin/Content/html/api.html new file mode 100644 index 00000000..8eef6a95 --- /dev/null +++ b/Bootstrap.Admin/Content/html/api.html @@ -0,0 +1,50 @@ + + + + + + + 单元测试网页 + + + + + + + + + + + + + + + diff --git a/Bootstrap.Admin/Scripts/_references.js b/Bootstrap.Admin/Scripts/_references.js index 8cf7b06845d5336fe8da9fe9a3984762568333c6..6b891884a3aaabbca541f7196901378f51b1bebf 100644 GIT binary patch delta 28 jcmaDMzd>Px05^9cLjgl3LkdGaL-J%pX4}mI+&5SNcj5=k delta 12 Tcmdm>@Iror0Qcqy?i(xsAh`sU diff --git a/Bootstrap.Admin/Scripts/apidoc.js b/Bootstrap.Admin/Scripts/apidoc.js new file mode 100644 index 00000000..8b8135f6 --- /dev/null +++ b/Bootstrap.Admin/Scripts/apidoc.js @@ -0,0 +1,92 @@ +$(function () { + $.extend({ + "format": function (source, params) { + if (params === undefined) { + return source; + } + if (arguments.length > 2 && params.constructor !== Array) { + params = $.makeArray(arguments).slice(1); + } + if (params.constructor !== Array) { + params = [params]; + } + $.each(params, function (i, n) { + source = source.replace(new RegExp("\\{" + i + "\\}", "g"), function () { + return n; + }); + }); + return source; + } + }); + + var ajax = function (options) { + options = $.extend({ + test: false, + div: undefined, + anonymous: false, + title: '未录入', + url: '', + method: 'get', + data: '', + headers: {}, + success: function (result) { + }, + error: function (textStatus, errorThrown) { + } + }, options); + if (options.url == '') { + document.writeln("请求地址丢失!"); + return; + } + $.ajax({ + url: '../../' + options.url, + data: options.data, + type: options.method, + headers: options.headers, + success: function (result) { + if (!options.test) { + var $body = $('body'); + $body.append('
'); + var $section = $body.find('section').last(); + $section.append($.format('

{0}

', options.title)); + $section.append($.format('
{0}
', options.url)); + $section.append($.format('
{0}
', options.anonymous ? "允许" : "不允许")); + $section.append($.format('
{0}
', JSON.stringify(options.headers))); + $section.append($.format('
{0}
', options.method)); + $section.append($.format('
{0}
', JSON.stringify(options.data))); + $section.append($.format('
{0}
', JSON.stringify(result))); + $section.append('
'); + $section.append($.format('
', JSON.stringify(options), JSON.stringify(options.data))); + $section.append('
') + options.success(result); + } + else { + if (options.div) { + options.div.html($.format('
{0}
', JSON.stringify(result))).show(); + } + } + }, + error: function (XMLHttpRequest, textStatus, errorThrown) { + var $body = $('body'); + var $section = $body.find('section').last(); + $section.append($.format('
textStatus:{0}
', textStatus)); + $section.append($.format('
errorThrown:{0}
', errorThrown)); + options.error(textStatus, errorThrown); + } + }); + }; + + $('body').on('click', 'button', function () { + var $input = $(this).parent().prev(); + var options = $.extend(JSON.parse($input.attr('data-val')), { data: JSON.parse($input.val()) }, { test: true, div: $(this).parent().parent().next() }); + ajax(options); + }); + + ajax({ + title: '用户登陆调用接口', + anonymous: true, + url: 'api/login', method: 'POST', data: { userName: 'Test', password: '1' }, success: function (result) { + ajax({ title: '用户登陆信息接口', url: 'api/login', method: 'GET', headers: { Token: result.Token } }); + } + }); +}); \ No newline at end of file