From 746956b8227ed74a2a9ac475dd7bfae84c960d30 Mon Sep 17 00:00:00 2001 From: hzj <1304805162@qq.com> Date: Wed, 12 Nov 2025 20:42:22 +0800 Subject: [PATCH] =?UTF-8?q?test17(KYC=E9=A1=B5):=20=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=E5=9B=BE=E7=89=87=E8=8E=B7=E5=8F=96=E5=92=8C=E5=8F=91=E9=80=81?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=EF=BC=8C=E6=96=B0=E5=A2=9E=E6=B8=85=E9=99=A4?= =?UTF-8?q?=E8=AE=A1=E6=97=B6=E5=99=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/utils/uploadFiles.js | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/utils/uploadFiles.js b/src/utils/uploadFiles.js index 1518bae..9da62bf 100644 --- a/src/utils/uploadFiles.js +++ b/src/utils/uploadFiles.js @@ -42,6 +42,12 @@ export function uploadImgFile(renderFun) { let attempts = 0 const maxAttempts = 6000 // 最多等待60秒 + // 清除之前的定时器(如果存在) + if (window._flutterCheckTimeout) { + clearTimeout(window._flutterCheckTimeout) + window._flutterCheckTimeout = null + } + const checkInterface = () => { attempts++ console.debug(`尝试第 ${attempts} 次检查Flutter接口...`) @@ -52,6 +58,11 @@ export function uploadImgFile(renderFun) { typeof window.app.getImagePath === 'function' ) { console.debug('Flutter接口检测成功,调用 getImagePath') + // 清除定时器 + if (window._flutterCheckTimeout) { + clearTimeout(window._flutterCheckTimeout) + window._flutterCheckTimeout = null + } try { const result = window.app.getImagePath() console.debug('getImagePath 返回结果:', result) @@ -60,10 +71,15 @@ export function uploadImgFile(renderFun) { console.error('调用 getImagePath 出错:', error) } } else if (attempts < maxAttempts) { - // 继续等待 - setTimeout(checkInterface, 100) + // 保存timeout ID以便下次调用时清除 + window._flutterCheckTimeout = setTimeout(checkInterface, 100) } else { console.error('Flutter接口注入超时,使用默认数据') + // 清除定时器 + if (window._flutterCheckTimeout) { + clearTimeout(window._flutterCheckTimeout) + window._flutterCheckTimeout = null + } // 使用默认的开发数据 const mockAccess = JSON.stringify({}) renderFun(mockAccess)