import { parseJsonText } from './index'; export default class LocalStorage { // 登录的用户,包括用户名、密码和版本号 static readonly loginUserKey = 'login-user'; // 记住密码 static readonly rememberPasswordKey = 'login-remember-password'; static getItem(key: string, isObject: boolean = false) { const jsonStr = localStorage.getItem(key); if (!isObject) { return jsonStr; } if (jsonStr) { return parseJsonText(jsonStr); } return null; } static setItem(key: string, state?: any, isObject: boolean = false) { if (state) { localStorage.setItem(key, isObject ? JSON.stringify(state) : state); } } static removeItem(key: string) { localStorage.removeItem(key); } }