修复:本地上传文件 开启分片功能时,报错提示2次的问题

pull/486/head
lande 2025-01-14 10:23:54 +08:00
parent 9bdf43e808
commit f50cb727cb
1 changed files with 446 additions and 445 deletions

View File

@ -83,10 +83,10 @@ define(['jquery', 'bootstrap', 'dropzone', 'template'], function ($, undefined,
try { try {
var ret = typeof response === 'object' ? response : JSON.parse(response); var ret = typeof response === 'object' ? response : JSON.parse(response);
if (!ret.hasOwnProperty('code')) { if (!ret.hasOwnProperty('code')) {
$.extend(ret, {code: -2, msg: response, data: null}); $.extend(ret, { code: -2, msg: response, data: null });
} }
} catch (e) { } catch (e) {
var ret = {code: -1, msg: e.message, data: null}; var ret = { code: -1, msg: e.message, data: null };
} }
return ret; return ret;
}, },
@ -163,7 +163,7 @@ define(['jquery', 'bootstrap', 'dropzone', 'template'], function ($, undefined,
var matches = maxsize.toString().match(/^([0-9\.]+)(\w+)$/); var matches = maxsize.toString().match(/^([0-9\.]+)(\w+)$/);
var size = matches ? parseFloat(matches[1]) : parseFloat(maxsize), var size = matches ? parseFloat(matches[1]) : parseFloat(maxsize),
unit = matches ? matches[2].toLowerCase() : 'b'; unit = matches ? matches[2].toLowerCase() : 'b';
var unitDict = {'b': 0, 'k': 1, 'kb': 1, 'm': 2, 'mb': 2, 'gb': 3, 'g': 3, 'tb': 4, 't': 4}; var unitDict = { 'b': 0, 'k': 1, 'kb': 1, 'm': 2, 'mb': 2, 'gb': 3, 'g': 3, 'tb': 4, 't': 4 };
var y = typeof unitDict[unit] !== 'undefined' ? unitDict[unit] : 0; var y = typeof unitDict[unit] !== 'undefined' ? unitDict[unit] : 0;
var bytes = size * Math.pow(1024, y); var bytes = size * Math.pow(1024, y);
return bytes / Math.pow(1024, 2); return bytes / Math.pow(1024, 2);
@ -261,7 +261,7 @@ define(['jquery', 'bootstrap', 'dropzone', 'template'], function ($, undefined,
var responseObj = $("<div>" + (xhr && typeof xhr.responseText !== 'undefined' ? xhr.responseText : response) + "</div>"); var responseObj = $("<div>" + (xhr && typeof xhr.responseText !== 'undefined' ? xhr.responseText : response) + "</div>");
responseObj.find("style, title, script").remove(); responseObj.find("style, title, script").remove();
var msg = responseObj.text() || __('Network error'); var msg = responseObj.text() || __('Network error');
var ret = {code: 0, data: null, msg: msg}; var ret = { code: 0, data: null, msg: msg };
Upload.events.onUploadError(this, ret, file); Upload.events.onUploadError(this, ret, file);
}, },
uploadprogress: function (file, progress, bytesSent) { uploadprogress: function (file, progress, bytesSent) {
@ -298,6 +298,7 @@ define(['jquery', 'bootstrap', 'dropzone', 'template'], function ($, undefined,
}, function (data, ret) { }, function (data, ret) {
file.accepted = false; file.accepted = false;
that._errorProcessing([file], ret.msg); that._errorProcessing([file], ret.msg);
return false;
}); });
}, },
onUploadSuccess: onUploadSuccess, onUploadSuccess: onUploadSuccess,
@ -363,10 +364,10 @@ define(['jquery', 'bootstrap', 'dropzone', 'template'], function ($, undefined,
var suffix = /[\.]?([a-zA-Z0-9]+)$/.exec(j); var suffix = /[\.]?([a-zA-Z0-9]+)$/.exec(j);
suffix = suffix ? suffix[1] : 'file'; suffix = suffix ? suffix[1] : 'file';
var btnData = $(that).data(); var btnData = $(that).data();
var fullurl = typeof btnData.cdnurl!=='undefined' ? Fast.api.cdnurl(j, btnData.cdnurl) : Fast.api.cdnurl(j); var fullurl = typeof btnData.cdnurl !== 'undefined' ? Fast.api.cdnurl(j, btnData.cdnurl) : Fast.api.cdnurl(j);
j = Config.upload.fullmode ? fullurl : j; j = Config.upload.fullmode ? fullurl : j;
var value = (json && typeof json[i] !== 'undefined' ? json[i] : null); var value = (json && typeof json[i] !== 'undefined' ? json[i] : null);
var data = {url: j, fullurl: fullurl, data: btnData, key: i, index: i, value: value, row: value, suffix: suffix}; var data = { url: j, fullurl: fullurl, data: btnData, key: i, index: i, value: value, row: value, suffix: suffix };
var html = tpl ? Template(tpl, data) : Template.render(Upload.config.previewtpl, data); var html = tpl ? Template(tpl, data) : Template.render(Upload.config.previewtpl, data);
previewObj.append(html); previewObj.append(html);
}); });
@ -437,7 +438,7 @@ define(['jquery', 'bootstrap', 'dropzone', 'template'], function ($, undefined,
}, },
// AJAX异步上传 // AJAX异步上传
send: function (file, onUploadSuccess, onUploadError, onUploadComplete) { send: function (file, onUploadSuccess, onUploadError, onUploadComplete) {
var index = Layer.msg(__('Uploading'), {offset: 't', time: 0}); var index = Layer.msg(__('Uploading'), { offset: 't', time: 0 });
var id = "dropzone-" + Dropzone.uuidv4(); var id = "dropzone-" + Dropzone.uuidv4();
$('<button type="button" id="' + id + '" class="btn btn-danger hidden faupload" />').appendTo("body"); $('<button type="button" id="' + id + '" class="btn btn-danger hidden faupload" />').appendTo("body");
$("#" + id).data("upload-complete", function (files) { $("#" + id).data("upload-complete", function (files) {