修正詳細評審頁面結果
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
"use client"
|
||||
|
||||
import { useState, useEffect } from "react"
|
||||
import { useSearchParams } from "next/navigation"
|
||||
import { Sidebar } from "@/components/sidebar"
|
||||
import { Button } from "@/components/ui/button"
|
||||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card"
|
||||
@@ -128,32 +129,58 @@ export default function ResultsPage() {
|
||||
const [activeTab, setActiveTab] = useState("overview")
|
||||
const [evaluationData, setEvaluationData] = useState(null)
|
||||
const [isLoading, setIsLoading] = useState(true)
|
||||
const [error, setError] = useState(null)
|
||||
const { toast } = useToast()
|
||||
const searchParams = useSearchParams()
|
||||
|
||||
useEffect(() => {
|
||||
// 從 localStorage 獲取評審結果
|
||||
const storedData = localStorage.getItem('evaluationResult')
|
||||
if (storedData) {
|
||||
const loadEvaluationData = async () => {
|
||||
try {
|
||||
const data = JSON.parse(storedData)
|
||||
setEvaluationData(data)
|
||||
setIsLoading(true)
|
||||
setError(null)
|
||||
|
||||
// 檢查是否有 URL 參數中的評審 ID
|
||||
const evaluationId = searchParams.get('id')
|
||||
|
||||
if (evaluationId) {
|
||||
// 從 API 獲取評審數據
|
||||
console.log(`📊 從 API 獲取評審數據: ID=${evaluationId}`)
|
||||
const response = await fetch(`/api/evaluation/${evaluationId}`)
|
||||
const result = await response.json()
|
||||
|
||||
if (result.success) {
|
||||
setEvaluationData(result.data)
|
||||
console.log('✅ 成功載入評審數據:', result.data.projectTitle)
|
||||
} else {
|
||||
throw new Error(result.error || '獲取評審數據失敗')
|
||||
}
|
||||
} else {
|
||||
// 回退到從 localStorage 獲取評審結果
|
||||
console.log('📊 從 localStorage 獲取評審結果')
|
||||
const storedData = localStorage.getItem('evaluationResult')
|
||||
if (storedData) {
|
||||
const data = JSON.parse(storedData)
|
||||
setEvaluationData(data)
|
||||
console.log('✅ 成功載入 localStorage 數據')
|
||||
} else {
|
||||
throw new Error('沒有找到評審結果')
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('解析評審結果失敗:', error)
|
||||
console.error('載入評審結果失敗:', error)
|
||||
setError(error.message)
|
||||
toast({
|
||||
title: "數據錯誤",
|
||||
description: "無法載入評審結果,請重新進行評審",
|
||||
title: "載入失敗",
|
||||
description: error.message || "無法載入評審結果,請重新進行評審",
|
||||
variant: "destructive",
|
||||
})
|
||||
} finally {
|
||||
setIsLoading(false)
|
||||
}
|
||||
} else {
|
||||
toast({
|
||||
title: "無評審結果",
|
||||
description: "請先進行評審以查看結果",
|
||||
variant: "destructive",
|
||||
})
|
||||
}
|
||||
setIsLoading(false)
|
||||
}, [toast])
|
||||
|
||||
loadEvaluationData()
|
||||
}, [searchParams, toast])
|
||||
|
||||
// 如果正在載入,顯示載入狀態
|
||||
if (isLoading) {
|
||||
@@ -174,8 +201,8 @@ export default function ResultsPage() {
|
||||
)
|
||||
}
|
||||
|
||||
// 如果沒有數據,顯示錯誤狀態
|
||||
if (!evaluationData) {
|
||||
// 如果沒有數據或發生錯誤,顯示錯誤狀態
|
||||
if (!evaluationData || error) {
|
||||
return (
|
||||
<div className="min-h-screen bg-background">
|
||||
<Sidebar />
|
||||
@@ -183,10 +210,17 @@ export default function ResultsPage() {
|
||||
<div className="max-w-6xl mx-auto">
|
||||
<div className="flex items-center justify-center h-64">
|
||||
<div className="text-center">
|
||||
<p className="text-muted-foreground mb-4">沒有找到評審結果</p>
|
||||
<Button onClick={() => window.location.href = '/upload'}>
|
||||
重新進行評審
|
||||
</Button>
|
||||
<p className="text-muted-foreground mb-4">
|
||||
{error ? `載入失敗: ${error}` : '沒有找到評審結果'}
|
||||
</p>
|
||||
<div className="space-x-2">
|
||||
<Button onClick={() => window.location.href = '/upload'}>
|
||||
重新進行評審
|
||||
</Button>
|
||||
<Button variant="outline" onClick={() => window.location.href = '/history'}>
|
||||
查看歷史記錄
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -196,7 +230,7 @@ export default function ResultsPage() {
|
||||
}
|
||||
|
||||
// 使用真實數據或回退到模擬數據
|
||||
const results = evaluationData.evaluation?.fullData || mockResults
|
||||
const results = evaluationData.evaluation?.fullData || evaluationData || mockResults
|
||||
|
||||
// 計算統計數據 - 基於 criteria_items 的平均分作為閾值
|
||||
const calculateOverview = (criteria: any[]) => {
|
||||
|
Reference in New Issue
Block a user