assignObject: function(target, source1, source2) {
target = source1; /* 简单复制地址,严谨来说应该是做深度拷贝处理 */
Object.keys(source2).forEach(function(key) {
if (target[key] != undefined) {
target[key] = source2[key];
}
});
return target;
},这个地方
if (target[key] != undefined) {
target[key] = source2[key];
}在赋值的时候 把事件给搞掉了!
两个地方建议改下:
1.上传大文件会崩。
convertToBase: function(file) {
// var reader,
// isImg = this.checkImg(file);
// if (typeof FileReader !== 'undefined') {
// reader = new FileReader();
// } else {
// if (window.FileReader) reader = new window.FileReader();
// }
// reader.onload = (e) => {
// var base = e.target.result;
// if (isImg) {
// this.compressImg(base, file);
// } else {
// this.formatFile(file, iconFile, base);
// }
// }
// reader.readAsDataURL(file);
var base = "";
this.formatFile(file, iconFile, base);
},convertToBase这个方法修改,去掉了加载文件的操作,全程好像也不需要用到,注释掉的为原来的代码。当然,图片不大要预览可以转一下。
2. 随着文件选择次数增加,每次添加文件会重复。
找了老半天,终于找到了问题所在。
$(".btn-select-file").off("click").on("click", function() {
that.node.list = $(this).parent().siblings(".list");
console.info("chufa");
$(this).parent().children(".input-file").trigger("click").on("change", function(e) {
that.fileObj = {
fileList: e.target.files,
isReady: true
};
that.node.input = $(this);
console.info("doUpdateFiles")
that.updateFiles();
that.configs.onChange && that.configs.onChange(e.target.files);
$(this).parent().children(".input-file").unbind("change");
});
});这个文件选择点击事件中,在方法中加入
$(this).parent().children(".input-file").unbind("change");否则在每次点击选择文件都会触发上次的onchange,所以文件重复添加了