This commit is contained in:
MarkLo 2025-11-25 02:33:08 +08:00
parent 63ac0668ac
commit e3a3d09cff
2 changed files with 17 additions and 15 deletions

View File

@ -151,17 +151,6 @@ export default function AnalysisResultsPage() {
</Button> </Button>
</div> </div>
{/* Download Reports Section */}
{taskId && analysisResult.reports && (
<DownloadReports
ticker={analysisResult.ticker}
analysisDate={analysisResult.analysis_date}
taskId={taskId}
analysts={ANALYSTS}
reports={analysisResult.reports}
/>
)}
{/* 分析師選擇 Tabs */} {/* 分析師選擇 Tabs */}
<Tabs value={selectedAnalyst} onValueChange={setSelectedAnalyst} className="w-full"> <Tabs value={selectedAnalyst} onValueChange={setSelectedAnalyst} className="w-full">
<TabsList className="grid w-full grid-cols-2 md:grid-cols-3 lg:grid-cols-4 h-auto gap-2"> <TabsList className="grid w-full grid-cols-2 md:grid-cols-3 lg:grid-cols-4 h-auto gap-2">
@ -219,6 +208,17 @@ export default function AnalysisResultsPage() {
</TabsContent> </TabsContent>
))} ))}
</Tabs> </Tabs>
{/* Download Reports Section - 放在分析報告下方 */}
{taskId && analysisResult.reports && (
<DownloadReports
ticker={analysisResult.ticker}
analysisDate={analysisResult.analysis_date}
taskId={taskId}
analysts={ANALYSTS}
reports={analysisResult.reports}
/>
)}
</div> </div>
</div> </div>
); );

View File

@ -73,7 +73,7 @@ export function DownloadReports({
setIsDownloading(true); setIsDownloading(true);
try { try {
const response = await fetch(`${process.env.NEXT_PUBLIC_API_URL || 'http://localhost:8000'}/api/download/reports`, { const response = await fetch('/api/download/reports', {
method: 'POST', method: 'POST',
headers: { headers: {
'Content-Type': 'application/json', 'Content-Type': 'application/json',
@ -87,7 +87,9 @@ export function DownloadReports({
}); });
if (!response.ok) { if (!response.ok) {
throw new Error('Download failed'); const errorData = await response.json().catch(() => ({}));
const errorMessage = errorData.detail || `下載失敗 (${response.status})`;
throw new Error(errorMessage);
} }
// Get the blob // Get the blob
@ -117,9 +119,9 @@ export function DownloadReports({
// Cleanup // Cleanup
document.body.removeChild(link); document.body.removeChild(link);
window.URL.revokeObjectURL(url); window.URL.revokeObjectURL(url);
} catch (error) { } catch (error: any) {
console.error('Download error:', error); console.error('Download error:', error);
alert('下載失敗,請稍後再試'); alert(error.message || '下載失敗,請稍後再試');
} finally { } finally {
setIsDownloading(false); setIsDownloading(false);
} }