feat: 初始化刷新后覆盖本地funds数据到云端
This commit is contained in:
32
app/page.jsx
32
app/page.jsx
@@ -1459,14 +1459,19 @@ export default function HomePage() {
|
|||||||
userIdRef.current = user?.id || null;
|
userIdRef.current = user?.id || null;
|
||||||
}, [user]);
|
}, [user]);
|
||||||
|
|
||||||
const getFundCodesSignature = useCallback((value) => {
|
const getFundCodesSignature = useCallback((value, extraFields = []) => {
|
||||||
try {
|
try {
|
||||||
const list = JSON.parse(value || '[]');
|
const list = Array.isArray(value) ? value : JSON.parse(value || '[]');
|
||||||
if (!Array.isArray(list)) return '';
|
if (!Array.isArray(list)) return '';
|
||||||
|
const fields = Array.from(new Set([
|
||||||
|
'jzrq',
|
||||||
|
'dwjz',
|
||||||
|
...(Array.isArray(extraFields) ? extraFields : [])
|
||||||
|
]));
|
||||||
const items = list.map((item) => {
|
const items = list.map((item) => {
|
||||||
if (!item?.code) return null;
|
if (!item?.code) return null;
|
||||||
// 加入 jzrq 和 dwjz 以检测净值更新
|
const extras = fields.map((field) => item?.[field] || '').join(':');
|
||||||
return `${item.code}:${item.jzrq || ''}:${item.dwjz || ''}`;
|
return `${item.code}:${extras}`;
|
||||||
}).filter(Boolean);
|
}).filter(Boolean);
|
||||||
return Array.from(new Set(items)).join('|');
|
return Array.from(new Set(items)).join('|');
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
@@ -3027,6 +3032,25 @@ export default function HomePage() {
|
|||||||
if (nextFunds.length) {
|
if (nextFunds.length) {
|
||||||
const codes = Array.from(new Set(nextFunds.map((f) => f.code)));
|
const codes = Array.from(new Set(nextFunds.map((f) => f.code)));
|
||||||
if (codes.length) await refreshAll(codes);
|
if (codes.length) await refreshAll(codes);
|
||||||
|
// 刷新完成后,强制同步本地localStorage 的 funds 数据到云端
|
||||||
|
const currentUserId = userIdRef.current || user?.id;
|
||||||
|
if (currentUserId) {
|
||||||
|
try {
|
||||||
|
const latestFunds = JSON.parse(localStorage.getItem('funds') || '[]');
|
||||||
|
const localSig = getFundCodesSignature(latestFunds, ['gztime']);
|
||||||
|
const cloudSig = getFundCodesSignature(Array.isArray(cloudData.funds) ? cloudData.funds : [], ['gztime']);
|
||||||
|
if (localSig !== cloudSig) {
|
||||||
|
await syncUserConfig(
|
||||||
|
currentUserId,
|
||||||
|
false,
|
||||||
|
{ funds: Array.isArray(latestFunds) ? latestFunds : [] },
|
||||||
|
true
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.error('刷新后强制同步 funds 到云端失败', e);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const payload = collectLocalPayload();
|
const payload = collectLocalPayload();
|
||||||
|
|||||||
Reference in New Issue
Block a user