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 let attempts = 0
const maxAttempts = 6000 // 最多等待60秒 const maxAttempts = 6000 // 最多等待60秒
// 清除之前的定时器(如果存在)
if (window._flutterCheckTimeout) {
clearTimeout(window._flutterCheckTimeout)
window._flutterCheckTimeout = null
}
const checkInterface = () => { const checkInterface = () => {
attempts++ attempts++
console.debug(`尝试第 ${attempts} 次检查Flutter接口...`) console.debug(`尝试第 ${attempts} 次检查Flutter接口...`)
@ -52,6 +58,11 @@ export function uploadImgFile(renderFun) {
typeof window.app.getImagePath === 'function' typeof window.app.getImagePath === 'function'
) { ) {
console.debug('Flutter接口检测成功调用 getImagePath') console.debug('Flutter接口检测成功调用 getImagePath')
// 清除定时器
if (window._flutterCheckTimeout) {
clearTimeout(window._flutterCheckTimeout)
window._flutterCheckTimeout = null
}
try { try {
const result = window.app.getImagePath() const result = window.app.getImagePath()
console.debug('getImagePath 返回结果:', result) console.debug('getImagePath 返回结果:', result)
@ -60,10 +71,15 @@ export function uploadImgFile(renderFun) {
console.error('调用 getImagePath 出错:', error) console.error('调用 getImagePath 出错:', error)
} }
} else if (attempts < maxAttempts) { } else if (attempts < maxAttempts) {
// 继续等待 // 保存timeout ID以便下次调用时清除
setTimeout(checkInterface, 100) window._flutterCheckTimeout = setTimeout(checkInterface, 100)
} else { } else {
console.error('Flutter接口注入超时使用默认数据') console.error('Flutter接口注入超时使用默认数据')
// 清除定时器
if (window._flutterCheckTimeout) {
clearTimeout(window._flutterCheckTimeout)
window._flutterCheckTimeout = null
}
// 使用默认的开发数据 // 使用默认的开发数据
const mockAccess = JSON.stringify({}) const mockAccess = JSON.stringify({})
renderFun(mockAccess) renderFun(mockAccess)