|
372 | 372 | <script setup> |
373 | 373 | import { computed, ref, watch, reactive, onMounted, onUnmounted, nextTick } from "vue"; |
374 | 374 | import { ElMessage } from "element-plus"; |
375 | | -import { uploadFile } from "../utils/api"; |
| 375 | +import { getHistoryTraceIds, uploadFile } from "../utils/api"; |
376 | 376 | import selectComponent from "../components/select-component.vue"; |
377 | 377 | import smSelectComponent from "../components/sm-select-component.vue"; |
378 | 378 | import loadingSvg from "../components/loading-dot.vue"; |
@@ -830,39 +830,53 @@ const Back = () => { |
830 | 830 |
|
831 | 831 | function getCompletedIdList() { |
832 | 832 | const data = localStorage.getItem(completedTraceStorageKey); |
833 | | - return data ? JSON.parse(data) : []; |
834 | | -} |
| 833 | + if (!data) { |
| 834 | + return []; |
| 835 | + } |
835 | 836 |
|
836 | | -function buildHistoryTraceList() { |
837 | | - const groupedTraceMap = new Map(); |
838 | | - const completedIdList = getCompletedIdList(); |
| 837 | + try { |
| 838 | + return JSON.parse(data); |
| 839 | + } catch { |
| 840 | + return []; |
| 841 | + } |
| 842 | +} |
839 | 843 |
|
840 | | - completedIdList.forEach((traceId) => { |
841 | | - const normalizedTraceId = String(traceId || "").trim(); |
| 844 | +function appendTraceId(groupedTraceMap, traceId) { |
| 845 | + const normalizedTraceId = String(traceId || "").trim(); |
842 | 846 |
|
843 | | - if (!normalizedTraceId) { |
844 | | - return; |
845 | | - } |
| 847 | + if (!normalizedTraceId) { |
| 848 | + return; |
| 849 | + } |
846 | 850 |
|
847 | | - const separatorIndex = normalizedTraceId.indexOf("/"); |
848 | | - const scenario = |
849 | | - separatorIndex === -1 |
850 | | - ? normalizedTraceId |
851 | | - : normalizedTraceId.slice(0, separatorIndex); |
852 | | - const traceName = |
853 | | - separatorIndex === -1 |
854 | | - ? normalizedTraceId |
855 | | - : normalizedTraceId.slice(separatorIndex + 1); |
856 | | -
|
857 | | - if (!groupedTraceMap.has(scenario)) { |
858 | | - groupedTraceMap.set(scenario, new Map()); |
859 | | - } |
| 851 | + const separatorIndex = normalizedTraceId.indexOf("/"); |
| 852 | + const scenario = |
| 853 | + separatorIndex === -1 |
| 854 | + ? normalizedTraceId |
| 855 | + : normalizedTraceId.slice(0, separatorIndex); |
| 856 | + const traceName = |
| 857 | + separatorIndex === -1 |
| 858 | + ? normalizedTraceId |
| 859 | + : normalizedTraceId.slice(separatorIndex + 1); |
| 860 | +
|
| 861 | + if (!groupedTraceMap.has(scenario)) { |
| 862 | + groupedTraceMap.set(scenario, new Map()); |
| 863 | + } |
860 | 864 |
|
861 | | - groupedTraceMap.get(scenario).set(traceName, { |
862 | | - name: traceName, |
863 | | - id: normalizedTraceId, |
864 | | - }); |
| 865 | + groupedTraceMap.get(scenario).set(traceName, { |
| 866 | + name: traceName, |
| 867 | + id: normalizedTraceId, |
865 | 868 | }); |
| 869 | +} |
| 870 | +
|
| 871 | +async function buildHistoryTraceList() { |
| 872 | + const groupedTraceMap = new Map(); |
| 873 | + const completedIdList = getCompletedIdList(); |
| 874 | + const backendTraceIds = await getHistoryTraceIds().then((response) => |
| 875 | + Array.isArray(response) ? response : [] |
| 876 | + ).catch(() => []); |
| 877 | +
|
| 878 | + const traceIdList = [...new Set([...completedIdList, ...backendTraceIds])]; |
| 879 | + traceIdList.forEach((traceId) => appendTraceId(groupedTraceMap, traceId)); |
866 | 880 |
|
867 | 881 | historyScenarioList.value = Array.from(groupedTraceMap.entries()).map( |
868 | 882 | ([scenario, traceMap]) => ({ |
@@ -924,8 +938,8 @@ const viewTracePage = () => { |
924 | 938 | showPlayground.value = true; |
925 | 939 | }; |
926 | 940 |
|
927 | | -const openHistoryPanel = () => { |
928 | | - buildHistoryTraceList(); |
| 941 | +const openHistoryPanel = async () => { |
| 942 | + await buildHistoryTraceList(); |
929 | 943 | showPanel.value = 3; |
930 | 944 | showPlayground.value = false; |
931 | 945 | }; |
@@ -979,7 +993,7 @@ function moveSlider(index) { |
979 | 993 | } |
980 | 994 |
|
981 | 995 | onMounted(() => { |
982 | | - buildHistoryTraceList(); |
| 996 | + void buildHistoryTraceList(); |
983 | 997 | }); |
984 | 998 | </script> |
985 | 999 |
|
|
0 commit comments