+
+
+ ${renderedMessages || '
暂无消息
'}
+
+
+
+
+`
+
+ fs.writeFileSync(outputPath, html, 'utf-8')
+
+ onProgress?.({
+ current: 100,
+ total: 100,
+ currentSession: sessionInfo.displayName,
+ phase: 'complete'
+ })
+
+ return { success: true }
+ } catch (e) {
+ return { success: false, error: String(e) }
+ }
+ }
+
/**
* 批量导出多个会话
*/
@@ -2145,6 +2731,7 @@ class ExportService {
if (options.format === 'chatlab-jsonl') ext = '.jsonl'
else if (options.format === 'excel') ext = '.xlsx'
else if (options.format === 'txt') ext = '.txt'
+ else if (options.format === 'html') ext = '.html'
const outputPath = path.join(sessionDir, `${safeName}${ext}`)
let result: { success: boolean; error?: string }
@@ -2156,6 +2743,8 @@ class ExportService {
result = await this.exportSessionToExcel(sessionId, outputPath, options)
} else if (options.format === 'txt') {
result = await this.exportSessionToTxt(sessionId, outputPath, options)
+ } else if (options.format === 'html') {
+ result = await this.exportSessionToHtml(sessionId, outputPath, options)
} else {
result = { success: false, error: `不支持的格式: ${options.format}` }
}
diff --git a/src/pages/ExportPage.tsx b/src/pages/ExportPage.tsx
index 87f3bfa..088c0ef 100644
--- a/src/pages/ExportPage.tsx
+++ b/src/pages/ExportPage.tsx
@@ -216,6 +216,23 @@ function ExportPage() {
return date.toLocaleDateString('zh-CN', { year: 'numeric', month: '2-digit', day: '2-digit' })
}
+ const handleFormatChange = (format: ExportOptions['format']) => {
+ setOptions((prev) => {
+ const next = { ...prev, format }
+ if (format === 'html') {
+ return {
+ ...next,
+ exportMedia: true,
+ exportImages: true,
+ exportVoices: true,
+ exportEmojis: true,
+ exportVoiceAsText: true
+ }
+ }
+ return next
+ })
+ }
+
const openExportFolder = async () => {
if (exportFolder) {
await window.electronAPI.shell.openPath(exportFolder)
@@ -249,7 +266,7 @@ function ExportPage() {
} : null
}
- if (options.format === 'chatlab' || options.format === 'chatlab-jsonl' || options.format === 'json' || options.format === 'excel' || options.format === 'txt') {
+ if (options.format === 'chatlab' || options.format === 'chatlab-jsonl' || options.format === 'json' || options.format === 'excel' || options.format === 'txt' || options.format === 'html') {
const result = await window.electronAPI.export.exportSessions(
sessionList,
exportFolder,
@@ -455,7 +472,7 @@ function ExportPage() {
setOptions({ ...options, format: fmt.value as any })}
+ onClick={() => handleFormatChange(fmt.value as ExportOptions['format'])}
>
{fmt.label}