flyzto 5 сар өмнө
parent
commit
83f058e45b

+ 18 - 8
web/apps/web-antd/src/views/match/solutions/index.vue

@@ -12,6 +12,7 @@ const contentsPositionStore = useContentsPositionStore();
 const solutions = ref([]);
 const selectedSolutions = reactive([]);
 const totalProfit = ref({});
+const loopActive = ref(false);
 
 const psOptions = reactive({
   bet: 10000,
@@ -305,8 +306,21 @@ const formatSolution = (solution, eventsList) => {
 }
 
 const updateSolutions = async () => {
-  const { solutions: solutionsList, gamesEvents: eventsList } = await getSolutions();
-  solutions.value = solutionsList?.map(solution => formatSolution(solution, eventsList)) ?? [];
+  getSolutions()
+  .then(({ solutions: solutionsList, gamesEvents: eventsList }) => {
+    solutions.value = solutionsList?.map(solution => formatSolution(solution, eventsList)) ?? [];
+  })
+  .catch(error => {
+    console.error('Failed to update solutions:', error);
+    message.error('获取中单方案失败');
+  })
+  .finally(() => {
+    if (loopActive.value) {
+      setTimeout(() => {
+        updateSolutions();
+      }, 1000 * 10);
+    }
+  });
 }
 
 const showTotalProfit = async () => {
@@ -336,17 +350,13 @@ const toggleSolution = (sid, timestamp) => {
   }
 }
 
-let updateTimer = null;
-
 onMounted(() => {
+  loopActive.value = true;
   updateSolutions();
-  updateTimer = setInterval(() => {
-    updateSolutions();
-  }, 1000 * 10);
 });
 
 onUnmounted(() => {
-  clearInterval(updateTimer);
+  loopActive.value = false;
 });