From b0c151e6fdf956a3a6e1f0d98162a5adc777e474 Mon Sep 17 00:00:00 2001 From: XuZhiqiang Date: Wed, 17 Jun 2026 16:25:45 +0800 Subject: [PATCH] =?UTF-8?q?fix(@vben/web-antdv-next):=20=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E4=BB=A3=E7=A0=81=E7=94=9F=E6=88=90=E9=83=A8=E5=88=86=EF=BC=8C?= =?UTF-8?q?=E9=A2=84=E8=A7=88=E6=97=B6=E9=BC=A0=E6=A0=87=E7=A7=BB=E5=85=A5?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E6=A0=91=EF=BC=8C=E9=A2=84=E8=A7=88=E5=86=85?= =?UTF-8?q?=E5=AE=B9=E4=B8=8D=E6=98=BE=E7=A4=BA=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../infra/codegen/modules/preview-code.vue | 37 +++++++++++-------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/apps/web-antdv-next/src/views/infra/codegen/modules/preview-code.vue b/apps/web-antdv-next/src/views/infra/codegen/modules/preview-code.vue index c798a25b9..8c5d5f401 100644 --- a/apps/web-antdv-next/src/views/infra/codegen/modules/preview-code.vue +++ b/apps/web-antdv-next/src/views/infra/codegen/modules/preview-code.vue @@ -26,6 +26,7 @@ const loading = ref(false); const fileTree = ref([]); const previewFiles = ref([]); const activeKey = ref(''); +const selectedKeys = ref([]); /** 代码地图 */ const codeMap = ref>(new Map()); @@ -53,31 +54,35 @@ function removeCodeMapKey(targetKey: any) { /** 复制代码 */ async function copyCode() { const { copy } = useClipboard(); - const file = previewFiles.value.find( - (item) => item.filePath === activeKey.value, - ); + const file = findPreviewFile(activeKey.value); if (file) { await copy(file.code); message.success('复制成功'); } } -/** 文件节点点击事件 */ -function handleNodeClick(_: any[], e: any) { - if (!e.node.isLeaf) { - return; - } - - activeKey.value = e.node.key; - const file = previewFiles.value.find((item) => { - const list = activeKey.value.split('.'); +function findPreviewFile(fileKey: string) { + return previewFiles.value.find((item) => { + const list = fileKey.split('.'); // 特殊处理 - 包合并 if (list.length > 2) { const lang = list.pop(); return item.filePath === `${list.join('/')}.${lang}`; } - return item.filePath === activeKey.value; + return item.filePath === fileKey; }); +} + +/** 文件节点点击事件 */ +function handleNodeClick(_: any[], e: any) { + if (!e.node.isLeaf) { + selectedKeys.value = activeKey.value ? [activeKey.value] : []; + return; + } + + activeKey.value = String(e.node.key); + selectedKeys.value = [activeKey.value]; + const file = findPreviewFile(activeKey.value); if (!file) { return; } @@ -179,6 +184,7 @@ const [Modal, modalApi] = useVbenModal({ if (!isOpen) { // 关闭时清除代码视图缓存 codeMap.value.clear(); + selectedKeys.value = []; return; } @@ -197,6 +203,7 @@ const [Modal, modalApi] = useVbenModal({ fileTree.value = handleFiles(data); if (data.length > 0) { activeKey.value = data[0]?.filePath || ''; + selectedKeys.value = activeKey.value ? [activeKey.value] : []; const code = data[0]?.code || ''; setCodeMap(activeKey.value, code); } @@ -217,7 +224,7 @@ const [Modal, modalApi] = useVbenModal({ @@ -240,7 +247,7 @@ const [Modal, modalApi] = useVbenModal({ >