修改了历史回答导出pdf的bug,让表格数据能完全展示

This commit is contained in:
moon 2025-10-14 10:23:54 +08:00
parent 9fc56b7393
commit f092d0e77e
1 changed files with 66 additions and 8 deletions

View File

@ -173,28 +173,70 @@
//
const originalMaxHeight = timelineContainer.value.style.maxHeight
const originalOverflow = timelineContainer.value.style.overflow
const originalTableStyles: { table: HTMLElement; styles: Record<string, string> }[] = []
//
//
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