浏览代码

Merge branch 'develop'

star7th 9 年之前
父节点
当前提交
e953fcba34

+ 3 - 0
Application/Home/Lang/en-us.php

@@ -136,7 +136,10 @@ return array(
     'cancel'=>'Cancel',
     'inser_apidoc_template'=>'Insert apidoc template',
     'inser_database_doc_template'=>'Insert db-doc template',
+    'json_tools'=>'Json tools',
     'json_to_table'=>'Json to table',
+    'beautify_json'=>'Beautify Json',
+    'beautify_json_description'=>'Make your json more beautiful ',
     'http_test_api'=>'Api test online',
     'json_to_table_description'=>'Please paste a section of JSON, the program will automatically parse and generate JSON parameters table. This feature is suitable for the rapid preparation of API documents returned to the parameter table',
     'confirm'=>'Confirm',

+ 3 - 0
Application/Home/Lang/zh-cn.php

@@ -136,7 +136,10 @@ return array(
     'cancel'=>'取消',
     'inser_apidoc_template'=>'插入API接口模板',
     'inser_database_doc_template'=>'插入数据字典模板',
+    'json_tools'=>'JSON工具',
     'json_to_table'=>'JSON转参数表格',
+    'beautify_json'=>'JSON格式化',
+    'beautify_json_description'=>'请粘贴一段json,程序将自动以美观的方式格式化显示',
     'http_test_api'=>'在线测试API',
     'json_to_table_description'=>'请粘贴一段json,程序将自动将json解析并生成参数表格。此功能适合用于快速编写API文档的返回参数表格',
     'confirm'=>'确定',

+ 30 - 3
Application/Home/View/Page/edit.html

@@ -1,5 +1,5 @@
 <include file="Common/header" />
-<link rel="stylesheet" href="__PUBLIC__/css/page/edit.css?1.1third" />
+<link rel="stylesheet" href="__PUBLIC__/css/page/edit.css?1.1thirde" />
 <link rel="stylesheet" href="__PUBLIC__/editor.md/css/editormd.css" />
 <style type="text/css">
 
@@ -52,7 +52,17 @@
         <button id="api-doc" tabindex="5" >{$Think.Lang.inser_apidoc_template}</button>
         <button id="database-doc" tabindex="6" >{$Think.Lang.inser_database_doc_template}</button>
         <button id="more-templ" tabindex="7" >{$Think.Lang.more_templ}</button>
-        <button id="jsons" tabindex="8" style="margin-left: 100px;">{$Think.Lang.json_to_table}</button>
+<!--         <button id="jsons" tabindex="8" style="margin-left: 100px;">{$Think.Lang.json_to_table}</button> -->
+        <div class="btn-group" style="margin-left: 100px;">
+          <a class="btn dropdown-toggle" id="json-tools-btn" data-toggle="dropdown" tabindex="8" href="#">
+           {$Think.Lang.json_tools}
+            <span class="caret"></span>
+          </a>
+          <ul class="dropdown-menu">
+                <li><a id="jsons" >{$Think.Lang.json_to_table}</a></li>
+                <li><a id="beautify-json" >{$Think.Lang.beautify_json}</a></li>
+          </ul>
+        </div>
         <a href="http://runapi.showdoc.cc/" target="_blank" class="btn" tabindex="9" id="runapi">{$Think.Lang.http_test_api}</a>
     </div>
     <div id="editormd">
@@ -89,6 +99,23 @@
     <div class="editormd-dialog-mask editormd-dialog-mask-bg"></div><div class="editormd-dialog-mask editormd-dialog-mask-con"></div>
 </div>
 
+<div id="beautify-json-dialog" class="editormd-dialog editormd-preformatted-text-dialog" style="width: 780px; height: 540px;">
+
+    <div style="cursor: move;" class="editormd-dialog-header">
+        <strong class="editormd-dialog-title">{$Think.Lang.beautify_json}</strong>
+    </div>
+    <a class="fa fa-close editormd-dialog-close" href="javascript:closeDiv('#beautify-json-dialog');"></a>
+    <div class="editormd-dialog-container">
+        <textarea id="beautify-jsons-content" class="jsons" placeholder="{$Think.Lang.beautify_json_description}"></textarea>
+        
+        <div class="editormd-dialog-footer">
+            <button class="editormd-btn editormd-enter-btn">{$Think.Lang.confirm}</button>
+            <button class="editormd-btn editormd-cancel-btn" onclick="closeDiv('#beautify-json-dialog')">{$Think.Lang.cancel}</button>
+        </div>
+    </div>
+    <div class="editormd-dialog-mask editormd-dialog-mask-bg"></div><div class="editormd-dialog-mask editormd-dialog-mask-con"></div>
+</div>
+
  <div id="more-templ-modal" class="modal hide fade">
   <div class="modal-header">
     <h4>{$Think.Lang.saved_templ_list}</h4>
@@ -116,7 +143,7 @@
 <script src="__PUBLIC__/editor.md/plugins/table-dialog/table-dialog.js"></script>
 <script src="__PUBLIC__/editor.md/plugins/reference-link-dialog/reference-link-dialog.js"></script>
 
-<script src="__PUBLIC__/js/page/edit.js?v=1.1.2thirdonmopqrs"></script>
+<script src="__PUBLIC__/js/page/edit.js?v=1.1.2thirdonmopqrst"></script>
 <if condition="LANG_SET=='en-us'">
     <script src="__PUBLIC__/editor.md/languages/en.js"></script>
 </if>

+ 245 - 1
Public/css/page/edit.css

@@ -1,194 +1,388 @@
 * {
 
+
+
     padding: 0;
 
+
+
     margin: 0;
 
+
+
 }
 
 
 
+
+
+
+
 *, *:before, *:after {
 
+
+
     -webkit-box-sizing: border-box;
 
+
+
     -moz-box-sizing: border-box;
 
+
+
     box-sizing: border-box;
 
+
+
 }
 
+
+
 		body,div,dl,dt,dd,ul,ol,li,h1,h2,h3,h4,h5,h6,pre,code,form,fieldset,legend,input,textarea,p,blockquote,th,td,hr,button,article,aside,details,figcaption,figure,footer,header,hgroup,menu,nav,section{
 
+
+
     margin: 0;
 
+
+
     padding: 0;
 
+
+
 }
 
 
 
+
+
+
+
 article, aside, details, figcaption, figure, footer, header, hgroup, menu, nav, section, summary {
 
+
+
     display: block;
 
+
+
 }
 
 
 
+
+
+
+
 audio, canvas, video {
 
+
+
     display: inline-block;
 
+
+
 }
 
 
 
+
+
+
+
 img {
 
+
+
     border: none;
 
+
+
     vertical-align: middle;
 
+
+
 }
 
 
 
+
+
+
+
 ul, ol {
 
+
+
     /*list-style: none;*/
 
+
+
 }
 
 
 
+
+
+
+
 .clear {
 
+
+
     *zoom: 1;           /* for IE 6/7 */
 
+
+
 }
 
 
 
+
+
+
+
 .clear:before, .clear:after {
 
+
+
     height: 0; 
 
+
+
     content: "";
 
+
+
     font-size: 0;
 
+
+
     display: table;
 
+
+
     line-height: 0;     /* for Opera */
 
+
+
     visibility: hidden;
 
+
+
 }
 
 
 
+
+
+
+
 .clear:after {
 
+
+
     clear: both;
 
+
+
 }
 
 
 
+
+
+
+
 body {
 
+
+
     font-size: 14px;
 
+
+
     color: #666;
 
+
+
     font-family: "Microsoft YaHei", "微软雅黑", Helvetica, Tahoma, STXihei, "华文细黑", STHeiti, "Helvetica Neue", Helvetica, Tahoma, "Droid Sans", "wenquanyi micro hei", FreeSans, Arimo, Arial, SimSun, "宋体", Heiti, "黑体", sans-serif; 
 
+
+
     background: #fff;
 
+
+
     text-align: center;
 
+
+
 }
 
 
 
+
+
+
+
 #layout {
 
+
+
     text-align: left;
 
+
+
 }
 
 
 
+
+
+
+
 #layout > header, .btns {
 
+
+
     padding: 15px 0;
 
+
+
     width: 90%;
 
+
+
     margin: 0 auto;
 
+
+
 }
 
 
 
+
+
+
+
 .btns {
 
+
+
     padding-top: 0;
 
+
+
 }
 
 
 
+
+
+
+
 .btns button {
 
+
+
     padding: 2px 8px;
 
+
+
 }
 
 
 
+
+
+
+
 #layout > header > h1 {
 
+
+
     font-size: 20px;
 
+
+
     margin-bottom: 10px;
 
+
+
 }
 
 
 
+
+
+
+
 .btns button, .btn {
 
+
+
     padding: 8px 10px;
 
+
+
     background: #fff;
 
+
+
     border: 1px solid #ddd;
 
+
+
     -webkit-border-radius: 3px;
 
+
+
     border-radius: 3px;
 
+
+
     cursor: pointer;
 
+
+
     -webkit-transition: background 300ms ease-out;
 
+
+
     transition: background 300ms ease-out;
 
+
+
 }
 
 
 
+
+
+
+
 .btns button:hover, .btn:hover {
 
+
+
     background: #f6f6f6;
 
+
+
 }
 
 
 
-#json-templ{ position:fixed; float:left; top:100px; left:300px; border:2px solid #ccc; display:none; z-index:999999;}
+
+
+
+
+#json-templ,#beautify-json-dialog{ position:fixed; float:left; top:100px; left:300px; border:2px solid #ccc; display:none; z-index:999999;}
+
+
+
+
 
 
 
@@ -196,49 +390,99 @@ body {
 
 
 
+
+
+
+
 .btn-primary {
 
+
+
     background-color: #006dcc;
 
+
+
 }
 
 
 
+
+
+
+
 .btn-primary:hover {
 
+
+
     background-color: #04c;
 
+
+
 }
 
 
 
+
+
+
+
 #page_title,
 
+
+
 #cat_id,
 
+
+
 #order {
 
+
+
     height: 30px;
 
+
+
 }
 
 
 
+
+
+
+
 #cat_id ,#parent_cat_id {
 
+
+
     width: 120px;
 
+
+
 }
 
 
 
+
+
+
+
 #s_number {
 
+
+
     width: 120px;
 
+
+
     margin-right: 20px;
 
+
+
     height: 28px;
 
+
+
 }
 
+
+

+ 56 - 2
Public/js/page/edit.js

@@ -9,7 +9,7 @@ $(function() {
   if (is_showdoc_online()) {
     set_text_color( "runapi" , "red");
   };
-
+  
   /*加载目录*/
   secondCatList();
 
@@ -129,12 +129,19 @@ $(function() {
     editormd.insertValue(tmpl);
   });
   
-   /*插入JSON*/
+   /*JSON转参数表格*/
   $("#jsons").click(function() {
 	  
    $("#json-templ").show();
 	
   });
+
+   /*JSON格式美化*/
+  $("#beautify-json").click(function() {
+    
+   $("#beautify-json-dialog").show();
+  
+  });
   
   
 
@@ -174,8 +181,55 @@ $(function() {
 	});
 	
 
+$("#beautify-json-dialog .editormd-enter-btn").click(function(){
+  var data = $("#beautify-json-dialog .jsons").val();
+      try{
+          var text="\n ``` \n \{ \n"+dump(JSON.parse(data))+" \} \n\n ```\n\n";//整体加个大括号
+          //$("#beautify-json-dialog .jsons").val(text);
+          $("#beautify-json-dialog .jsons").val("");
+          editormd.insertValue(text);
+      }catch(e){
+          //非json数据直接显示
+          //$("#beautify-json-dialog .jsons").val(data);
+          $("#beautify-json-dialog .jsons").val("");
+          editormd.insertValue(data);
+      }
+    $("#beautify-json-dialog").hide();
+
+});
 //{"dgfgdfg":"gdfgdfg"}
   
+//格式化json数据
+function dump(arr,level) { 
+     var dumped_text = ""; 
+     if(!level) level = 0; 
+     
+     //The padding given at the beginning of the line. 
+     var level_padding = ""; 
+     for(var j=0;j<level+1;j++) level_padding += "     "; 
+     if(typeof(arr) == 'object') { //Array/Hashes/Objects 
+         var i=0;
+         for(var item in arr) { 
+             var value = arr[item]; 
+             if(typeof(value) == 'object') { //If it is an array, 
+                 dumped_text += level_padding + "\"" + item + "\" : \{ \n"; 
+                 dumped_text += dump(value,level+1); 
+                 dumped_text +=level_padding +"\}";
+             } else { 
+                dumped_text += level_padding + "\"" + item + "\" : \"" + value + "\""; 
+             } 
+             if(i<Object.getOwnPropertyNames(arr).length-1){
+                dumped_text+=", \n";
+             }else{
+                dumped_text+=" \n";
+             }
+             i++;
+         } 
+     } else { //Stings/Chars/Numbers etc. 
+        dumped_text = "===>"+arr+"<===("+typeof(arr)+")"; 
+     } 
+     return dumped_text; 
+}
 
   /*保存*/
   var saving = false;