@@ -8,6 +8,7 @@ import ImageDisplay from './components/ImageDisplay';
88import LatexEditor from './components/LatexEditor' ;
99import StatusBar from './components/StatusBar' ;
1010import CopyButton from './components/CopyButton' ;
11+ import ExportButton from './components/ExportButton' ;
1112import ApiSettingsDialog from './components/ApiSettingsDialog' ;
1213import ShortcutSettingsDialog from './components/ShortcutSettingsDialog' ;
1314import HistoryDialog from './components/HistoryDialog' ;
@@ -1141,6 +1142,60 @@ function App() {
11411142 }
11421143 } ;
11431144
1145+ // 导出数学公式为图片
1146+ const handleExportFormula = async ( format : 'svg' | 'png' | 'jpg' ) => {
1147+ if ( ! appState . latexCode . trim ( ) ) {
1148+ setAppState ( prev => ( {
1149+ ...prev ,
1150+ statusMessage : '❌ 请先识别或输入数学公式'
1151+ } ) ) ;
1152+ return ;
1153+ }
1154+
1155+ if ( ! window . electronAPI ) {
1156+ setAppState ( prev => ( {
1157+ ...prev ,
1158+ statusMessage : '❌ 图片导出功能仅在桌面应用中可用'
1159+ } ) ) ;
1160+ return ;
1161+ }
1162+
1163+ try {
1164+ setAppState ( prev => ( {
1165+ ...prev ,
1166+ statusMessage : `🔄 正在导出为${ format . toUpperCase ( ) } 格式...`
1167+ } ) ) ;
1168+
1169+ const result = await window . electronAPI . exportFormulaImage ( appState . latexCode , format ) ;
1170+
1171+ if ( result . success ) {
1172+ setAppState ( prev => ( {
1173+ ...prev ,
1174+ statusMessage : `✅ ${ result . message } `
1175+ } ) ) ;
1176+ } else {
1177+ setAppState ( prev => ( {
1178+ ...prev ,
1179+ statusMessage : `❌ ${ result . message } `
1180+ } ) ) ;
1181+ }
1182+
1183+ // 3秒后恢复状态
1184+ setTimeout ( ( ) => {
1185+ setAppState ( prev => ( {
1186+ ...prev ,
1187+ statusMessage : '⚡ 准备就绪'
1188+ } ) ) ;
1189+ } , 3000 ) ;
1190+ } catch ( error ) {
1191+ console . error ( `导出${ format . toUpperCase ( ) } 失败:` , error ) ;
1192+ setAppState ( prev => ( {
1193+ ...prev ,
1194+ statusMessage : `❌ 导出${ format . toUpperCase ( ) } 失败`
1195+ } ) ) ;
1196+ }
1197+ } ;
1198+
11441199 if ( ! settings ) {
11451200 return < div > 加载中...</ div > ;
11461201 }
@@ -1180,6 +1235,10 @@ function App() {
11801235 onCopy = { handleCopy }
11811236 disabled = { ! appState . latexCode . trim ( ) || appState . isRecognizing }
11821237 />
1238+ < ExportButton
1239+ onExport = { handleExportFormula }
1240+ disabled = { ! appState . latexCode . trim ( ) || appState . isRecognizing }
1241+ />
11831242 </ ButtonContainer >
11841243 </ BottomSection >
11851244 </ MainContent >
0 commit comments