feat: export report as Markdown
This commit is contained in:
@ -16,13 +16,18 @@
|
|||||||
const error = ref('')
|
const error = ref('')
|
||||||
const loading = ref(false)
|
const loading = ref(false)
|
||||||
const loadingExportPdf = ref(false)
|
const loadingExportPdf = ref(false)
|
||||||
|
const loadingExportMarkdown = ref(false)
|
||||||
const reasoningContent = ref('')
|
const reasoningContent = ref('')
|
||||||
const reportContent = ref('')
|
const reportContent = ref('')
|
||||||
const reportHtml = computed(() =>
|
const reportHtml = computed(() =>
|
||||||
marked(reportContent.value, { silent: true, gfm: true, breaks: true }),
|
marked(reportContent.value, { silent: true, gfm: true, breaks: true }),
|
||||||
)
|
)
|
||||||
const isExportButtonDisabled = computed(
|
const isExportButtonDisabled = computed(
|
||||||
() => !reportContent.value || loading.value || loadingExportPdf.value,
|
() =>
|
||||||
|
!reportContent.value ||
|
||||||
|
loading.value ||
|
||||||
|
loadingExportPdf.value ||
|
||||||
|
loadingExportMarkdown.value,
|
||||||
)
|
)
|
||||||
let pdf: jsPDF | undefined
|
let pdf: jsPDF | undefined
|
||||||
|
|
||||||
@ -81,6 +86,8 @@
|
|||||||
duration: 5000,
|
duration: 5000,
|
||||||
color: 'info',
|
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'
|
const fontUrl = '/fonts/SourceHanSansCN-VF.ttf'
|
||||||
pdf.addFont(fontUrl, 'SourceHanSans', 'normal')
|
pdf.addFont(fontUrl, 'SourceHanSans', 'normal')
|
||||||
pdf.setFont('SourceHanSans')
|
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({
|
defineExpose({
|
||||||
generateReport,
|
generateReport,
|
||||||
exportToPdf,
|
exportToPdf,
|
||||||
|
exportToMarkdown,
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<UCard>
|
<UCard>
|
||||||
<template #header>
|
<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>
|
<h2 class="font-bold">{{ $t('researchReport.title') }}</h2>
|
||||||
<UButton
|
<div class="flex gap-2">
|
||||||
color="info"
|
<UButton
|
||||||
variant="ghost"
|
color="info"
|
||||||
icon="i-lucide-download"
|
variant="ghost"
|
||||||
:disabled="isExportButtonDisabled"
|
icon="i-lucide-download"
|
||||||
:loading="loadingExportPdf"
|
:disabled="isExportButtonDisabled"
|
||||||
@click="exportToPdf"
|
:loading="loadingExportMarkdown"
|
||||||
>
|
@click="exportToMarkdown"
|
||||||
{{ $t('researchReport.exportPdf') }}
|
>
|
||||||
</UButton>
|
{{ $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>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
@ -54,7 +54,7 @@
|
|||||||
"waiting": "Waiting for model feedback...",
|
"waiting": "Waiting for model feedback...",
|
||||||
"submit": "Submit Answer",
|
"submit": "Submit Answer",
|
||||||
"error": "Error getting feedback: {0}",
|
"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": {
|
"webBrowsing": {
|
||||||
"title": "3. Web Browsing",
|
"title": "3. Web Browsing",
|
||||||
@ -75,6 +75,7 @@
|
|||||||
"researchReport": {
|
"researchReport": {
|
||||||
"title": "4. Research Report",
|
"title": "4. Research Report",
|
||||||
"exportPdf": "Export PDF",
|
"exportPdf": "Export PDF",
|
||||||
|
"exportMarkdown": "Export Markdown",
|
||||||
"sources": "Sources",
|
"sources": "Sources",
|
||||||
"waiting": "Waiting for report...",
|
"waiting": "Waiting for report...",
|
||||||
"generating": "Generating report...",
|
"generating": "Generating report...",
|
||||||
|
@ -75,6 +75,7 @@
|
|||||||
"researchReport": {
|
"researchReport": {
|
||||||
"title": "4. 研究报告",
|
"title": "4. 研究报告",
|
||||||
"exportPdf": "导出 PDF",
|
"exportPdf": "导出 PDF",
|
||||||
|
"exportMarkdown": "导出 Markdown",
|
||||||
"sources": "来源",
|
"sources": "来源",
|
||||||
"waiting": "等待报告...",
|
"waiting": "等待报告...",
|
||||||
"generating": "生成报告中...",
|
"generating": "生成报告中...",
|
||||||
|
Reference in New Issue
Block a user