fix: fallback upload selected local media on mobile webview

This commit is contained in:
JOJO 2026-04-07 11:50:48 +08:00
parent 386f618c83
commit edc7f9b7ea

View File

@ -90,23 +90,18 @@ export const uploadMethods = {
return; return;
} }
const valid = list.filter((file) => this.isImageFile(file)); const valid = list.filter((file) => this.isImageFile(file));
if (!valid.length) { // 兼容 Android WebView 部分机型:返回的 File 可能缺失 type/扩展名,导致识别失败
this.uiPushToast({ // 若来自图片选择器但未识别出有效类型,回退为“按选择结果直接上传”。
title: '无法上传', const candidates = valid.length ? valid : list;
message: '仅支持图片文件', if (valid.length < list.length && valid.length > 0) {
type: 'warning'
});
return;
}
if (valid.length < list.length) {
this.uiPushToast({ this.uiPushToast({
title: '已忽略', title: '已忽略',
message: '已跳过非图片文件', message: '已跳过非图片文件',
type: 'info' type: 'info'
}); });
} }
const limited = valid.slice(0, remaining); const limited = candidates.slice(0, remaining);
if (valid.length > remaining) { if (candidates.length > remaining) {
this.uiPushToast({ this.uiPushToast({
title: '已超出数量', title: '已超出数量',
message: `最多还能添加 ${remaining} 张图片,已自动截断`, message: `最多还能添加 ${remaining} 张图片,已自动截断`,
@ -146,29 +141,23 @@ export const uploadMethods = {
return; return;
} }
const valid = list.filter((file) => this.isVideoFile(file)); const valid = list.filter((file) => this.isVideoFile(file));
if (!valid.length) { // 兼容 Android WebView文件元数据缺失时回退按选择结果直接上传
this.uiPushToast({ const candidates = valid.length ? valid : list;
title: '无法上传', if (valid.length < list.length && valid.length > 0) {
message: '仅支持视频文件',
type: 'warning'
});
return;
}
if (valid.length < list.length) {
this.uiPushToast({ this.uiPushToast({
title: '已忽略', title: '已忽略',
message: '已跳过非视频文件', message: '已跳过非视频文件',
type: 'info' type: 'info'
}); });
} }
if (valid.length > 1) { if (candidates.length > 1) {
this.uiPushToast({ this.uiPushToast({
title: '视频数量过多', title: '视频数量过多',
message: '一次只能选择 1 个视频,已使用第一个', message: '一次只能选择 1 个视频,已使用第一个',
type: 'warning' type: 'warning'
}); });
} }
const [file] = valid; const [file] = candidates;
if (!file) { if (!file) {
return; return;
} }