Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
pearone committed Mar 19, 2024
1 parent b5f5d18 commit 8e33d44
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 13 deletions.
2 changes: 1 addition & 1 deletion packages/event/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@dpdfe/event-utils",
"version": "0.0.39",
"version": "0.0.44",
"description": "通用方法",
"author": "pearone",
"homepage": "https://github.com/DPDFE/react-layout/tree/main/packages/event",
Expand Down
2 changes: 2 additions & 0 deletions packages/event/src/func.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,5 @@ function tryIt(func: Function) {
console.error(e);
}
}

export default addUserInfo;
29 changes: 17 additions & 12 deletions packages/event/src/localstorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,11 @@
/** iframe */
const is_in_open_service_iframe = window.parent !== window;

/** global local storage */
const global_local_storage =
// @ts-ignore
(window.global_local_storage ?? {}) as Record<string, any>;

// @ts-ignore
window.global_local_storage = global_local_storage;
window.global_local_storage = (window.global_local_storage ?? {}) as Record<
string,
any
>;

const LocalStorage = (
storage: Record<string, any> = {},
Expand All @@ -39,7 +37,8 @@ const LocalStorage = (

// 检查 key 是不已经注册过,没注册过,则抛出异常
const ensureKeyRegistered = (key: string): void => {
if (!global_local_storage.hasOwnProperty(key)) {
// @ts-ignore
if (!window.global_local_storage.hasOwnProperty(key)) {
throw new Error(
`未注册的 LocalStorage key:${key}。请先在 Storage 注册,统一管理。`
);
Expand Down Expand Up @@ -88,9 +87,12 @@ const LocalStorage = (
storage[key] = target;
setStorageItem(key, target);
}
global_local_storage[key] = target;
//@ts-ignore
if (!window.global_local_storage[key]) {
//@ts-ignore
window.global_local_storage[key] = target;
}
});
console.log('global_local_storage init', global_local_storage);
} catch (e) {
console.log(e);
}
Expand All @@ -103,7 +105,8 @@ const LocalStorage = (
get(target: typeof storage, key: string): any {
ensureKeyRegistered(key);
return is_in_open_service_iframe
? global_local_storage[key]
? // @ts-ignore
window.global_local_storage[key]
: getStorageItem(key);
},

Expand All @@ -112,7 +115,8 @@ const LocalStorage = (
storage[key] = value;
/** 处理iframe访问storage时,没有权限的情况 */
if (is_in_open_service_iframe) {
global_local_storage[key] = value;
// @ts-ignore
window.global_local_storage[key] = value;
} else {
setStorageItem(key, value);
}
Expand All @@ -123,7 +127,8 @@ const LocalStorage = (
ensureKeyRegistered(key);
/** 处理iframe访问storage时,没有权限的情况 */
if (is_in_open_service_iframe) {
delete global_local_storage[key];
// @ts-ignore
delete window.global_local_storage[key];
} else {
removeStorageItem(key);
}
Expand Down

0 comments on commit 8e33d44

Please sign in to comment.