feat: 设置持仓支持今日首次买入
This commit is contained in:
@@ -7,7 +7,7 @@ import {
|
||||
DialogTitle,
|
||||
} from '@/components/ui/dialog';
|
||||
|
||||
export default function HoldingActionModal({ fund, onClose, onAction, hasHistory }) {
|
||||
export default function HoldingActionModal({ fund, onClose, onAction, hasHistory, pendingCount }) {
|
||||
const handleOpenChange = (open) => {
|
||||
if (!open) {
|
||||
onClose?.();
|
||||
@@ -39,11 +39,26 @@ export default function HoldingActionModal({ fund, onClose, onAction, hasHistory
|
||||
display: 'flex',
|
||||
alignItems: 'center',
|
||||
gap: 4,
|
||||
position: 'relative',
|
||||
}}
|
||||
title="查看交易记录"
|
||||
>
|
||||
<span>📜</span>
|
||||
<span>交易记录</span>
|
||||
{pendingCount > 0 && (
|
||||
<span
|
||||
style={{
|
||||
position: 'absolute',
|
||||
top: -4,
|
||||
right: -4,
|
||||
width: 10,
|
||||
height: 10,
|
||||
borderRadius: '50%',
|
||||
backgroundColor: '#ef4444',
|
||||
border: '2px solid var(--background)',
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
</button>
|
||||
</div>
|
||||
<button className="icon-button" onClick={onClose} style={{ border: 'none', background: 'transparent' }}>
|
||||
|
||||
@@ -8,7 +8,7 @@ import {
|
||||
DialogTitle,
|
||||
} from '@/components/ui/dialog';
|
||||
|
||||
export default function HoldingEditModal({ fund, holding, onClose, onSave }) {
|
||||
export default function HoldingEditModal({ fund, holding, onClose, onSave, onOpenTrade }) {
|
||||
const [mode, setMode] = useState('amount'); // 'amount' | 'share'
|
||||
|
||||
const dwjz = fund?.dwjz || fund?.gsz || 0;
|
||||
@@ -124,6 +124,23 @@ export default function HoldingEditModal({ fund, holding, onClose, onSave }) {
|
||||
<div style={{ display: 'flex', alignItems: 'center', gap: 10 }}>
|
||||
<SettingsIcon width="20" height="20" />
|
||||
<span>设置持仓</span>
|
||||
{typeof onOpenTrade === 'function' && (
|
||||
<button
|
||||
type="button"
|
||||
onClick={onOpenTrade}
|
||||
className="button secondary"
|
||||
style={{
|
||||
height: 28,
|
||||
padding: '0 10px',
|
||||
borderRadius: 999,
|
||||
fontSize: 12,
|
||||
background: 'rgba(255,255,255,0.06)',
|
||||
color: 'var(--primary)',
|
||||
}}
|
||||
>
|
||||
今日买入?去加仓。
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
<button className="icon-button" onClick={onClose} style={{ border: 'none', background: 'transparent' }}>
|
||||
<CloseIcon width="20" height="20" />
|
||||
|
||||
28
app/page.jsx
28
app/page.jsx
@@ -883,7 +883,21 @@ export default function HomePage() {
|
||||
|
||||
const handleClearConfirm = () => {
|
||||
if (clearConfirm?.fund) {
|
||||
handleSaveHolding(clearConfirm.fund.code, { share: null, cost: null });
|
||||
const code = clearConfirm.fund.code;
|
||||
handleSaveHolding(code, { share: null, cost: null });
|
||||
|
||||
setTransactions(prev => {
|
||||
const next = { ...(prev || {}) };
|
||||
delete next[code];
|
||||
storageHelper.setItem('transactions', JSON.stringify(next));
|
||||
return next;
|
||||
});
|
||||
|
||||
setPendingTrades(prev => {
|
||||
const next = prev.filter(trade => trade.fundCode !== code);
|
||||
storageHelper.setItem('pendingTrades', JSON.stringify(next));
|
||||
return next;
|
||||
});
|
||||
}
|
||||
setClearConfirm(null);
|
||||
};
|
||||
@@ -1040,6 +1054,11 @@ export default function HomePage() {
|
||||
setPendingTrades(next);
|
||||
storageHelper.setItem('pendingTrades', JSON.stringify(next));
|
||||
|
||||
// 如果该基金没有持仓数据,初始化持仓金额为 0
|
||||
if (!holdings[fund.code]) {
|
||||
handleSaveHolding(fund.code, { share: 0, cost: 0 });
|
||||
}
|
||||
|
||||
setTradeModal({ open: false, fund: null, type: 'buy' });
|
||||
showToast('净值暂未更新,已加入待处理队列', 'info');
|
||||
return;
|
||||
@@ -4489,6 +4508,7 @@ export default function HomePage() {
|
||||
onClose={() => setActionModal({ open: false, fund: null })}
|
||||
onAction={(type) => handleAction(type, actionModal.fund)}
|
||||
hasHistory={!!transactions[actionModal.fund?.code]?.length}
|
||||
pendingCount={pendingTrades.filter(t => t.fundCode === actionModal.fund?.code).length}
|
||||
/>
|
||||
)}
|
||||
</AnimatePresence>
|
||||
@@ -4597,6 +4617,12 @@ export default function HomePage() {
|
||||
holding={holdings[holdingModal.fund?.code]}
|
||||
onClose={() => setHoldingModal({ open: false, fund: null })}
|
||||
onSave={(data) => handleSaveHolding(holdingModal.fund?.code, data)}
|
||||
onOpenTrade={() => {
|
||||
const f = holdingModal.fund;
|
||||
if (!f) return;
|
||||
setHoldingModal({ open: false, fund: null });
|
||||
setTradeModal({ open: true, fund: f, type: 'buy' });
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
</AnimatePresence>
|
||||
|
||||
Reference in New Issue
Block a user