|
|
|
@ -323,7 +323,7 @@ layui.define(['lay', 'layer'], function(exports){
|
|
|
|
|
'Upload failed, please try again.', |
|
|
|
|
'status: '+ (e.status || '') +' - '+ (e.statusText || 'error') |
|
|
|
|
].join('<br>')); |
|
|
|
|
error(sets.index); |
|
|
|
|
error(sets.index, e.responseText); |
|
|
|
|
allDone(sets.index); |
|
|
|
|
resetFileState(sets.file); |
|
|
|
|
} |
|
|
|
@ -386,22 +386,42 @@ layui.define(['lay', 'layer'], function(exports){
|
|
|
|
|
} |
|
|
|
|
}, 30);
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
// 统一回调
|
|
|
|
|
var done = function(index, res){ |
|
|
|
|
that.elemFile.next('.'+ ELEM_CHOOSE).remove(); |
|
|
|
|
elemFile.value = ''; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 强制返回的数据格式
|
|
|
|
|
var forceConvert = function(src) { |
|
|
|
|
if(options.force === 'json'){ |
|
|
|
|
if(typeof res !== 'object'){ |
|
|
|
|
if(typeof src !== 'object'){ |
|
|
|
|
try { |
|
|
|
|
res = JSON.parse(res); |
|
|
|
|
return { |
|
|
|
|
status: "CONVERTED", |
|
|
|
|
data: JSON.parse(src) |
|
|
|
|
}; |
|
|
|
|
} catch(e){ |
|
|
|
|
res = {}; |
|
|
|
|
return that.msg(text['data-format-error']); |
|
|
|
|
that.msg(text['data-format-error']); |
|
|
|
|
return { |
|
|
|
|
status: "FORMAT_ERROR", |
|
|
|
|
data: {} |
|
|
|
|
}; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return { status: "DO_NOTHING", data: {} } |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 统一回调
|
|
|
|
|
var done = function(index, res){ |
|
|
|
|
that.elemFile.next('.'+ ELEM_CHOOSE).remove(); |
|
|
|
|
elemFile.value = ''; |
|
|
|
|
|
|
|
|
|
var convert = forceConvert(res); |
|
|
|
|
|
|
|
|
|
switch(convert.status) { |
|
|
|
|
case "CONVERTED": |
|
|
|
|
res = convert.data; |
|
|
|
|
break; |
|
|
|
|
case "FORMAT_ERROR": |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
typeof options.done === 'function' && options.done(res, index || 0, function(files){ |
|
|
|
|
that.upload(files); |
|
|
|
@ -409,13 +429,24 @@ layui.define(['lay', 'layer'], function(exports){
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
// 统一网络异常回调
|
|
|
|
|
var error = function(index){ |
|
|
|
|
var error = function(index, res){ |
|
|
|
|
if(options.auto){ |
|
|
|
|
elemFile.value = ''; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
var convert = forceConvert(res); |
|
|
|
|
|
|
|
|
|
switch(convert.status) { |
|
|
|
|
case "CONVERTED": |
|
|
|
|
res = convert.data; |
|
|
|
|
break; |
|
|
|
|
case "FORMAT_ERROR": |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
typeof options.error === 'function' && options.error(index || 0, function(files){ |
|
|
|
|
that.upload(files); |
|
|
|
|
}); |
|
|
|
|
}, res); |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
var check; |
|
|
|
|