diff --git a/frontend/src/views/MyDiary.vue b/frontend/src/views/MyDiary.vue index 81b1599..2a7081f 100644 --- a/frontend/src/views/MyDiary.vue +++ b/frontend/src/views/MyDiary.vue @@ -125,7 +125,7 @@ 点击上传 - + @@ -137,7 +137,7 @@ 点击上传 - + @@ -149,14 +149,14 @@ 点击上传 - +
- +
@@ -580,15 +580,26 @@ async function handleUpload(type, event) { const isHeic = file.name.toLowerCase().match(/\.hei[cf]$/) || file.type === 'image/heic' || file.type === 'image/heif' if (isHeic) { - ui.showToast('正在转换HEIC格式...') + ui.showToast('正在转换格式...') try { const heic2any = (await import('heic2any')).default let blob = await heic2any({ blob: file, toType: 'image/jpeg', quality: 0.8 }) if (Array.isArray(blob)) blob = blob[0] file = new File([blob], 'photo.jpg', { type: 'image/jpeg' }) - } catch (e) { - ui.showToast('HEIC转换失败,请手动转为JPG后上传') - return + } catch { + // Fallback: try createImageBitmap (works on some browsers) + try { + const bmp = await createImageBitmap(file) + const canvas = document.createElement('canvas') + canvas.width = bmp.width + canvas.height = bmp.height + canvas.getContext('2d').drawImage(bmp, 0, 0) + const jpegBlob = await new Promise(r => canvas.toBlob(r, 'image/jpeg', 0.8)) + file = new File([jpegBlob], 'photo.jpg', { type: 'image/jpeg' }) + } catch { + ui.showToast('该格式暂不支持,请在相册中选择"自动"格式或转为JPG后上传') + return + } } } let base64 = await readFileAsBase64(file)