storage.ts 1.25 KB
import { getSessionStorage, fetchRouteParamsLocation, JSONParse } from '@/utils'
import { StorageEnum } from '@/enums/storageEnum'
import { ChartEditStorage } from '@/store/modules/chartEditStore/chartEditStore.d'
import { getDataView } from '@/api/external/contentSave/content'

export interface ChartEditStorageType extends ChartEditStorage {
  id: string
}
// THINGS_KIT
// 根据路由 id 获取存储数据的信息
export const getSessionStorageInfo = async () => {
  const id = fetchRouteParamsLocation()
  const storageList: ChartEditStorageType[] = getSessionStorage(StorageEnum.GO_CHART_STORAGE_LIST)
  // 是否本地预览
  if (!storageList || storageList.findIndex(e => e.id === id.toString()) === -1) {
    // 接口调用
    const res = await getDataView(id)
    if (res) {
      const { dataViewContent, state, dataViewName, dataViewId } = res
      // if (state === 1) {
      //   // 跳转未发布页
      //   return { isRelease: false }
      // }
      return { ...JSONParse(dataViewContent?.content), id: dataViewId, projectName: dataViewName }
    } else {
      // 本地读取
      for (let i = 0; i < storageList.length; i++) {
        if (id.toString() === storageList[i]['id']) {
          return storageList[i]
        }
      }
    }
  }
}