feat(KYC页): 更改图片上传方式

This commit is contained in:
hzj 2025-11-12 12:22:53 +08:00
parent e98f7002ac
commit 5c4033611f

View File

@ -60,11 +60,14 @@
src="/src/assets/icon/addImg.png"
alt=""
style="display: block; width: 15vw; aspect-ratio: 1/1; object-fit: cover"
@click="triggerFileInput"
/>
<input
ref="fileInputRef"
type="file"
accept="image/*"
@change="handleFileChange"
style="position: absolute; inset: 0; opacity: 0"
style="display: none"
/>
</div>
@ -176,6 +179,8 @@ import { getWithdrawInfoList, addWithdrawInfo, updateWithdrawInfo } from '@/api/
const { t, locale } = useI18n()
const router = useRouter()
const fileInputRef = ref(null)
//
locale.value && setDocumentDirection(locale.value)
@ -201,37 +206,67 @@ const checkStatus = computed(() => {
return applyInfo.value.contactNumber != '' && previewUrls.value.length > 0
})
//
const triggerFileInput = () => {
console.log('触发文件选择')
if (fileInputRef.value) {
fileInputRef.value.click()
}
}
// ()
const handleFileChange = (e) => {
// 3
if (previewUrls.value.length < 3) {
const fileList = e.target.files //
console.log('=== 文件选择事件开始 ===')
try {
//
if (!e.target.files || e.target.files.length === 0) {
console.warn('No files selected or unsupported environment')
//
console.log(
'触发条件: !e.target=',
!e.target,
', !e.target.files=',
!e.target.files,
', e.target.files.length === 0=',
e.target.files?.length === 0
)
//
if (!fileList || fileList.length === 0) {
console.error('未选择文件')
return
}
//
const file = fileList[0]
if (!file.type || !file.type.startsWith('image/')) {
console.error(`不支持的文件类型: ${file.type || '未知'}`)
showError(t('unsupported_file_type'))
return
// 3
if (previewUrls.value.length < 3) {
const fileList = e.target.files //
//
if (!fileList || fileList.length === 0) {
console.error('未选择文件')
return
}
//
const file = fileList[0]
if (!file.type || !file.type.startsWith('image/')) {
console.error(`不支持的文件类型: ${file.type || '未知'}`)
showError(t('unsupported_file_type'))
return
}
// 3.
console.log('文件名:', file.name) // defaultAvatar.png
console.log('文件类型:', file.type) // image/png
console.log('文件大小:', (file.size / 1024).toFixed(2), 'KB')
//
previewUrls.value.push(URL.createObjectURL(file))
//
tempFiles.value.push(file)
} else {
showWarning(t('max_images_warning'))
}
// 3.
console.log('文件名:', file.name) // defaultAvatar.png
console.log('文件类型:', file.type) // image/png
console.log('文件大小:', (file.size / 1024).toFixed(2), 'KB')
//
previewUrls.value.push(URL.createObjectURL(file))
//
tempFiles.value.push(file)
} else {
showWarning(t('max_images_warning'))
} catch (error) {
console.error('File selection error:', error)
}
}