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.

sessionStorage.ts 956 B

1 year ago
1234567891011121314151617181920212223242526272829303132333435
  1. import { parseJsonText } from './index';
  2. export default class SessionStorage {
  3. // 用于新建镜像
  4. static readonly mirrorNameKey = 'mirror-name';
  5. // 模型部署服务
  6. static readonly serviceInfoKey = 'service-info';
  7. // 模型部署服务版本
  8. static readonly serviceVersionInfoKey = 'service-version-info';
  9. // 编辑器 url
  10. static readonly editorUrlKey = 'editor-url';
  11. // 客户端信息
  12. static readonly clientInfoKey = 'client-info';
  13. static getItem(key: string, isObject: boolean = false) {
  14. const jsonStr = sessionStorage.getItem(key);
  15. if (!isObject) {
  16. return jsonStr;
  17. }
  18. if (jsonStr) {
  19. return parseJsonText(jsonStr);
  20. }
  21. return null;
  22. }
  23. static setItem(key: string, state?: any, isObject: boolean = false) {
  24. if (state) {
  25. sessionStorage.setItem(key, isObject ? JSON.stringify(state) : state);
  26. }
  27. }
  28. static removeItem(key: string) {
  29. sessionStorage.removeItem(key);
  30. }
  31. }