优化StorageManager存储的key值中唯一编号字符记录在前,便于数据多时阅读数据;无唯一编号key去掉间隔符

This commit is contained in:
dgflash
2024-03-05 22:26:07 +08:00
parent ae80538e93
commit 805280d741

View File

@@ -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}`;
}
}