diff --git a/app/components/MobileFundTable.jsx b/app/components/MobileFundTable.jsx index e47cd62..cba4518 100644 --- a/app/components/MobileFundTable.jsx +++ b/app/components/MobileFundTable.jsx @@ -531,39 +531,27 @@ export default function MobileFundTable({ header: '估算收益', cell: (info) => { const original = info.row.original || {}; - const estimateValue = original.estimateChangeValue; - const hasTodayEstimate = original.hasTodayEstimate; - const holdingProfitPercentStr = original.holdingProfitPercent ?? ''; - - let holdingProfitPercentValue = null; - if (holdingProfitPercentStr && holdingProfitPercentStr !== '') { - const numStr = holdingProfitPercentStr.replace(/[+%]/g, ''); - holdingProfitPercentValue = parseFloat(numStr); - } - - const hasEstimate = hasTodayEstimate && estimateValue != null; - const hasHolding = holdingProfitPercentValue != null && !isNaN(holdingProfitPercentValue); - - if (!hasEstimate && !hasHolding) { - return ( - + const value = original.estimateProfitValue; + const hasProfit = value != null; + const cls = hasProfit ? (value > 0 ? 'up' : value < 0 ? 'down' : '') : 'muted'; + const amountStr = hasProfit ? (original.estimateProfit ?? '') : '—'; + const percentStr = original.estimateProfitPercent ?? ''; + + return ( +
+ - — + {amountStr} - ); - } - - const total = (hasEstimate ? estimateValue : 0) + (hasHolding ? holdingProfitPercentValue : 0); - const cls = total > 0 ? 'up' : total < 0 ? 'down' : ''; - const displayValue = `${total > 0 ? '+' : ''}${total.toFixed(2)}%`; - - return ( - - - {displayValue} - - + {percentStr ? ( + + + {percentStr} + + + ) : null} +
); }, meta: { align: 'right', cellClassName: 'total-change-cell', width: columnWidthMap.totalChangePercent }, diff --git a/app/components/PcFundTable.jsx b/app/components/PcFundTable.jsx index bd8cb36..278bb7d 100644 --- a/app/components/PcFundTable.jsx +++ b/app/components/PcFundTable.jsx @@ -521,35 +521,25 @@ export default function PcFundTable({ minSize: 100, cell: (info) => { const original = info.row.original || {}; - const estimateValue = original.estimateChangeValue; - const hasTodayEstimate = original.hasTodayEstimate; - const holdingProfitPercentStr = original.holdingProfitPercent ?? ''; - - let holdingProfitPercentValue = null; - if (holdingProfitPercentStr && holdingProfitPercentStr !== '') { - const numStr = holdingProfitPercentStr.replace(/[+%]/g, ''); - holdingProfitPercentValue = parseFloat(numStr); - } - - const hasEstimate = hasTodayEstimate && estimateValue != null; - const hasHolding = holdingProfitPercentValue != null && !isNaN(holdingProfitPercentValue); - - if (!hasEstimate && !hasHolding) { - return ( - - — - - ); - } - - const total = (hasEstimate ? estimateValue : 0) + (hasHolding ? holdingProfitPercentValue : 0); - const cls = total > 0 ? 'up' : total < 0 ? 'down' : ''; - const displayValue = `${total > 0 ? '+' : ''}${total.toFixed(2)}%`; - + const value = original.estimateProfitValue; + const hasProfit = value != null; + const cls = hasProfit ? (value > 0 ? 'up' : value < 0 ? 'down' : '') : 'muted'; + const amountStr = hasProfit ? (original.estimateProfit ?? '') : '—'; + const percentStr = original.estimateProfitPercent ?? ''; + return ( - - {displayValue} - +
+ + {amountStr} + + {percentStr ? ( + + + {percentStr} + + + ) : null} +
); }, meta: { diff --git a/app/page.jsx b/app/page.jsx index e9e9f80..e567044 100644 --- a/app/page.jsx +++ b/app/page.jsx @@ -815,6 +815,30 @@ export default function HomePage() { : ''; const holdingProfitValue = total; + const holdingProfitPercentValue = + total != null && principal > 0 ? (total / principal) * 100 : null; + const hasEstimatePercent = hasTodayEstimate && estimateChangeValue != null; + const hasHoldingPercent = holdingProfitPercentValue != null; + const fallbackEstimateProfitPercentValue = hasEstimatePercent || hasHoldingPercent + ? (hasEstimatePercent ? estimateChangeValue : 0) + (hasHoldingPercent ? holdingProfitPercentValue : 0) + : null; + const estimateProfitPercentValue = hasTodayData + ? holdingProfitPercentValue + : fallbackEstimateProfitPercentValue; + const estimateProfitValue = hasTodayData + ? total + : (estimateProfitPercentValue != null && principal > 0 + ? principal * (estimateProfitPercentValue / 100) + : null); + const estimateProfit = + estimateProfitValue == null + ? '' + : `${estimateProfitValue > 0 ? '+' : estimateProfitValue < 0 ? '-' : ''}¥${Math.abs(estimateProfitValue).toFixed(2)}`; + const estimateProfitPercent = + estimateProfitPercentValue == null + ? '' + : `${estimateProfitPercentValue > 0 ? '+' : ''}${estimateProfitPercentValue.toFixed(2)}%`; + return { rawFund: f, code: f.code, @@ -831,6 +855,10 @@ export default function HomePage() { estimateChangeMuted: f.noValuation, estimateTime, hasTodayEstimate, + totalChangePercent: estimateProfitPercent, + estimateProfit, + estimateProfitValue, + estimateProfitPercent, holdingAmount, holdingAmountValue, todayProfit,