上传附件优化

This commit is contained in:
Dev
2026-09-30 15:59:39 +08:00
parent c793b70cbd
commit 36697b8b57
+8 -11
View File
@@ -44,24 +44,21 @@ Page({
}, },
// 凭证截图选择成功 // 凭证截图选择成功
// 注意:t-upload 绑定了 files,success 事件返回的是完整文件列表(含已选的旧文件),
// 必须整体覆盖,不能往 imageFiles 里追加,否则已选图片会重复
handleSuccessImage(e) { handleSuccessImage(e) {
const files = e.detail?.files || []; const files = e.detail?.files || [];
const { imageFiles, imageMax } = this.data; const { imageMax } = this.data;
const remain = imageMax - imageFiles.length; if (files.length > imageMax) {
const accepted = files.slice(0, remain);
if (files.length > remain) {
wx.showToast({ wx.showToast({
title: `最多上传${imageMax}张截图`, title: `最多上传${imageMax}张截图`,
icon: 'none' icon: 'none'
}); });
} }
if (!accepted.length) { const list = files.slice(0, imageMax);
return; this.setData({ imageFiles: list });
} // 只上传未完成的(已上传过的 status 为 done)
this.setData({ this.uploadFiles(list.filter(file => file.status !== 'done'), 'image');
imageFiles: [...imageFiles, ...accepted]
});
this.uploadFiles(accepted, 'image');
}, },
// 移除凭证截图 // 移除凭证截图