Skip to content

Commit 6760bd6

Browse files
committed
feat(Debug.vue): integrate vue-json-pretty for improved JSON display and add loading state during API calls
1 parent 98cb6bd commit 6760bd6

3 files changed

Lines changed: 34 additions & 15 deletions

File tree

packages/business/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
"qs": "catalog:",
2626
"tiny-emitter": "catalog:",
2727
"vue": "catalog:",
28+
"vue-json-pretty": "catalog:",
2829
"vue-json-viewer": "catalog:",
2930
"vue-virtual-scroller": "catalog:",
3031
"vuex": "catalog:"

packages/business/src/views/data-server/Debug.vue

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,17 @@ import { useI18n } from '@tap/i18n'
77
import {
88
computed,
99
inject,
10+
markRaw,
1011
onBeforeUnmount,
1112
onMounted,
1213
ref,
14+
shallowRef,
1315
watch,
1416
type Ref,
1517
} from 'vue'
18+
import VueJsonPretty from 'vue-json-pretty'
1619
import getTemplate from './template'
20+
import 'vue-json-pretty/lib/styles.css'
1721
1822
interface Props {
1923
urlList?: any[]
@@ -33,10 +37,11 @@ const workerStatus = ref('')
3337
const token = ref<Record<string, any>>({})
3438
const templateType = ref('java')
3539
const debugMethod = ref('GET')
36-
const debugResult = ref('')
40+
const debugResult = shallowRef({})
3741
const debugHttpInfo = ref<Record<string, any>>({})
3842
const templates = ref<Record<string, string>>({})
3943
const intervalId = ref()
44+
const loading = ref(false)
4045
4146
const urlsMap = computed(() => {
4247
return props.urlList.reduce((acc: Record<string, string>, item) => {
@@ -71,7 +76,7 @@ const getAPIServerToken = async (
7176
}
7277
7378
const reflshToken = () => {
74-
getAPIServerToken((token: Record<string, any>) => {
79+
return getAPIServerToken((token: Record<string, any>) => {
7580
templates.value = getTemplate(props.host + form.value.path, token)
7681
})
7782
}
@@ -110,9 +115,13 @@ const getWorkers = () => {
110115
const debugData = async () => {
111116
const params = props.debugParams
112117
const method = debugMethod.value
118+
loading.value = true
119+
113120
if (method === 'TOKEN') {
114-
reflshToken()
115-
debugResult.value = JSON.stringify(token.value, null, 2)
121+
await reflshToken().finally(() => {
122+
loading.value = false
123+
})
124+
debugResult.value = markRaw(token.value)
116125
debugHttpInfo.value = {
117126
httpCode: 200,
118127
}
@@ -176,14 +185,15 @@ const debugData = async () => {
176185
httpCode: debugInfo.httpCode,
177186
}
178187
delete debugInfo.httpCode
179-
debugResult.value = debugInfo ? JSON.stringify(debugInfo, null, 2) : ''
188+
debugResult.value = markRaw(debugInfo)
180189
} catch (error: any) {
181190
const result = error?.response?.data
182-
debugResult.value = result ? JSON.stringify(result, null, 2) : ''
191+
debugResult.value = markRaw(result)
183192
debugHttpInfo.value = {
184193
httpCode: result?.code || result?.httpCode,
185194
}
186195
}
196+
loading.value = false
187197
}
188198
189199
const getParamType = (key: string) => {
@@ -250,7 +260,11 @@ onMounted(() => {
250260
</template>
251261
</el-input>
252262

253-
<ElButton type="primary" :disabled="debugDisabled" @click="debugData"
263+
<ElButton
264+
type="primary"
265+
:disabled="debugDisabled"
266+
:loading="loading"
267+
@click="debugData"
254268
>{{ $t('public_button_submit') }}
255269
</ElButton>
256270
</div>
@@ -270,14 +284,15 @@ onMounted(() => {
270284
>{{ debugHttpInfo.httpCode }}</el-tag
271285
>
272286
</div>
273-
<VCodeEditor
274-
class="rounded-lg"
275-
height="280"
276-
lang="json"
277-
:options="{ printMargin: false, readOnly: true, wrap: 'free' }"
278-
:value="debugResult"
287+
<VueJsonPretty
288+
class="bg-light rounded-xl p-2 pr-0"
289+
:data="debugResult"
290+
:height="280"
291+
virtual
292+
show-icon
293+
:show-line="false"
279294
/>
280-
<div class="position-relative mt-4 mb-3">
295+
<div class="position-relative mt-4">
281296
<div
282297
class="fs-7 fw-sub font-color-dark flex align-center"
283298
style="line-height: 36px; height: 36px"
@@ -299,7 +314,7 @@ onMounted(() => {
299314
</ElTabs>
300315
</div>
301316
<VCodeEditor
302-
class="rounded-lg"
317+
class="rounded-xl ace-one-dark overflow-hidden"
303318
height="280"
304319
:lang="templateType"
305320
:options="{ printMargin: false, readOnly: true, wrap: 'free' }"

pnpm-lock.yaml

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)