-feat 修复json格式问题
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
```typescript
|
||||
import React, { useState, useEffect } from 'react';
|
||||
import { Icon } from '@iconify/react';
|
||||
import { formatCurrency } from '../../../utils/format';
|
||||
@@ -26,7 +25,7 @@ export const DailyInsightCard: React.FC<DailyInsightCardProps> = ({
|
||||
lastWeekSpend,
|
||||
streakDays
|
||||
}) => {
|
||||
const [aiData, setAiData] = useState<{spending: string; budget: string} | null>(null);
|
||||
const [aiData, setAiData] = useState<{ spending: string; budget: string } | null>(null);
|
||||
const [isAiLoading, setIsAiLoading] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
@@ -97,21 +96,21 @@ export const DailyInsightCard: React.FC<DailyInsightCardProps> = ({
|
||||
if (ratio >= 1) return { text: <span className="daily-insight__highlight daily-insight__highlight--danger">本月预算已耗尽!接下来的每一天都需要极限生存挑战了。</span>, type: 'danger' };
|
||||
|
||||
if (ratio > timeRatio + 0.15) {
|
||||
return { text: <span>进度 <strong className="daily-insight__highlight daily-insight__highlight--warning">{Math.round(ratio*100)}%</strong> (时间 {Math.round(timeRatio*100)}%)。花钱速度有点快了,建议踩踩刹车。</span>, type: 'warning' };
|
||||
return { text: <span>进度 <strong className="daily-insight__highlight daily-insight__highlight--warning">{Math.round(ratio * 100)}%</strong> (时间 {Math.round(timeRatio * 100)}%)。花钱速度有点快了,建议踩踩刹车。</span>, type: 'warning' };
|
||||
}
|
||||
|
||||
if (ratio < timeRatio - 0.1) {
|
||||
return { text: <span>进度 <strong className="daily-insight__highlight daily-insight__highlight--success">{Math.round(ratio*100)}%</strong> (时间 {Math.round(timeRatio*100)}%)。控制得非常完美,月底可能有惊喜结余!</span>, type: 'success' };
|
||||
return { text: <span>进度 <strong className="daily-insight__highlight daily-insight__highlight--success">{Math.round(ratio * 100)}%</strong> (时间 {Math.round(timeRatio * 100)}%)。控制得非常完美,月底可能有惊喜结余!</span>, type: 'success' };
|
||||
}
|
||||
|
||||
return { text: <span>进度 <strong>{Math.round(ratio*100)}%</strong> (时间 {Math.round(timeRatio*100)}%)。目前节奏刚刚好,稳扎稳打。</span>, type: 'normal' };
|
||||
return { text: <span>进度 <strong>{Math.round(ratio * 100)}%</strong> (时间 {Math.round(timeRatio * 100)}%)。目前节奏刚刚好,稳扎稳打。</span>, type: 'normal' };
|
||||
};
|
||||
|
||||
const spendingInsight = getSpendingInsight(todaySpend, yesterdaySpend);
|
||||
const budgetInsight = getBudgetInsight(monthlySpent, monthlyBudget);
|
||||
|
||||
return (
|
||||
<div className={`daily - insight - card ${ aiData ? 'daily-insight-card--ai' : '' } `}>
|
||||
<div className={`daily-insight-card ${aiData ? 'daily-insight-card--ai' : ''}`}>
|
||||
<div className="daily-insight__header">
|
||||
<Icon icon={aiData ? "solar:magic-stick-3-bold-duotone" : "solar:stars-minimalistic-bold-duotone"} width="20" />
|
||||
<span>{aiData ? 'AI 每日简报' : '每日简报'}</span>
|
||||
@@ -123,7 +122,7 @@ export const DailyInsightCard: React.FC<DailyInsightCardProps> = ({
|
||||
<div className="section-header-row">
|
||||
<span className="daily-insight__title">今日消费</span>
|
||||
{lastWeekSpend !== undefined && lastWeekSpend > 0 && (
|
||||
<span className={`week - diff - badge ${ todaySpend <= lastWeekSpend ? 'green' : 'red' } `}>
|
||||
<span className={`week-diff-badge ${todaySpend <= lastWeekSpend ? 'green' : 'red'}`}>
|
||||
周同比 {todaySpend <= lastWeekSpend ? '↓' : '↑'}{Math.abs(todaySpend - lastWeekSpend).toFixed(0)}
|
||||
</span>
|
||||
)}
|
||||
@@ -141,4 +140,3 @@ export const DailyInsightCard: React.FC<DailyInsightCardProps> = ({
|
||||
</div>
|
||||
);
|
||||
};
|
||||
```
|
||||
|
||||
@@ -289,14 +289,16 @@ Output Requirements:
|
||||
// Here we choose to throw so fallback static text appears.
|
||||
throw error;
|
||||
}
|
||||
// Cache storage for daily insight
|
||||
let dailyInsightCache: {
|
||||
}
|
||||
|
||||
// Cache storage for daily insight
|
||||
let dailyInsightCache: {
|
||||
data: { spending: string; budget: string };
|
||||
timestamp: number;
|
||||
contentHash: string;
|
||||
} | null = null;
|
||||
} | null = null;
|
||||
|
||||
export interface DailyInsightContext {
|
||||
export interface DailyInsightContext {
|
||||
todaySpend: number;
|
||||
yesterdaySpend: number;
|
||||
monthlyBudget: number;
|
||||
@@ -306,12 +308,12 @@ Output Requirements:
|
||||
maxTransaction?: { note: string; amount: number };
|
||||
lastWeekSpend?: number;
|
||||
streakDays?: number;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Get AI-powered daily insight
|
||||
*/
|
||||
export async function getDailyInsight(context: DailyInsightContext): Promise<{ spending: string; budget: string }> {
|
||||
export async function getDailyInsight(context: DailyInsightContext): Promise<{ spending: string; budget: string }> {
|
||||
// Hash needs to include new fields
|
||||
const currentHash = JSON.stringify(context);
|
||||
const NOW = Date.now();
|
||||
@@ -397,9 +399,9 @@ Task:
|
||||
console.error('Failed to get AI insight:', error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export default {
|
||||
export default {
|
||||
getSessionId,
|
||||
clearSession,
|
||||
sendChatMessage,
|
||||
@@ -410,4 +412,5 @@ Task:
|
||||
isConfirmationCardComplete,
|
||||
formatConfirmationCard,
|
||||
getFinancialAdvice,
|
||||
};
|
||||
getDailyInsight,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user