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

1234567891011121314151617181920212223242526272829303132333435363738
  1. // 用于新建镜像
  2. export const mirrorNameKey = 'mirror-name';
  3. // 模型部署
  4. export const modelDeploymentInfoKey = 'model-deployment-info';
  5. // 编辑器 url
  6. export const editorUrlKey = 'editor-url';
  7. export const getSessionStorageItem = (key: string, isObject: boolean = false) => {
  8. const jsonStr = sessionStorage.getItem(key);
  9. if (!isObject) {
  10. return jsonStr;
  11. }
  12. if (jsonStr) {
  13. try {
  14. return JSON.parse(jsonStr);
  15. } catch (error) {
  16. return undefined;
  17. }
  18. }
  19. return undefined;
  20. };
  21. export const setSessionStorageItem = (key: string, state?: any, isObject: boolean = false) => {
  22. if (state) {
  23. sessionStorage.setItem(key, isObject ? JSON.stringify(state) : state);
  24. }
  25. };
  26. export const removeSessionStorageItem = (key: string) => {
  27. sessionStorage.removeItem(key);
  28. };
  29. // 获取之后就删除,多用于上一个页面传递数据到下一个页面
  30. export const getSessionItemThenRemove = (key: string, isObject: boolean = false) => {
  31. const res = getSessionStorageItem(key, isObject);
  32. sessionStorage.removeItem(key);
  33. return res;
  34. };