浏览代码

fix: bugs fixed

Acathur 5 年之前
父节点
当前提交
229c5963cc

+ 24 - 4
kaifain_v2/components/ApiDoc.vue

@@ -66,18 +66,21 @@
               table.api-params-table
                 tbody
                   tr
-                    th 错误码
+                    th.center 错误码
                     th 描述
                   tr(v-for="(value, code) in route.responses")
-                    td {{code}}
-                    td {{value.description}}
+                    td.center {{code}}
+                    td
+                      pre.in-cell(v-if="isJsonString(value.description)")
+                        code {{formatJsonString(value.description)}}
+                      span(v-else) {{value.description}}
 
 </template>
 
 <script lang="ts">
 import Vue from 'vue'
 import ParamsTable from './ParamsTable.vue'
-import { formatApiDocToRoutes } from '../helpers/apiDocHelper'
+import { formatApiDocToRoutes, isJsonString, formatJsonString } from '../helpers/apiDocHelper'
 
 export default Vue.extend({
   name: 'ApiDoc',
@@ -104,6 +107,11 @@ export default Vue.extend({
     routes(): any[] {
       return formatApiDocToRoutes(this.data)
     }
+  },
+
+  methods: {
+    isJsonString,
+    formatJsonString
   }
 })
 </script>
@@ -156,6 +164,18 @@ export default Vue.extend({
 
   pre {
     max-height: 240px;
+
+    &.in-cell {
+      max-width: calc(100vw - 10rem);
+      max-height: 112px;
+      padding: 1em;
+      background: #fafafa;
+
+      code {
+        background: inherit;
+        white-space: inherit;
+      }
+    }
   }
 
   h2 {

+ 6 - 1
kaifain_v2/components/ParamsTable.vue

@@ -16,7 +16,7 @@
             span.dash(v-for="idx in item.depth - 1") ─
           span.key {{item.name}}
         td(v-if="showType")
-          code(v-if="item.type") {{item.type}}
+          code(v-if="item.type" :style="{whiteSpace: item.type.length > 7 ? 'normal' : 'nowrap'}") {{item.type}}
           code(v-if="item.items && item.items.type !== 'object'") <{{item.items.type}}>
         td(v-if="showRequired") {{item.required ? '是' : '否'}}
         td {{item.description}}
@@ -75,6 +75,7 @@ export default Vue.extend({
   border: 1px solid #eaeaea;
   border-collapse: collapse;
   border-spacing: 0;
+  text-align: left;
 
   th,
   td {
@@ -97,6 +98,10 @@ export default Vue.extend({
     white-space: nowrap;
   }
 
+  .center {
+    text-align: center;
+  }
+
   .sub-symbol {
     opacity: 0.3;
     font-size: 0.75em;

+ 1 - 1
kaifain_v2/components/SolutionCell.vue

@@ -22,7 +22,7 @@
             .price-tag 0元用
             .small 限时免费
           .price-tag(v-else)
-            span ¥{{Number(data.min_price)}}
+            span ¥{{Number((data.min_price / 100).toFixed(2))}}
         .price-tag(v-else) 咨询
 
     .tags

+ 16 - 0
kaifain_v2/helpers/apiDocHelper.ts

@@ -13,6 +13,22 @@ export const parseApiDocFile = async (remoteUrl: string) => {
   return apiDoc
 }
 
+export const isJsonString = (input: string) => {
+  return input ? /^\{\s*".+}$/.test(input.trim()) : false
+}
+
+export const formatJsonString = (input: string) => {
+  let formatted: string
+
+  try {
+    formatted = JSON.stringify(JSON.parse(input), null, 2)
+  } catch (e) {
+    formatted = input.trim()
+  }
+
+  return formatted
+}
+
 const convertKeyValuePropertiesToArray = (obj: any) => {
   if (!obj || !Object.keys(obj).length) {
     return null

+ 3 - 2
yarn.lock

@@ -9263,12 +9263,13 @@ process@^0.11.10:
   integrity sha1-czIwDoQBYb2j5podHZGn1LwW8YI=
 
 "proginn-lib@ssh://git@www.gitinn.com:proginn/proginn-lib.git":
-  version "0.2.2"
-  resolved "ssh://git@www.gitinn.com:proginn/proginn-lib.git#c70e605fd5a72e5b4650aec3292ba6693fd4170a"
+  version "0.3.0"
+  resolved "ssh://git@www.gitinn.com:proginn/proginn-lib.git#02ea4eca47447056c1a2314f72fa929b7a6a6d10"
   dependencies:
     axios "^0.19.2"
     js-cookie "^2.2.1"
     querystring "^0.2.0"
+    semver "^7.3.2"
 
 promise-inflight@^1.0.1:
   version "1.0.1"