feat: 新增持仓金额排序

This commit is contained in:
hzm
2026-03-15 21:18:41 +08:00
parent cb87906aa2
commit 510bee53e3

View File

@@ -167,12 +167,14 @@ export default function HomePage() {
{ id: 'default', label: '默认', enabled: true },
// 估值涨幅为原始名称,“涨跌幅”为别名
{ id: 'yield', label: '估值涨幅', alias: '涨跌幅', enabled: true },
// 持仓金额排序:默认隐藏
{ id: 'holdingAmount', label: '持仓金额', enabled: false },
{ id: 'holding', label: '持有收益', enabled: true },
{ id: 'name', label: '名称', enabled: true },
{ id: 'name', label: '基金名称', alias: '名称', enabled: true },
];
// 排序状态
const [sortBy, setSortBy] = useState('default'); // default, name, yield, holding
const [sortBy, setSortBy] = useState('default'); // default, name, yield, holding, holdingAmount
const [sortOrder, setSortOrder] = useState('desc'); // asc | desc
const [isSortLoaded, setIsSortLoaded] = useState(false);
const [sortRules, setSortRules] = useState(DEFAULT_SORT_RULES);
@@ -652,6 +654,13 @@ export default function HomePage() {
return sortOrder === 'asc' ? valA - valB : valB - valA;
}
if (sortBy === 'holdingAmount') {
const pa = getHoldingProfit(a, holdings[a.code]);
const pb = getHoldingProfit(b, holdings[b.code]);
const amountA = pa?.amount ?? Number.NEGATIVE_INFINITY;
const amountB = pb?.amount ?? Number.NEGATIVE_INFINITY;
return sortOrder === 'asc' ? amountA - amountB : amountB - amountA;
}
if (sortBy === 'holding') {
const pa = getHoldingProfit(a, holdings[a.code]);
const pb = getHoldingProfit(b, holdings[b.code]);