瀏覽代碼

Clear cached monthly trend data before reloading and improve data fetching logic in trade analysis tab. Enhanced error handling for monthly trend data loading.

Zenas 5 天之前
父節點
當前提交
46f1dc80f6
共有 1 個文件被更改,包括 15 次插入7 次删除
  1. 15 7
      src/views/adweb/data/customsData.vue

+ 15 - 7
src/views/adweb/data/customsData.vue

@@ -881,6 +881,9 @@ const handleSearch = async () => {
   // 将参数保存到 queryParam 以供其他地方使用
   Object.assign(queryParam, params);
   
+  // 清除缓存的分析数据,以便在需要时重新加载
+  monthlyTrendData.value = [];
+  
   if (activeTabKey.value === 'transaction') {
     pagination.value.current = 1; // Reset to first page
     await handleTableChange(pagination.value);
@@ -978,10 +981,16 @@ const handleTabChange = async (key: string) => {
   if (key === 'companies') {
    
   } else if (key === 'tradeAnalysis') {
-    // Load trade analysis data
-    await Promise.all([
-      loadMonthlyTrendData(),
-    ]);
+    // 只在首次加载或数据为空时请求数据
+    if (monthlyTrendData.value.length === 0) {
+      loading.value = true;
+      try {
+        await loadMonthlyTrendData();
+      } finally {
+        loading.value = false;
+      }
+    }
+    // 否则使用缓存数据
   } else if (key === 'shippingAnalysis') {
 
   }
@@ -1005,9 +1014,8 @@ const loadMonthlyTrendData = async () => {
       }));
     }
   } catch (error) {
-    console.error('Failed to fetch data:', error);
-  } finally {
-    loading.value = false;
+    console.error('Failed to fetch monthly trend data:', error);
+    createMessage.error('加载月度趋势数据失败');
   }
 };