You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

localStorage.ts 760 B

1234567891011121314151617181920212223242526272829
  1. import { parseJsonText } from './index';
  2. export default class LocalStorage {
  3. // 登录的用户,包括用户名、密码和版本号
  4. static readonly loginUserKey = 'login-user';
  5. // 记住密码
  6. static readonly rememberPasswordKey = 'login-remember-password';
  7. static getItem(key: string, isObject: boolean = false) {
  8. const jsonStr = localStorage.getItem(key);
  9. if (!isObject) {
  10. return jsonStr;
  11. }
  12. if (jsonStr) {
  13. return parseJsonText(jsonStr);
  14. }
  15. return null;
  16. }
  17. static setItem(key: string, state?: any, isObject: boolean = false) {
  18. if (state) {
  19. localStorage.setItem(key, isObject ? JSON.stringify(state) : state);
  20. }
  21. }
  22. static removeItem(key: string) {
  23. localStorage.removeItem(key);
  24. }
  25. }