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 1.0 kB

1 year ago
12345678910111213141516171819202122232425262728293031323334353637
  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. // 自动机器学习记录ID
  14. static readonly autoMLRecordIDKey = 'auto-ml-record-id';
  15. static getItem(key: string, isObject: boolean = false) {
  16. const jsonStr = sessionStorage.getItem(key);
  17. if (!isObject) {
  18. return jsonStr;
  19. }
  20. if (jsonStr) {
  21. return parseJsonText(jsonStr);
  22. }
  23. return null;
  24. }
  25. static setItem(key: string, state?: any, isObject: boolean = false) {
  26. if (state) {
  27. sessionStorage.setItem(key, isObject ? JSON.stringify(state) : state);
  28. }
  29. }
  30. static removeItem(key: string) {
  31. sessionStorage.removeItem(key);
  32. }
  33. }