|
|
@ -52,6 +52,7 @@ layui.define(['lay','layer'], function(exports){
|
|
|
|
var ELEM_IFRAME = 'layui-upload-iframe';
|
|
|
|
var ELEM_IFRAME = 'layui-upload-iframe';
|
|
|
|
var ELEM_CHOOSE = 'layui-upload-choose';
|
|
|
|
var ELEM_CHOOSE = 'layui-upload-choose';
|
|
|
|
var ELEM_DRAG = 'layui-upload-drag';
|
|
|
|
var ELEM_DRAG = 'layui-upload-drag';
|
|
|
|
|
|
|
|
var UPLOADING = 'UPLOADING';
|
|
|
|
|
|
|
|
|
|
|
|
// 构造器
|
|
|
|
// 构造器
|
|
|
|
var Class = function(options){
|
|
|
|
var Class = function(options){
|
|
|
@ -218,16 +219,37 @@ layui.define(['lay','layer'], function(exports){
|
|
|
|
var request = function(sets){
|
|
|
|
var request = function(sets){
|
|
|
|
var formData = new FormData();
|
|
|
|
var formData = new FormData();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 删除正在上传中的文件队列
|
|
|
|
|
|
|
|
var removeUploaded = function(index, file) {
|
|
|
|
|
|
|
|
if (file[UPLOADING]) {
|
|
|
|
|
|
|
|
delete items[index];
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// 追加额外的参数
|
|
|
|
// 追加额外的参数
|
|
|
|
layui.each(options.data, function(key, value){
|
|
|
|
layui.each(options.data, function(key, value){
|
|
|
|
value = typeof value === 'function' ? value() : value;
|
|
|
|
value = typeof value === 'function' ? value() : value;
|
|
|
|
formData.append(key, value);
|
|
|
|
formData.append(key, value);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
// 添加 file 到表单域
|
|
|
|
/*
|
|
|
|
sets.unified ? layui.each(items, function(index, file){
|
|
|
|
*添加 file 到表单域
|
|
|
|
formData.append(options.field, file);
|
|
|
|
*/
|
|
|
|
}) : formData.append(options.field, sets.file);
|
|
|
|
|
|
|
|
|
|
|
|
// 是否统一上传
|
|
|
|
|
|
|
|
if (sets.unified) {
|
|
|
|
|
|
|
|
layui.each(items, function(index, file){
|
|
|
|
|
|
|
|
if (removeUploaded(index, file)) return;
|
|
|
|
|
|
|
|
file[UPLOADING] = true;
|
|
|
|
|
|
|
|
formData.append(options.field, file);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
} else { // 逐一上传
|
|
|
|
|
|
|
|
if (removeUploaded(sets.index, sets.file)) return;
|
|
|
|
|
|
|
|
formData.append(options.field, sets.file);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
sets.file[UPLOADING] = true; // 上传中的标记
|
|
|
|
|
|
|
|
|
|
|
|
// ajax 参数
|
|
|
|
// ajax 参数
|
|
|
|
var opts = {
|
|
|
|
var opts = {
|
|
|
|