From 805280d741cb89808eea34620bc0446063dda22d Mon Sep 17 00:00:00 2001 From: dgflash Date: Tue, 5 Mar 2024 22:26:07 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96StorageManager=E5=AD=98?= =?UTF-8?q?=E5=82=A8=E7=9A=84key=E5=80=BC=E4=B8=AD=E5=94=AF=E4=B8=80?= =?UTF-8?q?=E7=BC=96=E5=8F=B7=E5=AD=97=E7=AC=A6=E8=AE=B0=E5=BD=95=E5=9C=A8?= =?UTF-8?q?=E5=89=8D=EF=BC=8C=E4=BE=BF=E4=BA=8E=E6=95=B0=E6=8D=AE=E5=A4=9A?= =?UTF-8?q?=E6=97=B6=E9=98=85=E8=AF=BB=E6=95=B0=E6=8D=AE=EF=BC=9B=E6=97=A0?= =?UTF-8?q?=E5=94=AF=E4=B8=80=E7=BC=96=E5=8F=B7key=E5=8E=BB=E6=8E=89?= =?UTF-8?q?=E9=97=B4=E9=9A=94=E7=AC=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- assets/core/common/storage/StorageManager.ts | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/assets/core/common/storage/StorageManager.ts b/assets/core/common/storage/StorageManager.ts index ca535b9..9553ff1 100644 --- a/assets/core/common/storage/StorageManager.ts +++ b/assets/core/common/storage/StorageManager.ts @@ -6,7 +6,7 @@ import { EncryptUtil } from "../../utils/EncryptUtil"; export class StorageManager { private _key: string | null = null; private _iv: string | null = null; - private _id: string = ""; + private _id: string = null!; /** * 初始化密钥 @@ -35,7 +35,7 @@ export class StorageManager { * @returns */ set(key: string, value: any) { - var keywords = `${key}_${this._id}`; + var keywords = this.getKey(key); if (null == key) { console.error("存储的key不能为空"); @@ -84,7 +84,7 @@ export class StorageManager { return null!; } - key = `${key}_${this._id}`; + key = this.getKey(key); if (!PREVIEW) { key = EncryptUtil.md5(key); @@ -145,4 +145,11 @@ export class StorageManager { clear() { sys.localStorage.clear(); } + + private getKey(key: string): string { + if (this._id == null || this._id == "") { + return key; + } + return `${this._id}_${key}`; + } } \ No newline at end of file