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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. /** 登录之前的地址 */
  16. static readonly redirectUrl = 'redirect-url';
  17. // /** 云际系统 Token */
  18. // static readonly jccTokenKey = 'jcc-token';
  19. /**
  20. * 获取 SessionStorage 值
  21. * @param key - SessionStorage key
  22. * @param isObject - 是不是对象
  23. */
  24. static getItem(key: string, isObject: boolean = false) {
  25. const jsonStr = sessionStorage.getItem(key);
  26. if (!isObject) {
  27. return jsonStr;
  28. }
  29. if (jsonStr) {
  30. return parseJsonText(jsonStr);
  31. }
  32. return null;
  33. }
  34. /**
  35. * 设置 SessionStorage 值
  36. * @param key - SessionStorage key
  37. * @param state - SessionStorage state
  38. * @param isObject - 是不是对象
  39. */
  40. static setItem(key: string, state?: any, isObject: boolean = false) {
  41. if (state) {
  42. sessionStorage.setItem(key, isObject ? JSON.stringify(state) : state);
  43. }
  44. }
  45. /**
  46. * 移除 SessionStorage 值
  47. * @param key - SessionStorage key
  48. */
  49. static removeItem(key: string) {
  50. sessionStorage.removeItem(key);
  51. }
  52. }