From dea24a1297d4ec93eef531214fc850d937e06802 Mon Sep 17 00:00:00 2001 From: admin <1297598740@qq.com> Date: Fri, 30 Jan 2026 16:10:40 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=96=B0=E5=A2=9E=E9=A6=96=E9=A1=B5?= =?UTF-8?q?=EF=BC=8C=E5=B9=B6=E9=9B=86=E6=88=90=E8=B4=A2=E5=8A=A1=E5=81=A5?= =?UTF-8?q?=E5=BA=B7=E8=AF=84=E5=88=86=E5=8A=9F=E8=83=BD=E3=80=81=E7=9B=B8?= =?UTF-8?q?=E5=85=B3=E7=BB=84=E4=BB=B6=E5=92=8C=E8=AE=A1=E7=AE=97=E9=80=BB?= =?UTF-8?q?=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../HealthScoreModal/HealthScoreModal.tsx | 78 ++++---- src/pages/Home/Home.tsx | 5 +- src/utils/healthScore.ts | 168 ++++++++++++++---- 3 files changed, 170 insertions(+), 81 deletions(-) diff --git a/src/components/home/HealthScoreModal/HealthScoreModal.tsx b/src/components/home/HealthScoreModal/HealthScoreModal.tsx index 7bc5b7f..2cf92e1 100644 --- a/src/components/home/HealthScoreModal/HealthScoreModal.tsx +++ b/src/components/home/HealthScoreModal/HealthScoreModal.tsx @@ -6,7 +6,6 @@ import React, { useEffect, useState } from 'react'; import { Icon } from '@iconify/react'; import { formatCurrency } from '../../../utils/format'; -import { getFinancialAdvice } from '../../../services/aiService'; import './HealthScoreModal.css'; interface HealthScoreModalProps { @@ -24,6 +23,12 @@ interface HealthScoreModalProps { activity: number; }; streakDays: number; + metrics: { + debtRatio: number; + survivalMonths: number; + budgetHealth: number; + }; + tips: string[]; } export const HealthScoreModal: React.FC = ({ @@ -32,53 +37,34 @@ export const HealthScoreModal: React.FC = ({ score, totalAssets, totalLiabilities, - todaySpend, - yesterdaySpend, + // todaySpend, // Unused + // yesterdaySpend, // Unused breakdown, streakDays, + metrics, + tips }) => { const [showRules, setShowRules] = useState(false); const [animate, setAnimate] = useState(false); - const [aiAdvice, setAiAdvice] = useState(''); - const [loadingAdvice, setLoadingAdvice] = useState(false); + // AI Advice state can be removed if strictly using tips, or kept as fallback // --- Logic & Calculations --- const debtRatio = totalAssets > 0 ? (totalLiabilities / totalAssets) * 100 : 0; - const spendDiff = todaySpend - yesterdaySpend; + // const spendDiff = todaySpend - yesterdaySpend; // Unused now useEffect(() => { - let isMounted = true; if (isOpen) { setTimeout(() => setAnimate(true), 50); - - // Fetch AI Advice if not already fetched - if (!aiAdvice) { - setLoadingAdvice(true); - getFinancialAdvice({ - score, - totalAssets, - totalLiabilities, - todaySpend, - yesterdaySpend - }) - .then(advice => { - if (isMounted) setAiAdvice(advice); - }) - .catch(err => { - console.error("Failed to load AI advice", err); - }) - .finally(() => { - if (isMounted) setLoadingAdvice(false); - }); - } } else { setAnimate(false); setShowRules(false); // Reset view on close } - return () => { isMounted = false; }; }, [isOpen]); + const aiAdvice = ''; // Fallback placeholder if needed + + if (!isOpen) return null; // Status Levels @@ -135,8 +121,8 @@ export const HealthScoreModal: React.FC = ({
{breakdown.solvency}/40
-

偿债能力 (40分)

-

核心指标。计算公式:1 - (总负债 / 总资产)。负债率越低,得分越高。
{debtRatio > 50 ? '当前负债率过高,严重影响得分。' : '当前资产结构健康。'}

+

财务结构 (40分)

+

由“负债率”与“应急流动性”共同决定。不仅关注负债水平,更看重现金流能否支撑至少3-6个月的生活开支。
这是抵御风险的基石。

@@ -227,17 +213,20 @@ export const HealthScoreModal: React.FC = ({ - {/* Spending Card */} + {/* Survival Time Card (Replacing Spend) */}
-
- +
+
- 今日消费 + 生存期
- {formatCurrency(todaySpend)} + + {metrics?.survivalMonths > 99 ? '>99' : (metrics?.survivalMonths || 0).toFixed(1)} + + 个月
- 0 ? '#ef4444' : '#10b981' }}> - 比昨日 {spendDiff > 0 ? '多' : '少'} {formatCurrency(Math.abs(spendDiff))} + + {(metrics?.survivalMonths || 0) >= 6 ? '资金充裕' : (metrics?.survivalMonths || 0) >= 3 ? '健康' : '急需储备'}
@@ -247,15 +236,16 @@ export const HealthScoreModal: React.FC = ({
AI 智能建议 - {loadingAdvice && 思考中...}
-

- {loadingAdvice ? ( - 正在生成个性化理财建议... +

+ {tips && tips.length > 0 ? ( + tips.map((tip, i) => ( +
{tip}
+ )) ) : ( - aiAdvice || getStaticSuggestion() +

{aiAdvice || getStaticSuggestion()}

)} -

+
)} diff --git a/src/pages/Home/Home.tsx b/src/pages/Home/Home.tsx index bb3d54c..a5b989a 100644 --- a/src/pages/Home/Home.tsx +++ b/src/pages/Home/Home.tsx @@ -257,7 +257,8 @@ function Home() { monthlyBudget: monthlyBudgetTotal, monthlySpent: monthlyBudgetSpentTotal, streakDays: streakInfo?.currentStreak || 0, - hasRecentActivity: todaySpend > 0 || yesterdaySpend > 0 + hasRecentActivity: todaySpend > 0 || yesterdaySpend > 0, + accounts: accounts || [] }); }; const healthStatus = calculateHealthScore(); @@ -430,6 +431,8 @@ function Home() { yesterdaySpend={yesterdaySpend} breakdown={healthStatus.breakdown} streakDays={streakInfo?.currentStreak || 0} + metrics={healthStatus.metrics} + tips={healthStatus.tips} />