feat(projects): 添加cryptojs,对本地缓存数据进行加密

This commit is contained in:
Soybean
2022-01-01 22:52:05 +08:00
parent 25d3404c9c
commit 7a0648dba5
5 changed files with 994 additions and 775 deletions

View File

@@ -1,14 +1,21 @@
import { encrypto, decrypto } from '../crypto';
export function setSession(key: string, value: unknown) {
const json = JSON.stringify(value);
const json = encrypto(value);
sessionStorage.setItem(key, json);
}
export function getSession<T>(key: string) {
const json = sessionStorage.getItem(key);
let data: T | null = null;
if (json) {
return JSON.parse(json) as T;
try {
data = decrypto(json);
} catch {
// 防止解析失败
}
}
return null;
return data;
}
export function removeSession(key: string) {