Browse Source

KERNEL-4881 refactor: bi.multifile_editor 简化,自动重置状态, accept 属性与标准统一

es6
zsmj1994 4 years ago
parent
commit
b08d7ca9d8
  1. 1
      changelog.md
  2. 7
      src/base/single/editor/editor.multifile.js
  3. 31
      src/base/single/input/file.js

1
changelog.md

@ -1,5 +1,6 @@
# 更新日志 # 更新日志
2.0(2020-07) 2.0(2020-07)
- bi.file文件上传控件accept属性与 [input accept Attribute](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/file#accept) 统一
- BI.OB的on方法返回一个解除监听的函数 - BI.OB的on方法返回一个解除监听的函数
- 修复了grid_view执行_unMount时不调用子组件的_unMount的问题 - 修复了grid_view执行_unMount时不调用子组件的_unMount的问题
- combo新增belowMouse属性,允许popup在点击处弹出 - combo新增belowMouse属性,允许popup在点击处弹出

7
src/base/single/editor/editor.multifile.js

@ -66,6 +66,10 @@ BI.MultifileEditor = BI.inherit(BI.Widget, {
}); });
}, },
_reset: function () {
this.file.reset();
},
select: function () { select: function () {
this.file.select(); this.file.select();
}, },
@ -75,11 +79,12 @@ BI.MultifileEditor = BI.inherit(BI.Widget, {
}, },
upload: function () { upload: function () {
this._reset();
this.file.upload(); this.file.upload();
}, },
reset: function () { reset: function () {
this.file.reset(); this._reset();
} }
}); });
BI.MultifileEditor.EVENT_CHANGE = "EVENT_CHANGE"; BI.MultifileEditor.EVENT_CHANGE = "EVENT_CHANGE";

31
src/base/single/input/file.js

@ -401,6 +401,31 @@
return handler; return handler;
}; };
var r1 = /\.([^.]+)$/; // .png
var r2 = /\/([^/]+)$/; // image/png
/**
* 校验文件类型是否合法,同时兼容旧版形式
* @param fileName
* @param fileType
* @returns {boolean}
*/
var fileTypeValidate = function (fileName, fileType) {
var mimes = fileType.split(",");
if (mimes[0] === fileType) {
mimes = (fileType + "").split(";");
}
return BI.some(mimes, function (index, mime) {
var matches;
if (matches = mime.match(r1)) {
return fileName.toLowerCase().indexOf(matches[1]) > -1;
}
if (matches = mime.match(r2)) {
return matches[1] === "*" ? true : fileName.toLowerCase().indexOf(matches[1]) > -1;
}
});
};
BI.File = BI.inherit(BI.Widget, { BI.File = BI.inherit(BI.Widget, {
_defaultConfig: function () { _defaultConfig: function () {
var conf = BI.File.superclass._defaultConfig.apply(this, arguments); var conf = BI.File.superclass._defaultConfig.apply(this, arguments);
@ -413,7 +438,7 @@
name: "", name: "",
url: "", url: "",
multiple: true, multiple: true,
accept: "", /** '*.jpg; *.zip'**/ accept: "", // .png,.pdf,image/jpg,image/* 等
maxSize: -1 // 1024 * 1024 maxSize: -1 // 1024 * 1024
}); });
}, },
@ -426,6 +451,7 @@
} }
this.element.attr("name", o.name || this.getName()); this.element.attr("name", o.name || this.getName());
this.element.attr("title", o.title || ""); this.element.attr("title", o.title || "");
this.element.attr("accept", o.accept);
}, },
created: function () { created: function () {
@ -520,7 +546,8 @@
var value = item.fileName || (item.fileName = tempFile.split("\\").pop()), var value = item.fileName || (item.fileName = tempFile.split("\\").pop()),
ext = -1 !== value.indexOf(".") ? value.split(".").pop().toLowerCase() : "unknown", ext = -1 !== value.indexOf(".") ? value.split(".").pop().toLowerCase() : "unknown",
size = item.fileSize || item.size; size = item.fileSize || item.size;
if (wrap.fileType && -1 === wrap.fileType.indexOf("*." + ext)) { var validateFileType = fileTypeValidate(value, wrap.fileType);
if (!validateFileType) {
// 文件类型不支持 // 文件类型不支持
BI.Msg.toast(BI.i18nText("BI-Upload_File_Type_Error"), { level: "error" }); BI.Msg.toast(BI.i18nText("BI-Upload_File_Type_Error"), { level: "error" });
self.fireEvent(BI.File.EVENT_ERROR, { self.fireEvent(BI.File.EVENT_ERROR, {

Loading…
Cancel
Save