From aba4705b8ecc999740e2b0a96c4215e04d1fafc9 Mon Sep 17 00:00:00 2001 From: lizhixian <18210040298@163.com> Date: Tue, 14 Jan 2025 17:17:30 +0800 Subject: [PATCH] =?UTF-8?q?fix:=E8=A1=A8=E5=8D=95=E6=9E=84=E5=BB=BA?= =?UTF-8?q?=E9=A1=B5=E9=9D=A2=EF=BC=8Cjson=E6=98=BE=E7=A4=BA=E5=92=8C?= =?UTF-8?q?=E7=94=9F=E6=88=90=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/views/infra/build/index.vue | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/views/infra/build/index.vue b/src/views/infra/build/index.vue index ed1091e7..2eb63b6a 100644 --- a/src/views/infra/build/index.vue +++ b/src/views/infra/build/index.vue @@ -135,7 +135,8 @@ const makeTemplate = () => { /** 复制 **/ const copy = async (text: string) => { - const { copy, copied, isSupported } = useClipboard({ source: text }) + const textToCopy = JSON.stringify(text, null, 2) + const { copy, copied, isSupported } = useClipboard({ source: textToCopy }) if (!isSupported) { message.error(t('common.copyError')) } else { @@ -149,18 +150,19 @@ const copy = async (text: string) => { /** * 代码高亮 */ -const highlightedCode = (code) => { +const highlightedCode = (code: string) => { // 处理语言和代码 let language = 'json' if (formType.value === 2) { language = 'xml' } + // debugger if (!isString(code)) { - code = JSON.stringify(code) + code = JSON.stringify(code, null, 2) } // 高亮 - const result = hljs.highlight(language, code, true) - return result.value || ' ' + const result = hljs.highlight(code, { language: language, ignoreIllegals: true }) + return result.value } /** 初始化 **/