fix: fallback upload selected local media on mobile webview
This commit is contained in:
parent
386f618c83
commit
edc7f9b7ea
@ -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;
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user