fix: Dashboard complianceScore 字段名不匹配及缺少可选链保护

- complianceScore.overallScore → fallback to totalScore
- complianceScore.levelLabel → fallback to summary
- complianceScore.suggestions 加可选链守卫
- data.todos 加可选链守卫
- data.topRisks 加空数组兜底
This commit is contained in:
selfrelease
2026-08-01 16:27:03 +08:00
parent a252d72e68
commit b0942f3e61
+9 -9
View File
@@ -136,8 +136,8 @@ export default function Dashboard() {
})
}
const riskTodos = data?.todos.filter((t) => t.type === 'CONTRACT' || t.type === 'TERMINATION' || t.type === 'ONBOARDING' || t.type === 'RETIREMENT') || []
const taskTodos = data?.todos.filter((t) => t.type === 'MONTHLY' || t.type === 'SALARY') || []
const riskTodos = data?.todos?.filter((t) => t.type === 'CONTRACT' || t.type === 'TERMINATION' || t.type === 'ONBOARDING' || t.type === 'RETIREMENT') || []
const taskTodos = data?.todos?.filter((t) => t.type === 'MONTHLY' || t.type === 'SALARY') || []
const filteredTodos = activeTab === 'risk' ? riskTodos : taskTodos
if (isLoading) {
@@ -270,7 +270,7 @@ export default function Dashboard() {
<RadialBarChart
innerRadius="70%"
outerRadius="100%"
data={[{ value: complianceScore.overallScore, fill: complianceScore.level === 'safe' ? '#16A34A' : complianceScore.level === 'warning' ? '#D97706' : '#C00000' }]}
data={[{ value: complianceScore?.overallScore ?? complianceScore?.totalScore ?? 0, fill: complianceScore?.level === 'safe' ? '#16A34A' : complianceScore?.level === 'warning' ? '#D97706' : '#C00000' }]}
startAngle={90}
endAngle={-270}
>
@@ -279,13 +279,13 @@ export default function Dashboard() {
</RadialBarChart>
</ResponsiveContainer>
<div className="absolute inset-0 flex flex-col items-center justify-center">
<span className={`text-2xl font-bold ${complianceScore.level === 'safe' ? 'text-safe' : complianceScore.level === 'warning' ? 'text-warning' : 'text-danger'}`}>{complianceScore.overallScore}</span>
<span className="text-xs text-gray-500">{complianceScore.levelLabel}</span>
<span className={`text-2xl font-bold ${complianceScore?.level === 'safe' ? 'text-safe' : complianceScore?.level === 'warning' ? 'text-warning' : 'text-danger'}`}>{complianceScore?.overallScore ?? complianceScore?.totalScore ?? 0}</span>
<span className="text-xs text-gray-500">{complianceScore?.levelLabel ?? complianceScore?.summary ?? ''}</span>
</div>
</div>
{/* 5 维度评分 */}
<div className="flex-1 grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-2">
{complianceScore.dimensions.map((dim: any) => (
{complianceScore?.dimensions?.map((dim: any) => (
<Link key={dim.key} to={dim.key === 'contract' ? '/roster' : dim.key === 'policy' ? '/policies' : dim.key === 'attendance' ? '/attendance' : dim.key === 'salary' ? '/money' : '/social'} className="flex items-center justify-between p-2 rounded-lg hover:bg-gray-50 transition-colors">
<div className="flex items-center gap-2">
<div className={`w-2 h-2 rounded-full ${dim.score >= 85 ? 'bg-safe' : dim.score >= 60 ? 'bg-warning' : 'bg-danger'}`} />
@@ -302,7 +302,7 @@ export default function Dashboard() {
</Card>
{/* AI 建议卡片流 */}
{complianceScore.suggestions.length > 0 && (
{complianceScore?.suggestions && complianceScore.suggestions.length > 0 && (
<div className="space-y-2">
<div className="flex items-center gap-1.5 text-sm font-medium text-gray-700">
<Sparkles className="w-4 h-4 text-primary" />
@@ -547,8 +547,8 @@ export default function Dashboard() {
</span>
<button onClick={() => setDrillDownType(null)} className="text-xs text-gray-500 hover:text-gray-600"></button>
</div>
{data.topRisks.filter(r => r.type === drillDownType).length > 0 ? (
data.topRisks.filter(r => r.type === drillDownType).map((r) => (
{(data.topRisks || []).filter(r => r.type === drillDownType).length > 0 ? (
(data.topRisks || []).filter(r => r.type === drillDownType).map((r) => (
<Link key={r.id} to={r.actionUrl} className="flex items-center gap-2 px-2 py-1.5 rounded-md hover:bg-gray-50 text-xs">
<AlertCircle className={`w-4 h-4 flex-shrink-0 ${r.level === 'high' ? 'text-danger' : 'text-warning'}`} />
<div className="flex-1 min-w-0">