feat: 估算收益支持展示金额
This commit is contained in:
@@ -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 (
|
||||
<span className="muted" style={{ display: 'block', width: '100%', fontWeight: 700 }}>
|
||||
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 (
|
||||
<div style={{ width: '100%' }}>
|
||||
<span className={cls} style={{ display: 'block', width: '100%', fontWeight: 700 }}>
|
||||
<FitText maxFontSize={14} minFontSize={10}>
|
||||
—
|
||||
{amountStr}
|
||||
</FitText>
|
||||
</span>
|
||||
);
|
||||
}
|
||||
|
||||
const total = (hasEstimate ? estimateValue : 0) + (hasHolding ? holdingProfitPercentValue : 0);
|
||||
const cls = total > 0 ? 'up' : total < 0 ? 'down' : '';
|
||||
const displayValue = `${total > 0 ? '+' : ''}${total.toFixed(2)}%`;
|
||||
|
||||
return (
|
||||
<span className={cls} style={{ display: 'block', width: '100%', fontWeight: 700 }}>
|
||||
<FitText maxFontSize={14} minFontSize={10}>
|
||||
{displayValue}
|
||||
</FitText>
|
||||
</span>
|
||||
{percentStr ? (
|
||||
<span className={`${cls} estimate-profit-percent`} style={{ display: 'block', width: '100%', fontSize: '0.75em', opacity: 0.9, fontWeight: 500 }}>
|
||||
<FitText maxFontSize={11} minFontSize={9}>
|
||||
{percentStr}
|
||||
</FitText>
|
||||
</span>
|
||||
) : null}
|
||||
</div>
|
||||
);
|
||||
},
|
||||
meta: { align: 'right', cellClassName: 'total-change-cell', width: columnWidthMap.totalChangePercent },
|
||||
|
||||
@@ -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 (
|
||||
<FitText className="muted" style={{ fontWeight: 700 }} maxFontSize={14} minFontSize={10}>
|
||||
—
|
||||
</FitText>
|
||||
);
|
||||
}
|
||||
|
||||
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 (
|
||||
<FitText className={cls} style={{ fontWeight: 700 }} maxFontSize={14} minFontSize={10}>
|
||||
{displayValue}
|
||||
</FitText>
|
||||
<div style={{ width: '100%' }}>
|
||||
<FitText className={cls} style={{ fontWeight: 700, display: 'block' }} maxFontSize={14} minFontSize={10}>
|
||||
{amountStr}
|
||||
</FitText>
|
||||
{percentStr ? (
|
||||
<span className={`${cls} estimate-profit-percent`} style={{ display: 'block', fontSize: '0.75em', opacity: 0.9, fontWeight: 500 }}>
|
||||
<FitText maxFontSize={11} minFontSize={9}>
|
||||
{percentStr}
|
||||
</FitText>
|
||||
</span>
|
||||
) : null}
|
||||
</div>
|
||||
);
|
||||
},
|
||||
meta: {
|
||||
|
||||
28
app/page.jsx
28
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,
|
||||
|
||||
Reference in New Issue
Block a user