|
|
|
@ -403,6 +403,31 @@
|
|
|
|
|
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, { |
|
|
|
|
_defaultConfig: function () { |
|
|
|
|
var conf = BI.File.superclass._defaultConfig.apply(this, arguments); |
|
|
|
@ -415,7 +440,7 @@
|
|
|
|
|
name: "", |
|
|
|
|
url: "", |
|
|
|
|
multiple: true, |
|
|
|
|
accept: "", /** '*.jpg; *.zip'**/ |
|
|
|
|
accept: "", // .png,.pdf,image/jpg,image/* 等
|
|
|
|
|
maxSize: -1 // 1024 * 1024
|
|
|
|
|
}); |
|
|
|
|
}, |
|
|
|
@ -428,6 +453,7 @@
|
|
|
|
|
} |
|
|
|
|
this.element.attr("name", o.name || this.getName()); |
|
|
|
|
this.element.attr("title", o.title || ""); |
|
|
|
|
this.element.attr("accept", o.accept); |
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
created: function () { |
|
|
|
@ -522,7 +548,8 @@
|
|
|
|
|
var value = item.fileName || (item.fileName = tempFile.split("\\").pop()), |
|
|
|
|
ext = -1 !== value.indexOf(".") ? value.split(".").pop().toLowerCase() : "unknown", |
|
|
|
|
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" }); |
|
|
|
|
self.fireEvent(BI.File.EVENT_ERROR, { |
|
|
|
|