import { getSessionStorage } from '../../utils/storage';
import { useRoute } from 'vue-router';
import { ReportDesignApi } from '../../api/ReportDesignApi';

// 根据路由 id 获取存储数据的信息
export const getSessionStorageInfo = async () => {
  const route = useRoute();
  const { previewId, reportId } = route.query;
  if (previewId) {
    const storageList = getSessionStorage('CHART_STORAGE_LIST');

    if (!storageList) return;

    for (let i = 0; i < storageList.length; i++) {
      if (previewId.toString() === storageList[i]['id']) {
        return storageList[i];
      }
    }
  } else if (reportId) {
    const res = await ReportDesignApi.getConfig({ id: reportId });
    return res.data.reportConfig
  }
};
