From 2762eb84840cb5a959c5a74fbd28dfd006ae9171 Mon Sep 17 00:00:00 2001 From: zhaoxiang Date: Mon, 26 Feb 2018 14:18:08 +0800 Subject: [PATCH] =?UTF-8?q?modified=20=E5=AE=8C=E6=88=90=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=E6=96=87=E6=A1=A3=E8=87=AA=E5=8A=A8=E7=94=9F=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/apiRoute.php | 4 +- application/wiki/controller/Index.php | 53 +++-- application/wiki/view/index/detail.html | 8 +- public/static/.gitignore | 2 - public/static/jsonFormater/Collapsed.gif | Bin 0 -> 215 bytes public/static/jsonFormater/Expanded.gif | Bin 0 -> 206 bytes public/static/jsonFormater/jsonFormater.css | 35 ++++ public/static/jsonFormater/jsonFormater.js | 202 ++++++++++++++++++++ 8 files changed, 278 insertions(+), 26 deletions(-) delete mode 100644 public/static/.gitignore create mode 100644 public/static/jsonFormater/Collapsed.gif create mode 100644 public/static/jsonFormater/Expanded.gif create mode 100644 public/static/jsonFormater/jsonFormater.css create mode 100644 public/static/jsonFormater/jsonFormater.js diff --git a/application/apiRoute.php b/application/apiRoute.php index 8744858..e9a5824 100644 --- a/application/apiRoute.php +++ b/application/apiRoute.php @@ -44,7 +44,7 @@ return [ 'wiki/index/errorCode', ['method' => 'get'] ], - 'detail/:hash' => [ + 'detail/:groupHash/[:hash]' => [ 'wiki/index/detail', ['method' => 'get'] ], @@ -52,6 +52,6 @@ return [ 'wiki/index/logout', ['method' => 'get'] ], - '__miss__' => ['api/Miss/index'], + '__miss__' => ['wiki/index/index'], ], ]; diff --git a/application/wiki/controller/Index.php b/application/wiki/controller/Index.php index ba387fa..cbf8c8c 100644 --- a/application/wiki/controller/Index.php +++ b/application/wiki/controller/Index.php @@ -41,19 +41,32 @@ class Index extends Base { } public function detail() { - $gid = $this->request->route('gid'); - $hash = $this->request->route('hash'); - $newList = []; - $apiList = ApiList::all(['groupId' => $gid]); - foreach ($apiList as $value) { - $newList[$value['hash']] = $value; + $this->checkLogin(); + + $groupHash = $this->request->route('groupHash'); + $hash = $this->request->route('hash', ''); + $this->appInfo['app_api_show'] = json_decode($this->appInfo['app_api_show'], true); + if (!isset($this->appInfo['app_api_show'][$groupHash]) || empty($this->appInfo['app_api_show'][$groupHash])) { + $this->error('请求非法', url('/wiki/index')); } - if ($hash) { - $detail = $newList[$hash]; + + if (!$hash) { + $hash = $this->appInfo['app_api_show'][$groupHash][0]; } else { - $detail = $apiList[0]; - $hash = $detail['hash']; + if (!in_array($hash, $this->appInfo['app_api_show'][$groupHash])) { + $this->error('请求非法', url('/wiki/index')); + } } + + $apiList = (new ApiList())->whereIn('hash', $this->appInfo['app_api_show'][$groupHash])->where(['groupHash' => $groupHash])->select(); + $apiList = Tools::buildArrFromObj($apiList); + $apiList = Tools::buildArrByNewKey($apiList, 'hash'); + + if (!$hash) { + $hash = $this->appInfo['app_api_show'][$groupHash][0]; + } + $detail = $apiList[$hash]; + $request = ApiFields::all(['hash' => $hash, 'type' => 0]); $response = ApiFields::all(['hash' => $hash, 'type' => 1]); $dataType = array( @@ -67,15 +80,19 @@ class Index extends Base { DataType::TYPE_OBJECT => 'Object', DataType::TYPE_MOBILE => 'Mobile' ); - $this->assign('request', $request); - $this->assign('response', $response); - $this->assign('dataType', $dataType); - $this->assign('apiList', $apiList); - $this->assign('detail', $detail); - $this->assign('hash', $hash); - $this->assign('gid', $gid); - return $this->fetch(); + $groupInfo = ApiGroup::get(['hash' => $groupHash])->toArray(); + + return view('', [ + 'groupInfo' => $groupInfo, + 'request' => $request, + 'response' => $response, + 'dataType' => $dataType, + 'apiList' => $apiList, + 'detail' => $detail, + 'hash' => $hash, + 'groupHash' => $groupHash + ]); } public function calculation() { diff --git a/application/wiki/view/index/detail.html b/application/wiki/view/index/detail.html index 520696f..6fd7e54 100644 --- a/application/wiki/view/index/detail.html +++ b/application/wiki/view/index/detail.html @@ -19,9 +19,9 @@
- XXX分组 + {$groupInfo['name']}
-

系统将严格过滤请求字段,并且进行全部必要认证! 系统将严格过滤请求字段,并且进行全部必要认证! 系统将严格过滤请求字段,并且进行全部必要认证! 系统将严格过滤请求字段,并且进行全部必要认证!

+

{$groupInfo['description']}

额外的细节 @@ -36,7 +36,7 @@
-

接口唯一标识:{$hash}({$detail['apiClass']})


+

接口唯一标识:{$hash}{if condition="$detail['isTest'] == 1"}({$detail['apiClass']}){/if}


接口说明 {if condition="$detail['status'] eq 0 "} diff --git a/public/static/.gitignore b/public/static/.gitignore deleted file mode 100644 index c96a04f..0000000 --- a/public/static/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -* -!.gitignore \ No newline at end of file diff --git a/public/static/jsonFormater/Collapsed.gif b/public/static/jsonFormater/Collapsed.gif new file mode 100644 index 0000000000000000000000000000000000000000..17cbc27b321c010dc7f8e118c3a9fdddd26aec9d GIT binary patch literal 215 zcmZ?wbhEHblwsgzIKsg2|NsAg|9=1Z^XJ>Quiw6Y`1tYd`wy=_et7xz&9j#;AHR5Z z<*?;Ebt__E-?BBcL(2nJ`vv(L98#90n0g_mO;!hSvb_Q_< z9gr-@P6pPH2daH3ne)P3*6N5Z+~C1j!W&@d!@1|E@Qyp3MjBCU?XCe4iv)B6G?Fz} yg{->XJ=H~1L}1#HMUGd~wx_LIba8`)+ytY~PK_RF6?^8a%vu{)+}NbZU=09HV`3Qq literal 0 HcmV?d00001 diff --git a/public/static/jsonFormater/Expanded.gif b/public/static/jsonFormater/Expanded.gif new file mode 100644 index 0000000000000000000000000000000000000000..2aa74410fc1d4b5ff2eddf807c2fea896858e81a GIT binary patch literal 206 zcmZ?wbhEHblwsgzIKsg2|NsAg|9=1Z^XJ>Quiw6Y`1tYd`wy=_et7xz&9j#;A3u0- z@9wROH*Q?KdG+-5%SWzVICkmG{xc_cZ8&sg|K1IUb}X-*y@LU42#~}I6o0ZXvNMP? z=zwHFb~3PfKTz#U$(%PmWNnV>!VM9OCA=YqF`SO~g?HRpX`~^>-?d;vh+@RN^Q}de pt32+|j2UHq`XK`Aba)o9_4yDyin+FDin{)zyDH2~alU^@T+ literal 0 HcmV?d00001 diff --git a/public/static/jsonFormater/jsonFormater.css b/public/static/jsonFormater/jsonFormater.css new file mode 100644 index 0000000..79c6909 --- /dev/null +++ b/public/static/jsonFormater/jsonFormater.css @@ -0,0 +1,35 @@ +@charset "utf-8"; +/* CSS Document */ +.jf-ObjectBrace { + color: #00AA00; + font-weight: bold; +} +.jf-ArrayBrace { + color: #0033FF; + font-weight: bold; +} +.jf-PropertyName { + color: #CC0000; + font-weight: bold; +} +.jf-String { + color: #007777; +} +.jf-Number { + color: #AA00AA; +} +.jf-Boolean { + color: #0000FF; +} +.jf-Null { + color: #0000FF; +} +.jf-Comma { + color: #000000; + font-weight: bold; +} +pre.jf-CodeContainer { + margin-top: 0; + margin-bottom: 0; + text-align: left; +} diff --git a/public/static/jsonFormater/jsonFormater.js b/public/static/jsonFormater/jsonFormater.js new file mode 100644 index 0000000..f6995b3 --- /dev/null +++ b/public/static/jsonFormater/jsonFormater.js @@ -0,0 +1,202 @@ +function JsonFormater(opt) { + this.options = $.extend({ + dom: '', + tabSize: 2, + singleTab: " ", + quoteKeys: true, + imgCollapsed: "images/Collapsed.gif", + imgExpanded: "images/Expanded.gif", + isCollapsible: true + }, opt || {}); + this.isFormated = false; + this.obj = { + _dateObj: new Date(), + _regexpObj: new RegExp() + }; + this.init(); +} +JsonFormater.prototype = { + init: function () { + this.tab = this.multiplyString(this.options.tabSize, this.options.singleTab); + this.bindEvent(); + }, + doFormat: function (json) { + var html; + var obj; + try { + if(typeof json == 'object'){ + obj = [json]; + }else{ + if (json == ""){ + json = "\"\""; + } + obj = eval("[" + json + "]"); + } + html = this.ProcessObject(obj[0], 0, false, false, false); + $(this.options.dom).addClass('jf-CodeContainer'); + $(this.options.dom).html(html); + this.isFormated = true; + } catch (e) { + alert("JSON数据格式不正确:\n" + e.message); + $(this.options.dom).html(""); + this.isFormated = false; + } + }, + bindEvent: function () { + var that = this; + $(this.options.dom).off('click','.imgToggle'); + $(this.options.dom).on('click', '.imgToggle', function () { + if (that.isFormated == false) { + return; + } + that.makeContentVisible($(this).parent().next(), !$(this).data('status')); + }); + }, + expandAll: function () { + if (this.isFormated == false) { + return; + } + var that = this; + this.traverseChildren($(this.options.dom), function(element){ + if(element.hasClass('jf-collapsible')){ + that.makeContentVisible(element, true); + } + }, 0); + }, + collapseAll: function () { + if (this.isFormated == false) { + return; + } + var that = this; + this.traverseChildren($(this.options.dom), function(element){ + if(element.hasClass('jf-collapsible')){ + that.makeContentVisible(element, false); + } + }, 0); + }, + collapseLevel: function(level){ + if (this.isFormated == false) { + return; + } + var that = this; + this.traverseChildren($(this.options.dom), function(element, depth){ + if(element.hasClass('jf-collapsible')){ + if(depth >= level){ + that.makeContentVisible(element, false); + }else{ + that.makeContentVisible(element, true); + } + } + }, 0); + + }, + isArray: function (obj) { + return obj && + typeof obj === 'object' && + typeof obj.length === 'number' && !(obj.propertyIsEnumerable('length')); + }, + getRow: function (indent, data, isPropertyContent) { + var tabs = ""; + if (!isPropertyContent) { + tabs = this.multiplyString(indent, this.tab); + } + if (data != null && data.length > 0 && data.charAt(data.length - 1) != "\n") { + data = data + "\n"; + } + return tabs + data; + }, + formatLiteral: function (literal, quote, comma, indent, isArray, style) { + if (typeof literal == 'string') { + literal = literal.split("<").join("<").split(">").join(">"); + } + var str = "" + quote + literal + quote + comma + ""; + if (isArray) str = this.getRow(indent, str); + return str; + }, + formatFunction: function (indent, obj) { + var tabs; + var i; + var funcStrArray = obj.toString().split("\n"); + var str = ""; + tabs = this.multiplyString(indent, this.tab); + for (i = 0; i < funcStrArray.length; i++) { + str += ((i == 0) ? "" : tabs) + funcStrArray[i] + "\n"; + } + return str; + }, + multiplyString: function (num, str) { + var result = ''; + for (var i = 0; i < num; i++) { + result += str; + } + return result; + }, + traverseChildren: function (element, func, depth) { + var length = element.children().length; + for (var i = 0; i < length; i++) { + this.traverseChildren(element.children().eq(i), func, depth + 1); + } + func(element, depth); + }, + makeContentVisible : function(element, visible){ + var img = element.prev().find('img'); + if(visible){ + element.show(); + img.attr('src', this.options.imgExpanded); + img.data('status', 1); + }else{ + element.hide(); + img.attr('src', this.options.imgCollapsed); + img.data('status', 0); + } + }, + ProcessObject: function (obj, indent, addComma, isArray, isPropertyContent) { + var html = ""; + var comma = (addComma) ? ", " : ""; + var type = typeof obj; + var clpsHtml = ""; + var prop; + if (this.isArray(obj)) { + if (obj.length == 0) { + html += this.getRow(indent, "[ ]" + comma, isPropertyContent); + } else { + clpsHtml = this.options.isCollapsible ? "" : ""; + html += this.getRow(indent, "[" + clpsHtml, isPropertyContent); + for (var i = 0; i < obj.length; i++) { + html += this.ProcessObject(obj[i], indent + 1, i < (obj.length - 1), true, false); + } + clpsHtml = this.options.isCollapsible ? "" : ""; + html += this.getRow(indent, clpsHtml + "]" + comma); + } + } else if (type == 'object') { + if (obj == null) { + html += this.formatLiteral("null", "", comma, indent, isArray, "Null"); + } else { + var numProps = 0; + for (prop in obj) numProps++; + if (numProps == 0) { + html += this.getRow(indent, "{ }" + comma, isPropertyContent); + } else { + clpsHtml = this.options.isCollapsible ? "" : ""; + html += this.getRow(indent, "{" + clpsHtml, isPropertyContent); + var j = 0; + for (prop in obj) { + var quote = this.options.quoteKeys ? "\"" : ""; + html += this.getRow(indent + 1, "" + quote + prop + quote + ": " + this.ProcessObject(obj[prop], indent + 1, ++j < numProps, false, true)); + } + clpsHtml = this.options.isCollapsible ? "" : ""; + html += this.getRow(indent, clpsHtml + "}" + comma); + } + } + } else if (type == 'number') { + html += this.formatLiteral(obj, "", comma, indent, isArray, "Number"); + } else if (type == 'boolean') { + html += this.formatLiteral(obj, "", comma, indent, isArray, "Boolean"); + }else if (type == 'undefined') { + html += this.formatLiteral("undefined", "", comma, indent, isArray, "Null"); + } else { + html += this.formatLiteral(obj.toString().split("\\").join("\\\\").split('"').join('\\"'), "\"", comma, indent, isArray, "String"); + } + return html; + } +};