Selaa lähdekoodia

fix: 优化坐标转换逻辑,解决频率限制问题

- 将批量转换大小从100个坐标减少到50个,降低请求频率
- 将批次间隔从100ms增加到2000ms,避免触发API频率限制
- 添加频率限制错误处理,遇到CUQPS_HAS_EXCEEDED_THE_LIMIT错误时自动重试
- 增加详细的错误日志和重试提示,提高用户体验
sequoia tungfang 4 viikkoa sitten
vanhempi
commit
6533682357
1 muutettua tiedostoa jossa 13 lisäystä ja 4 poistoa
  1. 13 4
      src/components/TongzhouTrafficMap.vue

+ 13 - 4
src/components/TongzhouTrafficMap.vue

@@ -177,8 +177,8 @@ export default {
 
       console.log('开始转换百度地图坐标为高德地图坐标...');
       
-      // 批量转换,每次最多100个坐标
-      const batchSize = 100;
+      // 批量转换,每次最多50个坐标,减少请求频率
+      const batchSize = 50;
       const total = this.intersectionData.length;
       
       for (let i = 0; i < total; i += batchSize) {
@@ -212,11 +212,20 @@ export default {
           console.log(`已转换 ${Math.min(i + batchSize, total)} / ${total} 个坐标`);
         } catch (error) {
           console.error('坐标转换失败:', error);
+          
+          // 如果是频率限制错误,等待更长时间后重试
+          if (error.message.includes('CUQPS_HAS_EXCEEDED_THE_LIMIT')) {
+            console.log('遇到频率限制,等待5秒后重试...');
+            await new Promise(resolve => setTimeout(resolve, 5000));
+            // 重试当前批次
+            i -= batchSize;
+            continue;
+          }
         }
 
-        // 避免请求过于频繁
+        // 避免请求过于频繁,增加等待时间
         if (i + batchSize < total) {
-          await new Promise(resolve => setTimeout(resolve, 100));
+          await new Promise(resolve => setTimeout(resolve, 2000));
         }
       }