test17(KYC页): 测试图片获取和发送接口,新增清除计时器

This commit is contained in:
hzj 2025-11-12 20:42:22 +08:00
parent 6d65bfb7a9
commit 746956b822

View File

@ -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)