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.5 kB

1 year ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. import { parseJsonText } from './index';
  2. export default class SessionStorage {
  3. /** 用于新建镜像 */
  4. static readonly mirrorNameKey = 'mirror-name';
  5. /** 模型部署服务版本 */
  6. static readonly serviceVersionInfoKey = 'service-version-info';
  7. /** 编辑器 url */
  8. static readonly editorUrlKey = 'editor-url';
  9. /** 客户端信息 */
  10. static readonly clientInfoKey = 'client-info';
  11. /** aim url */
  12. static readonly aimUrlKey = 'aim-url';
  13. /** tensorBoard url */
  14. static readonly tensorBoardUrlKey = 'tensor-board-url';
  15. // /** 云际系统 Token */
  16. // static readonly jccTokenKey = 'jcc-token';
  17. /**
  18. * 获取 SessionStorage 值
  19. * @param key - SessionStorage key
  20. * @param isObject - 是不是对象
  21. */
  22. static getItem(key: string, isObject: boolean = false) {
  23. const jsonStr = sessionStorage.getItem(key);
  24. if (!isObject) {
  25. return jsonStr;
  26. }
  27. if (jsonStr) {
  28. return parseJsonText(jsonStr);
  29. }
  30. return null;
  31. }
  32. /**
  33. * 设置 SessionStorage 值
  34. * @param key - SessionStorage key
  35. * @param state - SessionStorage state
  36. * @param isObject - 是不是对象
  37. */
  38. static setItem(key: string, state?: any, isObject: boolean = false) {
  39. if (state) {
  40. sessionStorage.setItem(key, isObject ? JSON.stringify(state) : state);
  41. }
  42. }
  43. /**
  44. * 移除 SessionStorage 值
  45. * @param key - SessionStorage key
  46. */
  47. static removeItem(key: string) {
  48. sessionStorage.removeItem(key);
  49. }
  50. }