From edc7f9b7eae8fae5a5348ee0a318490161144265 Mon Sep 17 00:00:00 2001 From: JOJO <1498581755@qq.com> Date: Tue, 7 Apr 2026 11:50:48 +0800 Subject: [PATCH] fix: fallback upload selected local media on mobile webview --- static/src/app/methods/upload.ts | 33 +++++++++++--------------------- 1 file changed, 11 insertions(+), 22 deletions(-) diff --git a/static/src/app/methods/upload.ts b/static/src/app/methods/upload.ts index 897f62d..5bc3f80 100644 --- a/static/src/app/methods/upload.ts +++ b/static/src/app/methods/upload.ts @@ -90,23 +90,18 @@ export const uploadMethods = { return; } const valid = list.filter((file) => this.isImageFile(file)); - if (!valid.length) { - this.uiPushToast({ - title: '无法上传', - message: '仅支持图片文件', - type: 'warning' - }); - return; - } - if (valid.length < list.length) { + // 兼容 Android WebView 部分机型:返回的 File 可能缺失 type/扩展名,导致识别失败 + // 若来自图片选择器但未识别出有效类型,回退为“按选择结果直接上传”。 + const candidates = valid.length ? valid : list; + if (valid.length < list.length && valid.length > 0) { this.uiPushToast({ title: '已忽略', message: '已跳过非图片文件', type: 'info' }); } - const limited = valid.slice(0, remaining); - if (valid.length > remaining) { + const limited = candidates.slice(0, remaining); + if (candidates.length > remaining) { this.uiPushToast({ title: '已超出数量', message: `最多还能添加 ${remaining} 张图片,已自动截断`, @@ -146,29 +141,23 @@ export const uploadMethods = { return; } const valid = list.filter((file) => this.isVideoFile(file)); - if (!valid.length) { - this.uiPushToast({ - title: '无法上传', - message: '仅支持视频文件', - type: 'warning' - }); - return; - } - if (valid.length < list.length) { + // 兼容 Android WebView:文件元数据缺失时回退按选择结果直接上传 + const candidates = valid.length ? valid : list; + if (valid.length < list.length && valid.length > 0) { this.uiPushToast({ title: '已忽略', message: '已跳过非视频文件', type: 'info' }); } - if (valid.length > 1) { + if (candidates.length > 1) { this.uiPushToast({ title: '视频数量过多', message: '一次只能选择 1 个视频,已使用第一个', type: 'warning' }); } - const [file] = valid; + const [file] = candidates; if (!file) { return; }