diff --git a/components/ResearchReport.vue b/components/ResearchReport.vue index 3902813..3d09ee9 100644 --- a/components/ResearchReport.vue +++ b/components/ResearchReport.vue @@ -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, })