feat: 手动添加的交易记录,不算入持仓金额
This commit is contained in:
@@ -197,6 +197,10 @@ export default function AddHistoryModal({ fund, onClose, onConfirm }) {
|
|||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div className="muted" style={{ fontSize: '11px', lineHeight: 1.5, marginBottom: 16, paddingTop: 12, borderTop: '1px solid rgba(255,255,255,0.08)' }}>
|
||||||
|
*此处补录的买入/卖出仅作记录展示,不会改变当前持仓金额与份额;实际持仓请在持仓设置中维护。
|
||||||
|
</div>
|
||||||
|
|
||||||
<button
|
<button
|
||||||
className="button primary full-width"
|
className="button primary full-width"
|
||||||
onClick={handleSubmit}
|
onClick={handleSubmit}
|
||||||
|
|||||||
37
app/page.jsx
37
app/page.jsx
@@ -824,24 +824,7 @@ export default function HomePage() {
|
|||||||
|
|
||||||
const handleAddHistory = (data) => {
|
const handleAddHistory = (data) => {
|
||||||
const fundCode = data.fundCode;
|
const fundCode = data.fundCode;
|
||||||
const current = holdings[fundCode] || { share: 0, cost: 0 };
|
// 添加历史记录仅作补录展示,不修改真实持仓金额与份额
|
||||||
const isBuy = data.type === 'buy';
|
|
||||||
|
|
||||||
let newShare, newCost;
|
|
||||||
|
|
||||||
if (isBuy) {
|
|
||||||
newShare = current.share + data.share;
|
|
||||||
// 加权平均成本
|
|
||||||
const buyCost = data.amount; // amount is total cost
|
|
||||||
newCost = (current.cost * current.share + buyCost) / newShare;
|
|
||||||
} else {
|
|
||||||
newShare = Math.max(0, current.share - data.share);
|
|
||||||
newCost = current.cost;
|
|
||||||
if (newShare === 0) newCost = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
handleSaveHolding(fundCode, { share: newShare, cost: newCost });
|
|
||||||
|
|
||||||
setTransactions(prev => {
|
setTransactions(prev => {
|
||||||
const current = prev[fundCode] || [];
|
const current = prev[fundCode] || [];
|
||||||
const record = {
|
const record = {
|
||||||
@@ -853,8 +836,9 @@ export default function HomePage() {
|
|||||||
date: data.date,
|
date: data.date,
|
||||||
isAfter3pm: false, // 历史记录通常不需要此标记,或者默认为 false
|
isAfter3pm: false, // 历史记录通常不需要此标记,或者默认为 false
|
||||||
isDca: false,
|
isDca: false,
|
||||||
|
isHistoryOnly: true, // 仅记录,不参与持仓计算
|
||||||
timestamp: data.timestamp || Date.now()
|
timestamp: data.timestamp || Date.now()
|
||||||
};
|
}
|
||||||
// 按时间倒序排列
|
// 按时间倒序排列
|
||||||
const next = [record, ...current].sort((a, b) => (b.timestamp || 0) - (a.timestamp || 0));
|
const next = [record, ...current].sort((a, b) => (b.timestamp || 0) - (a.timestamp || 0));
|
||||||
const nextState = { ...prev, [fundCode]: next };
|
const nextState = { ...prev, [fundCode]: next };
|
||||||
@@ -3993,20 +3977,25 @@ export default function HomePage() {
|
|||||||
{(() => {
|
{(() => {
|
||||||
const hasTodayData = f.jzrq === todayStr;
|
const hasTodayData = f.jzrq === todayStr;
|
||||||
let isYesterdayChange = false;
|
let isYesterdayChange = false;
|
||||||
if (!hasTodayData && isString(f.gztime) && isString(f.jzrq)) {
|
let isPreviousTradingDay = false;
|
||||||
const gzDate = toTz(f.gztime).startOf('day');
|
if (!hasTodayData && isString(f.jzrq)) {
|
||||||
|
const today = toTz(todayStr).startOf('day');
|
||||||
const jzDate = toTz(f.jzrq).startOf('day');
|
const jzDate = toTz(f.jzrq).startOf('day');
|
||||||
if (gzDate.clone().subtract(1, 'day').isSame(jzDate, 'day')) {
|
const yesterday = today.clone().subtract(1, 'day');
|
||||||
|
if (jzDate.isSame(yesterday, 'day')) {
|
||||||
isYesterdayChange = true;
|
isYesterdayChange = true;
|
||||||
|
} else if (jzDate.isBefore(yesterday, 'day')) {
|
||||||
|
isPreviousTradingDay = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const shouldHideChange = isTradingDay && !hasTodayData && !isYesterdayChange;
|
const shouldHideChange = isTradingDay && !hasTodayData && !isYesterdayChange && !isPreviousTradingDay;
|
||||||
|
|
||||||
if (shouldHideChange) return null;
|
if (shouldHideChange) return null;
|
||||||
|
|
||||||
|
const changeLabel = hasTodayData ? '涨跌幅' : (isYesterdayChange ? '昨日涨跌幅' : (isPreviousTradingDay ? '上一交易日涨跌幅' : '涨跌幅'));
|
||||||
return (
|
return (
|
||||||
<Stat
|
<Stat
|
||||||
label={isYesterdayChange ? '昨日涨跌幅' : '涨跌幅'}
|
label={changeLabel}
|
||||||
value={f.zzl !== undefined ? `${f.zzl > 0 ? '+' : ''}${Number(f.zzl).toFixed(2)}%` : ''}
|
value={f.zzl !== undefined ? `${f.zzl > 0 ? '+' : ''}${Number(f.zzl).toFixed(2)}%` : ''}
|
||||||
delta={f.zzl}
|
delta={f.zzl}
|
||||||
/>
|
/>
|
||||||
|
|||||||
Reference in New Issue
Block a user