Merge pull request #82 from 5xiao0qing5/dev

实现 TXT导出 和 HTML导出
This commit is contained in:
cc
2026-01-24 00:25:34 +08:00
committed by GitHub
6 changed files with 1205 additions and 31 deletions

View File

@@ -22,6 +22,7 @@ interface ExportOptions {
exportEmojis: boolean
exportVoiceAsText: boolean
excelCompactColumns: boolean
txtColumns: string[]
}
interface ExportResult {
@@ -34,6 +35,7 @@ interface ExportResult {
type SessionLayout = 'shared' | 'per-session'
function ExportPage() {
const defaultTxtColumns = ['index', 'time', 'senderRole', 'messageType', 'content']
const [sessions, setSessions] = useState<ChatSession[]>([])
const [filteredSessions, setFilteredSessions] = useState<ChatSession[]>([])
const [selectedSessions, setSelectedSessions] = useState<Set<string>>(new Set())
@@ -61,7 +63,8 @@ function ExportPage() {
exportVoices: true,
exportEmojis: true,
exportVoiceAsText: true,
excelCompactColumns: true
excelCompactColumns: true,
txtColumns: defaultTxtColumns
})
const buildDateRangeFromPreset = (preset: string) => {
@@ -125,17 +128,20 @@ function ExportPage() {
savedRange,
savedMedia,
savedVoiceAsText,
savedExcelCompactColumns
savedExcelCompactColumns,
savedTxtColumns
] = await Promise.all([
configService.getExportDefaultFormat(),
configService.getExportDefaultDateRange(),
configService.getExportDefaultMedia(),
configService.getExportDefaultVoiceAsText(),
configService.getExportDefaultExcelCompactColumns()
configService.getExportDefaultExcelCompactColumns(),
configService.getExportDefaultTxtColumns()
])
const preset = savedRange || 'today'
const rangeDefaults = buildDateRangeFromPreset(preset)
const txtColumns = savedTxtColumns && savedTxtColumns.length > 0 ? savedTxtColumns : defaultTxtColumns
setOptions((prev) => ({
...prev,
@@ -144,7 +150,8 @@ function ExportPage() {
dateRange: rangeDefaults.dateRange,
exportMedia: savedMedia ?? false,
exportVoiceAsText: savedVoiceAsText ?? true,
excelCompactColumns: savedExcelCompactColumns ?? true
excelCompactColumns: savedExcelCompactColumns ?? true,
txtColumns
}))
} catch (e) {
console.error('加载导出默认设置失败:', e)
@@ -209,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)
@@ -233,6 +257,7 @@ function ExportPage() {
exportEmojis: options.exportMedia && options.exportEmojis,
exportVoiceAsText: options.exportVoiceAsText, // 即使不导出媒体,也可以导出语音转文字内容
excelCompactColumns: options.excelCompactColumns,
txtColumns: options.txtColumns,
sessionLayout,
dateRange: options.useAllTime ? null : options.dateRange ? {
start: Math.floor(options.dateRange.start.getTime() / 1000),
@@ -241,7 +266,7 @@ function ExportPage() {
} : null
}
if (options.format === 'chatlab' || options.format === 'chatlab-jsonl' || options.format === 'json' || options.format === 'excel') {
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,
@@ -447,7 +472,7 @@ function ExportPage() {
<div
key={fmt.value}
className={`format-card ${options.format === fmt.value ? 'active' : ''}`}
onClick={() => setOptions({ ...options, format: fmt.value as any })}
onClick={() => handleFormatChange(fmt.value as ExportOptions['format'])}
>
<fmt.icon size={24} />
<span className="format-label">{fmt.label}</span>

View File

@@ -166,6 +166,7 @@ function SettingsPage() {
await configService.setTranscribeLanguages(defaultLanguages)
}
if (savedWhisperModelDir) setWhisperModelDir(savedWhisperModelDir)
} catch (e) {
console.error('加载配置失败:', e)
@@ -1074,6 +1075,7 @@ function SettingsPage() {
)}
</div>
</div>
</div>
)
}
@@ -1225,4 +1227,3 @@ function SettingsPage() {
}
export default SettingsPage