This commit is contained in:
我是个攻城狮
2026-08-26 16:53:45 +08:00
parent 62b7844199
commit 2fe864787a
94 changed files with 240 additions and 93 deletions
+30
View File
@@ -0,0 +1,30 @@
export const USER_INFO_UPDATED_EVENT = 'user-info-updated';
function getCachedUserInfo() {
try {
const raw = window.localStorage.getItem('userInfo');
return raw ? JSON.parse(raw) : {};
} catch (error) {
return {};
}
}
export function updateCachedUserInfo(changes) {
if (typeof window === 'undefined' || !window.localStorage) {
return {};
}
const nextUserInfo = {
...getCachedUserInfo(),
...(changes && typeof changes === 'object' ? changes : {})
};
try {
window.localStorage.setItem('userInfo', JSON.stringify(nextUserInfo));
} catch (error) {
void error;
}
window.dispatchEvent(new CustomEvent(USER_INFO_UPDATED_EVENT, { detail: nextUserInfo }));
return nextUserInfo;
}