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