mirror of
https://github.com/soybeanjs/soybean-admin.git
synced 2025-12-25 14:20:21 +08:00
feat(projects): 添加cryptojs,对本地缓存数据进行加密
This commit is contained in:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user