mirror of https://github.com/layui/layui
优化 upload 多文件模式中,正在上传中的文件会被再次触发上传的问题
parent
3123adfe13
commit
9a6b85f1a2
|
@ -52,6 +52,7 @@ layui.define(['lay','layer'], function(exports){
|
|||
var ELEM_IFRAME = 'layui-upload-iframe';
|
||||
var ELEM_CHOOSE = 'layui-upload-choose';
|
||||
var ELEM_DRAG = 'layui-upload-drag';
|
||||
var UPLOADING = 'UPLOADING';
|
||||
|
||||
// 构造器
|
||||
var Class = function(options){
|
||||
|
@ -218,16 +219,37 @@ layui.define(['lay','layer'], function(exports){
|
|||
var request = function(sets){
|
||||
var formData = new FormData();
|
||||
|
||||
// 删除正在上传中的文件队列
|
||||
var removeUploaded = function(index, file) {
|
||||
if (file[UPLOADING]) {
|
||||
delete items[index];
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
// 追加额外的参数
|
||||
layui.each(options.data, function(key, value){
|
||||
value = typeof value === 'function' ? value() : value;
|
||||
formData.append(key, value);
|
||||
});
|
||||
|
||||
// 添加 file 到表单域
|
||||
sets.unified ? layui.each(items, function(index, file){
|
||||
/*
|
||||
*添加 file 到表单域
|
||||
*/
|
||||
|
||||
// 是否统一上传
|
||||
if (sets.unified) {
|
||||
layui.each(items, function(index, file){
|
||||
if (removeUploaded(index, file)) return;
|
||||
file[UPLOADING] = true;
|
||||
formData.append(options.field, file);
|
||||
}) : formData.append(options.field, sets.file);
|
||||
});
|
||||
} else { // 逐一上传
|
||||
if (removeUploaded(sets.index, sets.file)) return;
|
||||
formData.append(options.field, sets.file);
|
||||
}
|
||||
|
||||
sets.file[UPLOADING] = true; // 上传中的标记
|
||||
|
||||
// ajax 参数
|
||||
var opts = {
|
||||
|
|
Loading…
Reference in New Issue