feat:当日收益展示百分比
This commit is contained in:
@@ -88,7 +88,6 @@ function SortableRow({ row, children, isTableDragging, disabled }) {
|
||||
* @param {(row: any) => void} [props.onToggleFavorite] - 添加/取消自选
|
||||
* @param {(row: any) => void} [props.onRemoveFromGroup] - 从当前分组移除
|
||||
* @param {(row: any, meta: { hasHolding: boolean }) => void} [props.onHoldingAmountClick] - 点击持仓金额
|
||||
* @param {(row: any) => void} [props.onHoldingProfitClick] - 点击持有收益
|
||||
* @param {boolean} [props.refreshing] - 是否刷新中
|
||||
* @param {string} [props.sortBy] - 排序方式,'default' 时长按行触发拖拽排序
|
||||
* @param {(oldIndex: number, newIndex: number) => void} [props.onReorder] - 拖拽排序回调
|
||||
@@ -101,7 +100,7 @@ export default function MobileFundTable({
|
||||
onToggleFavorite,
|
||||
onRemoveFromGroup,
|
||||
onHoldingAmountClick,
|
||||
onHoldingProfitClick,
|
||||
onHoldingProfitClick, // 保留以兼容调用方,表格内已不再使用点击切换
|
||||
refreshing = false,
|
||||
sortBy = 'default',
|
||||
onReorder,
|
||||
@@ -119,18 +118,15 @@ export default function MobileFundTable({
|
||||
const onToggleFavoriteRef = useRef(onToggleFavorite);
|
||||
const onRemoveFromGroupRef = useRef(onRemoveFromGroup);
|
||||
const onHoldingAmountClickRef = useRef(onHoldingAmountClick);
|
||||
const onHoldingProfitClickRef = useRef(onHoldingProfitClick);
|
||||
|
||||
useEffect(() => {
|
||||
onToggleFavoriteRef.current = onToggleFavorite;
|
||||
onRemoveFromGroupRef.current = onRemoveFromGroup;
|
||||
onHoldingAmountClickRef.current = onHoldingAmountClick;
|
||||
onHoldingProfitClickRef.current = onHoldingProfitClick;
|
||||
}, [
|
||||
onToggleFavorite,
|
||||
onRemoveFromGroup,
|
||||
onHoldingAmountClick,
|
||||
onHoldingProfitClick,
|
||||
]);
|
||||
|
||||
const handleDragStart = (e) => setActiveId(e.active.id);
|
||||
@@ -475,12 +471,23 @@ export default function MobileFundTable({
|
||||
const value = original.todayProfitValue;
|
||||
const hasProfit = value != null;
|
||||
const cls = hasProfit ? (value > 0 ? 'up' : value < 0 ? 'down' : '') : 'muted';
|
||||
const amountStr = hasProfit ? (info.getValue() ?? '') : '—';
|
||||
const percentStr = original.todayProfitPercent ?? '';
|
||||
return (
|
||||
<span className={cls} style={{ display: 'block', width: '100%', fontWeight: 700 }}>
|
||||
<FitText maxFontSize={14} minFontSize={10}>
|
||||
{hasProfit ? (info.getValue() ?? '') : ''}
|
||||
</FitText>
|
||||
</span>
|
||||
<div style={{ width: '100%' }}>
|
||||
<span className={cls} style={{ display: 'block', width: '100%', fontWeight: 700 }}>
|
||||
<FitText maxFontSize={14} minFontSize={10}>
|
||||
{amountStr}
|
||||
</FitText>
|
||||
</span>
|
||||
{percentStr ? (
|
||||
<span className={`${cls} today-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: 'profit-cell', width: columnWidthMap.todayProfit },
|
||||
@@ -493,21 +500,22 @@ export default function MobileFundTable({
|
||||
const value = original.holdingProfitValue;
|
||||
const hasTotal = value != null;
|
||||
const cls = hasTotal ? (value > 0 ? 'up' : value < 0 ? 'down' : '') : 'muted';
|
||||
const amountStr = hasTotal ? (info.getValue() ?? '') : '—';
|
||||
const percentStr = original.holdingProfitPercent ?? '';
|
||||
return (
|
||||
<div
|
||||
title="点击切换金额/百分比"
|
||||
style={{ cursor: hasTotal ? 'pointer' : 'default', width: '100%' }}
|
||||
onClick={(e) => {
|
||||
if (!hasTotal) return;
|
||||
e.stopPropagation?.();
|
||||
onHoldingProfitClickRef.current?.(original);
|
||||
}}
|
||||
>
|
||||
<div style={{ width: '100%' }}>
|
||||
<span className={cls} style={{ display: 'block', width: '100%', fontWeight: 700 }}>
|
||||
<FitText maxFontSize={14} minFontSize={10}>
|
||||
{hasTotal ? (info.getValue() ?? '') : ''}
|
||||
{amountStr}
|
||||
</FitText>
|
||||
</span>
|
||||
{percentStr ? (
|
||||
<span className={`${cls} holding-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>
|
||||
);
|
||||
},
|
||||
|
||||
@@ -115,7 +115,6 @@ function SortableRow({ row, children, isTableDragging, disabled }) {
|
||||
* @param {(row: any) => void} [props.onToggleFavorite] - 添加/取消自选
|
||||
* @param {(row: any) => void} [props.onRemoveFromGroup] - 从当前分组移除
|
||||
* @param {(row: any, meta: { hasHolding: boolean }) => void} [props.onHoldingAmountClick] - 点击持仓金额
|
||||
* @param {(row: any) => void} [props.onHoldingProfitClick] - 点击持有收益
|
||||
* @param {boolean} [props.refreshing] - 是否处于刷新状态(控制删除按钮禁用态)
|
||||
*/
|
||||
export default function PcFundTable({
|
||||
@@ -126,7 +125,7 @@ export default function PcFundTable({
|
||||
onToggleFavorite,
|
||||
onRemoveFromGroup,
|
||||
onHoldingAmountClick,
|
||||
onHoldingProfitClick,
|
||||
onHoldingProfitClick, // 保留以兼容调用方,表格内已不再使用点击切换
|
||||
refreshing = false,
|
||||
sortBy = 'default',
|
||||
onReorder,
|
||||
@@ -308,20 +307,17 @@ export default function PcFundTable({
|
||||
const onToggleFavoriteRef = useRef(onToggleFavorite);
|
||||
const onRemoveFromGroupRef = useRef(onRemoveFromGroup);
|
||||
const onHoldingAmountClickRef = useRef(onHoldingAmountClick);
|
||||
const onHoldingProfitClickRef = useRef(onHoldingProfitClick);
|
||||
|
||||
useEffect(() => {
|
||||
onRemoveFundRef.current = onRemoveFund;
|
||||
onToggleFavoriteRef.current = onToggleFavorite;
|
||||
onRemoveFromGroupRef.current = onRemoveFromGroup;
|
||||
onHoldingAmountClickRef.current = onHoldingAmountClick;
|
||||
onHoldingProfitClickRef.current = onHoldingProfitClick;
|
||||
}, [
|
||||
onRemoveFund,
|
||||
onToggleFavorite,
|
||||
onRemoveFromGroup,
|
||||
onHoldingAmountClick,
|
||||
onHoldingProfitClick,
|
||||
]);
|
||||
|
||||
const FundNameCell = ({ info }) => {
|
||||
@@ -555,10 +551,21 @@ export default function PcFundTable({
|
||||
const value = original.todayProfitValue;
|
||||
const hasProfit = value != null;
|
||||
const cls = hasProfit ? (value > 0 ? 'up' : value < 0 ? 'down' : '') : 'muted';
|
||||
const amountStr = hasProfit ? (info.getValue() ?? '') : '—';
|
||||
const percentStr = original.todayProfitPercent ?? '';
|
||||
return (
|
||||
<FitText className={cls} style={{ fontWeight: 700 }} maxFontSize={14} minFontSize={10}>
|
||||
{hasProfit ? (info.getValue() ?? '') : ''}
|
||||
</FitText>
|
||||
<div style={{ width: '100%' }}>
|
||||
<FitText className={cls} style={{ fontWeight: 700, display: 'block' }} maxFontSize={14} minFontSize={10}>
|
||||
{amountStr}
|
||||
</FitText>
|
||||
{percentStr ? (
|
||||
<span className={`${cls} today-profit-percent`} style={{ display: 'block', fontSize: '0.75em', opacity: 0.9, fontWeight: 500 }}>
|
||||
<FitText maxFontSize={11} minFontSize={9}>
|
||||
{percentStr}
|
||||
</FitText>
|
||||
</span>
|
||||
) : null}
|
||||
</div>
|
||||
);
|
||||
},
|
||||
meta: {
|
||||
@@ -576,19 +583,20 @@ export default function PcFundTable({
|
||||
const value = original.holdingProfitValue;
|
||||
const hasTotal = value != null;
|
||||
const cls = hasTotal ? (value > 0 ? 'up' : value < 0 ? 'down' : '') : 'muted';
|
||||
const amountStr = hasTotal ? (info.getValue() ?? '') : '—';
|
||||
const percentStr = original.holdingProfitPercent ?? '';
|
||||
return (
|
||||
<div
|
||||
title="点击切换金额/百分比"
|
||||
style={{ cursor: hasTotal ? 'pointer' : 'default', width: '100%' }}
|
||||
onClick={(e) => {
|
||||
if (!hasTotal) return;
|
||||
e.stopPropagation?.();
|
||||
onHoldingProfitClickRef.current?.(original);
|
||||
}}
|
||||
>
|
||||
<FitText className={cls} style={{ fontWeight: 700 }} maxFontSize={14} minFontSize={10}>
|
||||
{hasTotal ? (info.getValue() ?? '') : ''}
|
||||
<div style={{ width: '100%' }}>
|
||||
<FitText className={cls} style={{ fontWeight: 700, display: 'block' }} maxFontSize={14} minFontSize={10}>
|
||||
{amountStr}
|
||||
</FitText>
|
||||
{percentStr ? (
|
||||
<span className={`${cls} holding-profit-percent`} style={{ display: 'block', fontSize: '0.75em', opacity: 0.9, fontWeight: 500 }}>
|
||||
<FitText maxFontSize={11} minFontSize={9}>
|
||||
{percentStr}
|
||||
</FitText>
|
||||
</span>
|
||||
) : null}
|
||||
</div>
|
||||
);
|
||||
},
|
||||
|
||||
17
app/page.jsx
17
app/page.jsx
@@ -778,13 +778,18 @@ export default function HomePage() {
|
||||
holding && isNumber(holding.cost) && isNumber(holding.share)
|
||||
? holding.cost * holding.share
|
||||
: 0;
|
||||
const asPercent = !!percentModes[f.code];
|
||||
const todayProfitPercent =
|
||||
profitToday != null && principal > 0
|
||||
? `${profitToday > 0 ? '+' : profitToday < 0 ? '-' : ''}${Math.abs((profitToday / principal) * 100).toFixed(2)}%`
|
||||
: '';
|
||||
const holdingProfit =
|
||||
total == null
|
||||
? ''
|
||||
: (asPercent && principal > 0
|
||||
? `${total > 0 ? '+' : total < 0 ? '-' : ''}${Math.abs((total / principal) * 100).toFixed(2)}%`
|
||||
: `${total > 0 ? '+' : total < 0 ? '-' : ''}¥${Math.abs(total).toFixed(2)}`);
|
||||
: `${total > 0 ? '+' : total < 0 ? '-' : ''}¥${Math.abs(total).toFixed(2)}`;
|
||||
const holdingProfitPercent =
|
||||
total != null && principal > 0
|
||||
? `${total > 0 ? '+' : total < 0 ? '-' : ''}${Math.abs((total / principal) * 100).toFixed(2)}%`
|
||||
: '';
|
||||
const holdingProfitValue = total;
|
||||
|
||||
return {
|
||||
@@ -804,12 +809,14 @@ export default function HomePage() {
|
||||
holdingAmount,
|
||||
holdingAmountValue,
|
||||
todayProfit,
|
||||
todayProfitPercent,
|
||||
todayProfitValue,
|
||||
holdingProfit,
|
||||
holdingProfitPercent,
|
||||
holdingProfitValue,
|
||||
};
|
||||
}),
|
||||
[displayFunds, holdings, isTradingDay, todayStr, getHoldingProfit, percentModes],
|
||||
[displayFunds, holdings, isTradingDay, todayStr, getHoldingProfit],
|
||||
);
|
||||
|
||||
// 自动滚动选中 Tab 到可视区域
|
||||
|
||||
Reference in New Issue
Block a user