From 0a97b8049966ebe470480a1a5a03a1998aed4c43 Mon Sep 17 00:00:00 2001 From: hzm <934585316@qq.com> Date: Tue, 17 Mar 2026 14:10:17 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E5=90=8C=E6=AD=A5?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/components/GroupSummary.jsx | 8 +++++-- app/page.jsx | 38 ++++++--------------------------- 2 files changed, 13 insertions(+), 33 deletions(-) diff --git a/app/components/GroupSummary.jsx b/app/components/GroupSummary.jsx index 2beb590..f7c9232 100644 --- a/app/components/GroupSummary.jsx +++ b/app/components/GroupSummary.jsx @@ -117,7 +117,8 @@ export default function GroupSummary({ hasHolding = true; totalAsset += profit.amount; if (profit.profitToday != null) { - totalProfitToday += Math.round(profit.profitToday * 100) / 100; + // 先累加原始当日收益,最后统一做一次四舍五入,避免逐笔四舍五入造成的总计误差 + totalProfitToday += profit.profitToday; hasAnyTodayData = true; } if (profit.profitTotal !== null) { @@ -129,11 +130,14 @@ export default function GroupSummary({ } }); + // 将当日收益总和四舍五入到两位小数,和卡片展示保持一致 + const roundedTotalProfitToday = Math.round(totalProfitToday * 100) / 100; + const returnRate = totalCost > 0 ? (totalHoldingReturn / totalCost) * 100 : 0; return { totalAsset, - totalProfitToday, + totalProfitToday: roundedTotalProfitToday, totalHoldingReturn, hasHolding, returnRate, diff --git a/app/page.jsx b/app/page.jsx index 64fc0c4..2dc15e1 100644 --- a/app/page.jsx +++ b/app/page.jsx @@ -3165,9 +3165,10 @@ export default function HomePage() { const fetchCloudConfig = async (userId, checkConflict = false) => { if (!userId) return; try { + // 一次查询同时拿到 meta 与 data,方便两种模式复用 const { data: meta, error: metaError } = await supabase .from('user_configs') - .select(`id, updated_at${checkConflict ? ', data' : ''}`) + .select('id, data, updated_at') .eq('user_id', userId) .maybeSingle(); @@ -3181,44 +3182,19 @@ export default function HomePage() { setCloudConfigModal({ open: true, userId, type: 'empty' }); return; } + + // 冲突检查模式:使用 meta.data 弹出冲突确认弹窗 if (checkConflict) { setCloudConfigModal({ open: true, userId, type: 'conflict', cloudData: meta.data }); return; } - const localUpdatedAt = window.localStorage.getItem('localUpdatedAt'); - if (localUpdatedAt && meta.updated_at && new Date(meta.updated_at) < new Date(localUpdatedAt)) { + // 非冲突检查模式:直接复用上方查询到的 meta 数据,覆盖本地 + if (meta.data && isPlainObject(meta.data) && Object.keys(meta.data).length > 0) { + await applyCloudConfig(meta.data, meta.updated_at); return; } - const { data, error } = await supabase - .from('user_configs') - .select('id, data, updated_at') - .eq('user_id', userId) - .maybeSingle(); - - if (error) throw error; - - if (data?.data && isPlainObject(data.data) && Object.keys(data.data).length > 0) { - const localPayload = collectLocalPayload(); - const localComparable = getComparablePayload(localPayload); - const cloudComparable = getComparablePayload(data.data); - - if (localComparable !== cloudComparable) { - // 如果数据不一致 - if (checkConflict) { - // 只有明确要求检查冲突时才提示(例如刚登录时) - setCloudConfigModal({ open: true, userId, type: 'conflict', cloudData: data.data }); - return; - } - // 否则直接覆盖本地(例如已登录状态下的刷新) - await applyCloudConfig(data.data, data.updated_at); - return; - } - - await applyCloudConfig(data.data, data.updated_at); - return; - } setCloudConfigModal({ open: true, userId, type: 'empty' }); } catch (e) { console.error('获取云端配置失败', e);