76 lines
2.1 KiB
JavaScript
76 lines
2.1 KiB
JavaScript
var _reloadData = '';
|
|
|
|
function closeMe() {
|
|
layer.closeMe(_reloadData);
|
|
}
|
|
|
|
//ESC按键关闭窗口
|
|
$(document).keyup(function (event) {
|
|
(event.keyCode === 27) && closeMe();
|
|
});
|
|
|
|
function UploadFile(options) {
|
|
|
|
if (!options || !options.url || !options.inputId) {
|
|
throw '[UploadFile]参数错误';
|
|
}
|
|
|
|
let file = $('#' + options.inputId).prop('files');
|
|
if (!file || !file[0]) return;
|
|
file = file[0];
|
|
|
|
var formData = new FormData();
|
|
formData.append("file", file, file.name);
|
|
formData.append("upload_file", true);
|
|
|
|
$.ajax({
|
|
type: "POST",
|
|
url: options.url,
|
|
xhr: function () {
|
|
var myXhr = $.ajaxSettings.xhr();
|
|
if (myXhr.upload) {
|
|
myXhr.upload.addEventListener('progress', options.progressFn, false);
|
|
}
|
|
return myXhr;
|
|
},
|
|
beforeSend() {
|
|
main.waitMe("show");
|
|
},
|
|
success: options.success,
|
|
error(error) {
|
|
main.alert("导入失败:" + error.statusText);
|
|
},
|
|
complete(result) {
|
|
main.waitMe("hide");
|
|
$('#' + options.inputId).val('');
|
|
},
|
|
async: true,
|
|
data: formData,
|
|
cache: false,
|
|
contentType: false,
|
|
processData: false,
|
|
timeout: 60000
|
|
});
|
|
}
|
|
|
|
function uploadClientVarietyConfig(url) {
|
|
let fileName = $("#openFile").val();
|
|
if (!fileName) {
|
|
return main.alert("请选择要导入的文件!");
|
|
}
|
|
let index = fileName.lastIndexOf(".");
|
|
let fileEx = index > 0 ? fileName.substr(index).toLowerCase() : '';
|
|
if (fileEx !== '.xlsx') {
|
|
return main.alert("只能上传.xlsx类型的文件!");
|
|
}
|
|
function success(data) {
|
|
if (data.success) {
|
|
_reloadData = 'reloadData';
|
|
main.alert(!data.totalNum ? '导入成功!' : "共 {0} 条数据,导入成功 {1} 条数据!".template(data.totalNum, data.successNum));
|
|
} else {
|
|
main.alert("导入失败:" + data.msg);
|
|
}
|
|
}
|
|
main.confirm("确定导入?", UploadFile.bind(null, { inputId: 'openFile', url: url, success: success }));
|
|
}
|