wujingjing
2025-02-12 5bb92f8f17655f99d60030770ff8eabc74651090
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import { AlloyConstant } from '../config/AlloyConstant';
 
export class AlloyStorage {
    static readonly PREFIX = `${AlloyConstant.NAMESPACE}:`;
    static getFullKey(key: string) {
        return `${AlloyStorage.PREFIX}${key}`;
    }
    static get(key: string) {
        const storageValue = localStorage.getItem(AlloyStorage.getFullKey(key));
        const jsonData = storageValue ? JSON.parse(storageValue) : undefined;
        return jsonData;
    }
    static set(key: string, value: any) {
        if (typeof value !== 'string') {
            value = JSON.stringify(value);
        }
        localStorage.setItem(AlloyStorage.getFullKey(key), value);
    }
    static remove(key: string) {
        localStorage.removeItem(key);
    }
    static clear() {
        localStorage.clear();
    }
}