From f092d0e77ed2ad9ec127fbd125847f3c2ed71469 Mon Sep 17 00:00:00 2001 From: moon <2623532423@qq.com> Date: Tue, 14 Oct 2025 10:23:54 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=BA=86=E5=8E=86=E5=8F=B2?= =?UTF-8?q?=E5=9B=9E=E7=AD=94=E5=AF=BC=E5=87=BApdf=E7=9A=84bug=EF=BC=8C?= =?UTF-8?q?=E8=AE=A9=E8=A1=A8=E6=A0=BC=E6=95=B0=E6=8D=AE=E8=83=BD=E5=AE=8C?= =?UTF-8?q?=E5=85=A8=E5=B1=95=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../historicalRecords/components/details.vue | 74 +++++++++++++++++-- 1 file changed, 66 insertions(+), 8 deletions(-) diff --git a/chat-client/src/views/chatweb/historicalRecords/components/details.vue b/chat-client/src/views/chatweb/historicalRecords/components/details.vue index 53cb43e..b1f67e3 100644 --- a/chat-client/src/views/chatweb/historicalRecords/components/details.vue +++ b/chat-client/src/views/chatweb/historicalRecords/components/details.vue @@ -173,28 +173,70 @@ // 保存原始样式 const originalMaxHeight = timelineContainer.value.style.maxHeight const originalOverflow = timelineContainer.value.style.overflow + const originalTableStyles: { table: HTMLElement; styles: Record }[] = [] - // 展开所有内容 + // 展开所有思考内容 + Object.keys(state.showThinking).forEach(k => (state.showThinking[k] = true)) timelineContainer.value.style.maxHeight = 'none' timelineContainer.value.style.overflow = 'visible' - Object.keys(state.showThinking).forEach(k => state.showThinking[k] = true) + + // ===== ✅ 临时修改表格样式(完全展开宽度、不压缩) ===== + const tables = timelineContainer.value.querySelectorAll('table') + tables.forEach((table: HTMLElement) => { + const computed = window.getComputedStyle(table) + originalTableStyles.push({ + table, + styles: { + maxWidth: table.style.maxWidth, + width: table.style.width, + display: table.style.display, + overflowX: table.style.overflowX, + whiteSpace: table.style.whiteSpace, + tableLayout: table.style.tableLayout, + }, + }) + + // 解除所有限制 + table.style.maxWidth = 'none' + table.style.width = 'auto' + table.style.display = 'table' + table.style.overflowX = 'visible' + table.style.whiteSpace = 'nowrap' + table.style.tableLayout = 'auto' + + // 同步列单元格样式 + const cells = table.querySelectorAll('th, td') + cells.forEach((cell: HTMLElement) => { + cell.style.whiteSpace = 'nowrap' + cell.style.wordBreak = 'keep-all' + cell.style.textOverflow = 'clip' + }) + }) await nextTick() - await new Promise(resolve => setTimeout(resolve, 50)) // 等待渲染 + await new Promise(resolve => setTimeout(resolve, 100)) // 等待渲染完成 + // 获取真实尺寸(包含展开的表格) const elementHeight = timelineContainer.value.scrollHeight const elementWidth = timelineContainer.value.scrollWidth - const opt : Html2PdfOptions = { + // 如果表格太宽,自动横向导出 + const orientation = elementWidth > elementHeight ? 'landscape' : 'portrait' + + const opt: Html2PdfOptions = { margin: 0.3, filename: `${props.conversationName}.pdf`, image: { type: 'jpeg', quality: 0.98 }, - html2canvas: { scale: 2, scrollY: -window.scrollY, windowWidth: elementWidth }, + html2canvas: { + scale: 2, + scrollY: -window.scrollY, + windowWidth: elementWidth, + }, jsPDF: { unit: 'in', format: [elementWidth / 90, elementHeight / 90] as [number, number], - orientation: 'portrait' - } + orientation, + }, } try { @@ -202,15 +244,31 @@ } catch (err) { console.error('PDF 导出失败:', err) } finally { - // 恢复原样式 + // 恢复容器样式 timelineContainer.value.style.maxHeight = originalMaxHeight timelineContainer.value.style.overflow = originalOverflow + + // 恢复表格样式 + originalTableStyles.forEach(({ table, styles }) => { + Object.keys(styles).forEach(key => { + table.style[key] = styles[key] + }) + // 恢复单元格样式 + const cells = table.querySelectorAll('th, td') + cells.forEach((cell: HTMLElement) => { + cell.style.whiteSpace = '' + cell.style.wordBreak = '' + cell.style.textOverflow = '' + }) + }) } } + + //导出为markdown格式 const handleExportMarkdown = async () => { // 原始 markdown 内容