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

This commit is contained in:
hzj 2025-11-12 17:49:24 +08:00
parent 7084474298
commit ae808c0439
2 changed files with 38 additions and 19 deletions

View File

@ -11,21 +11,31 @@ export function android() {
* @param {Function} renderFun 回调函数接收APP传递的access参数
*/
export function uploadImgFile(renderFun) {
// 设置全局回调函数供原生App调用
window.renderData = renderFun
// iOS平台兼容
window.getIosAccessOriginParam = renderFun
try {
if (window.app && window.app.uploadImgFile) {
console.log('使用uploadImgFile')
console.log('使用window.app.uploadImgFile')
// 使用注入的方法
const result = window.app.uploadImgFile()
console.log('uploadImgFile 返回结果:', result)
console.log('uploadImgFile返回结果:', result)
renderFun(result)
} else if (window.FlutterPageControl) {
// 直接使用Flutter通道
window.FlutterPageControl.postMessage(`正在调用uploadImgFile`)
window.FlutterPageControl.postMessage(`需要调用uploadImgFile`)
} else {
// 降级处理
const mockAccess = JSON.stringify('')
renderFun(mockAccess)
}
} catch (error) {
console.error('上传图片失败:', error)
console.error('调出图片选择界面失败:', error)
// 异常情况下的兜底处理
const mockAccess = JSON.stringify('')
renderFun(mockAccess)
}
}

View File

@ -62,8 +62,7 @@
style="display: block; width: 15vw; aspect-ratio: 1/1; object-fit: cover"
/>
<button
v-if="isInAppEnvironment"
@click="callNativeImagePicker"
@click="onClickImagePicker"
style="
position: absolute;
top: 0;
@ -75,7 +74,7 @@
border: none;
"
></button>
<input
<!-- <input
v-else
type="file"
accept="image/*"
@ -90,7 +89,7 @@
opacity: 0;
cursor: pointer;
"
/>
/> -->
</div>
<img
@ -231,6 +230,16 @@ const checkStatus = computed(() => {
return applyInfo.value.contactNumber != '' && previewUrls.value.length > 0
})
//
const onClickImagePicker = async () => {
try {
await callNativeImagePicker()
} catch (error) {
console.error('图片选择失败:', error)
//
}
}
//
const callNativeImagePicker = () => {
console.log('调用原生图片选择器')
@ -238,7 +247,7 @@ const callNativeImagePicker = () => {
// 3
if (previewUrls.value.length >= 3) {
showWarning(t('max_images_warning'))
return Promise.resolve() // rejected Promise
return Promise.reject(new Error('Maximum number of images reached'))
}
return new Promise((resolve, reject) => {
@ -258,16 +267,16 @@ const callNativeImagePicker = () => {
const file = result.data
console.log('接收到原生图片数据:', file)
//
if (typeof file === 'string' && (file.startsWith('http') || file.startsWith('data:'))) {
// URLbase64
previewUrls.value.push(file)
tempFiles.value.push(file) //
} else {
//
previewUrls.value.push(file)
tempFiles.value.push(file)
}
// //
// if (typeof file === 'string' && (file.startsWith('http') || file.startsWith('data:'))) {
// // URLbase64
// previewUrls.value.push(file)
// tempFiles.value.push(file) //
// } else {
// //
// previewUrls.value.push(file)
// tempFiles.value.push(file)
// }
showSuccess(t('image_selected_success'))
resolve()