feat: export report as Markdown
This commit is contained in:
@ -16,13 +16,18 @@
|
||||
const error = ref('')
|
||||
const loading = ref(false)
|
||||
const loadingExportPdf = ref(false)
|
||||
const loadingExportMarkdown = ref(false)
|
||||
const reasoningContent = ref('')
|
||||
const reportContent = ref('')
|
||||
const reportHtml = computed(() =>
|
||||
marked(reportContent.value, { silent: true, gfm: true, breaks: true }),
|
||||
)
|
||||
const isExportButtonDisabled = computed(
|
||||
() => !reportContent.value || loading.value || loadingExportPdf.value,
|
||||
() =>
|
||||
!reportContent.value ||
|
||||
loading.value ||
|
||||
loadingExportPdf.value ||
|
||||
loadingExportMarkdown.value,
|
||||
)
|
||||
let pdf: jsPDF | undefined
|
||||
|
||||
@ -81,6 +86,8 @@
|
||||
duration: 5000,
|
||||
color: 'info',
|
||||
})
|
||||
// Wait for 100ms to avoid toast being blocked by PDF generation
|
||||
await new Promise((resolve) => setTimeout(resolve, 100))
|
||||
const fontUrl = '/fonts/SourceHanSansCN-VF.ttf'
|
||||
pdf.addFont(fontUrl, 'SourceHanSans', 'normal')
|
||||
pdf.setFont('SourceHanSans')
|
||||
@ -146,27 +153,63 @@
|
||||
}
|
||||
}
|
||||
|
||||
async function exportToMarkdown() {
|
||||
if (!reportContent.value) return
|
||||
|
||||
loadingExportMarkdown.value = true
|
||||
try {
|
||||
const blob = new Blob([reportContent.value], { type: 'text/markdown' })
|
||||
const url = URL.createObjectURL(blob)
|
||||
const a = document.createElement('a')
|
||||
a.href = url
|
||||
a.download = 'research-report.md'
|
||||
document.body.appendChild(a)
|
||||
a.click()
|
||||
document.body.removeChild(a)
|
||||
URL.revokeObjectURL(url)
|
||||
} catch (error) {
|
||||
console.error('Export to Markdown failed:', error)
|
||||
} finally {
|
||||
loadingExportMarkdown.value = false
|
||||
}
|
||||
}
|
||||
|
||||
defineExpose({
|
||||
generateReport,
|
||||
exportToPdf,
|
||||
exportToMarkdown,
|
||||
})
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<UCard>
|
||||
<template #header>
|
||||
<div class="flex items-center justify-between">
|
||||
<div
|
||||
class="flex flex-col sm:flex-row sm:items-center justify-between gap-2"
|
||||
>
|
||||
<h2 class="font-bold">{{ $t('researchReport.title') }}</h2>
|
||||
<UButton
|
||||
color="info"
|
||||
variant="ghost"
|
||||
icon="i-lucide-download"
|
||||
:disabled="isExportButtonDisabled"
|
||||
:loading="loadingExportPdf"
|
||||
@click="exportToPdf"
|
||||
>
|
||||
{{ $t('researchReport.exportPdf') }}
|
||||
</UButton>
|
||||
<div class="flex gap-2">
|
||||
<UButton
|
||||
color="info"
|
||||
variant="ghost"
|
||||
icon="i-lucide-download"
|
||||
:disabled="isExportButtonDisabled"
|
||||
:loading="loadingExportMarkdown"
|
||||
@click="exportToMarkdown"
|
||||
>
|
||||
{{ $t('researchReport.exportMarkdown') }}
|
||||
</UButton>
|
||||
<UButton
|
||||
color="info"
|
||||
variant="ghost"
|
||||
icon="i-lucide-download"
|
||||
:disabled="isExportButtonDisabled"
|
||||
:loading="loadingExportPdf"
|
||||
@click="exportToPdf"
|
||||
>
|
||||
{{ $t('researchReport.exportPdf') }}
|
||||
</UButton>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
|
@ -54,7 +54,7 @@
|
||||
"waiting": "Waiting for model feedback...",
|
||||
"submit": "Submit Answer",
|
||||
"error": "Error getting feedback: {0}",
|
||||
"noQuestions": "The AI model did not return any follow-up questions."
|
||||
"noQuestions": "The model did not return any follow-up questions."
|
||||
},
|
||||
"webBrowsing": {
|
||||
"title": "3. Web Browsing",
|
||||
@ -75,6 +75,7 @@
|
||||
"researchReport": {
|
||||
"title": "4. Research Report",
|
||||
"exportPdf": "Export PDF",
|
||||
"exportMarkdown": "Export Markdown",
|
||||
"sources": "Sources",
|
||||
"waiting": "Waiting for report...",
|
||||
"generating": "Generating report...",
|
||||
|
@ -75,6 +75,7 @@
|
||||
"researchReport": {
|
||||
"title": "4. 研究报告",
|
||||
"exportPdf": "导出 PDF",
|
||||
"exportMarkdown": "导出 Markdown",
|
||||
"sources": "来源",
|
||||
"waiting": "等待报告...",
|
||||
"generating": "生成报告中...",
|
||||
|
Reference in New Issue
Block a user