diff --git a/src/utils/uploadFiles.js b/src/utils/uploadFiles.js new file mode 100644 index 0000000..53abe8d --- /dev/null +++ b/src/utils/uploadFiles.js @@ -0,0 +1,121 @@ +/** + * 上传图片 + * @param {Function} renderFun 回调函数,接收APP传递的access参数 + */ +export function uploadImgFile(renderFun) { + window.renderData = renderFun + // 兼容历史版本 + window.getIosAccessOriginParam = renderFun + + try { + if (android()) { + console.debug('Flutter Android WebView 检测') + console.debug('window.app 对象:', window.app) + + // 检查Flutter注入的接口 + if (window.app) { + console.debug('window.app 的所有方法:') + console.debug(Object.keys(window.app)) + + // 检查具体的方法 + console.debug('uploadImgFile 方法存在?', typeof window.app.uploadImgFile) + console.debug('uploadImgFile 是函数?', typeof window.app.uploadImgFile === 'function') + } + + // 等待Flutter注入完成 + const waitForFlutterInterface = () => { + let attempts = 0 + const maxAttempts = 50 // 最多等待5秒 + + // 循环检测Flutter接口 + const checkInterface = () => { + attempts++ + console.debug(`尝试第 ${attempts} 次检查Flutter接口...`) + + if ( + window.app && + window.app.uploadImgFile && + typeof window.app.uploadImgFile === 'function' + ) { + console.debug('Flutter接口检测成功,调用 uploadImgFile') + try { + const result = window.app.uploadImgFile() + console.debug('uploadImgFile 返回结果:', result) + renderFun(result) + } catch (error) { + console.error('调用 uploadImgFile 出错:', error) + } + } else if (attempts < maxAttempts) { + // 继续等待 + setTimeout(checkInterface, 100) + } else { + console.error('Flutter接口注入超时,使用默认数据') + // 使用默认的开发数据 + const mockAccess = JSON.stringify('') + renderFun(mockAccess) + } + } + + checkInterface() + } + + // 如果window.app已存在,直接检查,否则等待 + if (window.app) { + waitForFlutterInterface() + } else { + console.debug('等待Flutter注入window.app...') + // 监听window.app的创建 + let checkCount = 0 + const checkApp = () => { + checkCount++ + if (window.app) { + console.debug('检测到window.app,开始连接') + waitForFlutterInterface() + } else if (checkCount < 50) { + setTimeout(checkApp, 100) + } else { + console.error('等待window.app超时') + // 手动通知Flutter注入接口 + if (window.FlutterApp && window.FlutterApp.postMessage) { + window.FlutterApp.postMessage('uploadImgFile') + } + } + } + checkApp() + } + } else { + console.debug('非移动设备环境') + // 非APP环境,可能是浏览器调试 + console.warn('Not in APP environment, using mock data for development') + // 开发环境可以提供模拟数据 + if (process.env.NODE_ENV === 'development') { + const mockAccess = '' + setTimeout(() => renderFun(mockAccess), 100) + } + } + } catch (error) { + console.error('Failed to connect to APP:', error) + } +} + +/** + * 解析APP传递的访问参数 + * @param {string} access JSON字符串格式的访问参数 + * @returns {Object} 解析后的参数对象 + */ +export function parseAccessOrigin(access) { + try { + const accessParam = JSON.parse(access) + return { + success: true, + data: accessParam, + } + } catch (error) { + console.error('Failed to parse access origin:', error) + return { + success: false, + error: 'accessOrigin Error.', + data: null, + } + } +} diff --git a/src/views/Wallet/CashOut/KYC.vue b/src/views/Wallet/CashOut/KYC.vue index 85b3d4b..45f86b2 100644 --- a/src/views/Wallet/CashOut/KYC.vue +++ b/src/views/Wallet/CashOut/KYC.vue @@ -61,7 +61,22 @@ alt="" style="display: block; width: 15vw; aspect-ratio: 1/1; object-fit: cover" /> + - - -