test(KYC页): 测试图片上传方式

This commit is contained in:
hzj 2025-11-12 17:08:24 +08:00
parent 3f482aa23c
commit 8e4b4d4d6f
2 changed files with 15 additions and 16 deletions

View File

@ -17,17 +17,17 @@ export function uploadImgFile(renderFun) {
try { try {
if (android()) { if (android()) {
console.debug('Flutter Android WebView 检测') console.log('Flutter Android WebView 检测')
console.debug('window.app 对象:', window.app) console.log('window.app 对象:', window.app)
// 检查Flutter注入的接口 // 检查Flutter注入的接口
if (window.app) { if (window.app) {
console.debug('window.app 的所有方法:') console.log('window.app 的所有方法:')
console.debug(Object.keys(window.app)) console.log(Object.keys(window.app))
// 检查具体的方法 // 检查具体的方法
console.debug('uploadImgFile 方法存在?', typeof window.app.uploadImgFile) console.log('uploadImgFile 方法存在?', typeof window.app.uploadImgFile)
console.debug('uploadImgFile 是函数?', typeof window.app.uploadImgFile === 'function') console.log('uploadImgFile 是函数?', typeof window.app.uploadImgFile === 'function')
} }
// 等待Flutter注入完成 // 等待Flutter注入完成
@ -38,17 +38,17 @@ export function uploadImgFile(renderFun) {
// 循环检测Flutter接口 // 循环检测Flutter接口
const checkInterface = () => { const checkInterface = () => {
attempts++ attempts++
console.debug(`尝试第 ${attempts} 次检查Flutter接口...`) console.log(`尝试第 ${attempts} 次检查Flutter接口...`)
if ( if (
window.app && window.app &&
window.app.uploadImgFile && window.app.uploadImgFile &&
typeof window.app.uploadImgFile === 'function' typeof window.app.uploadImgFile === 'function'
) { ) {
console.debug('Flutter接口检测成功调用 uploadImgFile') console.log('Flutter接口检测成功调用 uploadImgFile')
try { try {
const result = window.app.uploadImgFile() const result = window.app.uploadImgFile()
console.debug('uploadImgFile 返回结果:', result) console.log('uploadImgFile 返回结果:', result)
renderFun(result) renderFun(result)
} catch (error) { } catch (error) {
console.error('调用 uploadImgFile 出错:', error) console.error('调用 uploadImgFile 出错:', error)
@ -71,13 +71,13 @@ export function uploadImgFile(renderFun) {
if (window.app) { if (window.app) {
waitForFlutterInterface() waitForFlutterInterface()
} else { } else {
console.debug('等待Flutter注入window.app...') console.log('等待Flutter注入window.app...')
// 监听window.app的创建 // 监听window.app的创建
let checkCount = 0 let checkCount = 0
const checkApp = () => { const checkApp = () => {
checkCount++ checkCount++
if (window.app) { if (window.app) {
console.debug('检测到window.app开始连接') console.log('检测到window.app开始连接')
waitForFlutterInterface() waitForFlutterInterface()
} else if (checkCount < 50) { } else if (checkCount < 50) {
setTimeout(checkApp, 100) setTimeout(checkApp, 100)
@ -92,7 +92,7 @@ export function uploadImgFile(renderFun) {
checkApp() checkApp()
} }
} else { } else {
console.debug('非移动设备环境') console.log('非移动设备环境')
// 非APP环境可能是浏览器调试 // 非APP环境可能是浏览器调试
console.warn('Not in APP environment, using mock data for development') console.warn('Not in APP environment, using mock data for development')
// 开发环境可以提供模拟数据 // 开发环境可以提供模拟数据

View File

@ -248,7 +248,6 @@ const callNativeImagePicker = () => {
// //
if (!access || access === '""' || access === '') { if (!access || access === '""' || access === '') {
console.warn('接收到空的图片数据') console.warn('接收到空的图片数据')
showWarning(t('no_image_selected'))
reject(new Error('No image selected')) reject(new Error('No image selected'))
return return
} }
@ -275,18 +274,18 @@ const callNativeImagePicker = () => {
} else { } else {
const errorMsg = result.error || t('file_selection_failed') const errorMsg = result.error || t('file_selection_failed')
console.error('图片选择失败:', errorMsg) console.error('图片选择失败:', errorMsg)
showError(errorMsg) // showError(errorMsg)
reject(new Error(errorMsg)) reject(new Error(errorMsg))
} }
} catch (error) { } catch (error) {
console.error('处理原生图片选择结果失败:', error) console.error('处理原生图片选择结果失败:', error)
showError(t('file_processing_failed')) // showError(t('file_processing_failed'))
reject(error) reject(error)
} }
}) })
} catch (error) { } catch (error) {
console.error('调用原生图片选择器失败:', error) console.error('调用原生图片选择器失败:', error)
showError(t('native_image_picker_failed')) // showError(t('native_image_picker_failed'))
reject(error) reject(error)
} }
}) })