|
@@ -0,0 +1,153 @@
|
|
|
+$(function(){
|
|
|
+ initUpload();
|
|
|
+})
|
|
|
+
|
|
|
+function save() {
|
|
|
+ var file = $("#data_file")[0].files[0];//获取文件
|
|
|
+ var formData = new FormData();
|
|
|
+ formData.append("data_file", file);
|
|
|
+ $.ajax({
|
|
|
+ cache: true,
|
|
|
+ type: "POST",
|
|
|
+ url: "/datas/dataSendProvince/plainTextImport",
|
|
|
+ data: formData,
|
|
|
+ async: false,
|
|
|
+ contentType: false,
|
|
|
+ processData: false,
|
|
|
+ dataType: "json",
|
|
|
+ mimeType: "multipart/form-data",
|
|
|
+ error: function (request) {
|
|
|
+ parent.layer.alert("Connection error");
|
|
|
+ },
|
|
|
+ success: function (data) {
|
|
|
+ if (data.code == 0) {
|
|
|
+ console.log(data.toString())
|
|
|
+ if (data.msg != null && data.msg != '0') {
|
|
|
+ console.log("1; " + data.toString())
|
|
|
+ // parent.layer.msg("操作成功, " + data.msg + "条非本省数据!");
|
|
|
+ parent.layer.open({
|
|
|
+ title: '导入提示信息'
|
|
|
+ , content: "操作成功, " + data.msg,
|
|
|
+ btnAlign: 'c'
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ console.log("2: " + data.toString())
|
|
|
+ parent.layer.msg("操作成功");
|
|
|
+ }
|
|
|
+ parent.reLoad();
|
|
|
+ var index = parent.layer.getFrameIndex(window.name); // 获取窗口索引
|
|
|
+ parent.layer.close(index);
|
|
|
+
|
|
|
+ } else {
|
|
|
+ parent.layer.alert(data.msg)
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+function initUpload() {
|
|
|
+ let finalContent = '';
|
|
|
+ $("#kv-explorer").fileinput({
|
|
|
+ language: 'zh',//设置语言
|
|
|
+ theme: 'explorer-fas',
|
|
|
+ uploadUrl: "/datas/dataSendProvince/plainTextImport",//上传的地址
|
|
|
+ allowedFileExtensions: ["xls", "xlsx"],//接收的文件后缀
|
|
|
+ overwriteInitial: false,
|
|
|
+ initialPreviewAsData: true,
|
|
|
+ //dropZoneTitle: '可以将文件拖放到这里',
|
|
|
+ uploadAsync: true, //默认异步上传
|
|
|
+ showPreview: true,//是否显示预览
|
|
|
+ showUpload: true,//是否显示上传按钮
|
|
|
+ showRemove: true, //显示移除按钮
|
|
|
+ showCancel: false, //是否显示文件上传取消按钮。默认为true。只有在AJAX上传过程中,才会启用和显示
|
|
|
+ showCaption: true,//是否显示文件标题,默认为true
|
|
|
+ browseClass: "btn btn-primary", //文件选择器/浏览按钮的CSS类。默认为btn btn-primary
|
|
|
+ dropZoneEnabled: true,//是否显示拖拽区域
|
|
|
+ maxFileSize: 0,//最大上传文件数限制,单位为kb,如果为0表示不限制文件大小
|
|
|
+ minFileCount: 1, //每次上传允许的最少文件数。如果设置为0,则表示文件数是可选的。默认为0
|
|
|
+ maxFileCount: 15, //每次上传允许的最大文件数。如果设置为0,则表示允许的文件数是无限制的。默认为0
|
|
|
+ previewFileIcon: "<i class='glyphicon glyphicon-king'></i>",//当检测到用于预览的不可读文件类型时,将在每个预览文件缩略图中显示的图标。默认为<i class="glyphicon glyphicon-file"></i>
|
|
|
+ layoutTemplates: {
|
|
|
+ //footer:'',//隐藏全部小图标;
|
|
|
+ actionUpload: '',//去除上传预览缩略图中的上传图片;
|
|
|
+ indicator: '', //去除上传状态图标(左侧➕)
|
|
|
+ //actionDrag:'',//去除拖动图标(通常编辑的时候会显示这个图标)
|
|
|
+ actionZoom: '',
|
|
|
+ //actionDelete:'',//去除删除图标
|
|
|
+ //其他 参考fileinput.js/fileinput.min.js中 搜索 layoutTemplates,可以看到模板内所有元素 需要改哪个,直接在这里赋空字符串就行了
|
|
|
+ },
|
|
|
+ previewFileIconSettings: {
|
|
|
+ 'docx': '<i ass="fa fa-file-word-o text-primary"></i>',
|
|
|
+ 'xlsx': '<i class="fa fa-file-excel-o text-success"></i>',
|
|
|
+ 'xls': '<i class="fa fa-file-excel-o text-success"></i>',
|
|
|
+ 'pptx': '<i class="fa fa-file-powerpoint-o text-danger"></i>',
|
|
|
+ 'jpg': '<i class="fa fa-file-photo-o text-warning"></i>',
|
|
|
+ 'pdf': '<i class="fa fa-file-archive-o text-muted"></i>',
|
|
|
+ 'zip': '<i class="fa fa-file-archive-o text-muted"></i>',
|
|
|
+ },
|
|
|
+ msgFilesTooMany: "选择上传的文件数量({n}) 超过允许的最大数值{m}!",//字符串,当文件数超过设置的最大计数时显示的消息 maxFileCount。默认为:选择上传的文件数({n})超出了允许的最大限制{m}。请重试您的上传!
|
|
|
+ elErrorContainer: '#kartik-file-errors'
|
|
|
+ }).on("fileuploaded", function (event, data, previewId, index) {//异步上传成功结果处理
|
|
|
+ console.log("fileuploaded");
|
|
|
+ console.log("event" + event);
|
|
|
+ console.log("data" + data);
|
|
|
+ console.log("previewId" + previewId);
|
|
|
+ console.log("index" + index);
|
|
|
+ console.log("resp" + data.response);
|
|
|
+ //处理结果
|
|
|
+ if (data.response.code == 0) {
|
|
|
+ // 全部成功并且没有条数提示
|
|
|
+ // if (index == data.files.length && finalContent == '') {
|
|
|
+ console.log("2: " + data.toString())
|
|
|
+ // parent.layer.msg("操作成功");
|
|
|
+ // parent.reLoad();
|
|
|
+ // var index = parent.layer.getFrameIndex(window.name); // 获取窗口索引
|
|
|
+ // parent.layer.close(index);
|
|
|
+
|
|
|
+ parent.layer.open({
|
|
|
+ title: ['导入提示信息', 'text-align: center']
|
|
|
+ , icon: 7
|
|
|
+ , content: "操作成功 <br/>" + finalContent,
|
|
|
+ btnAlign: 'c'
|
|
|
+ });
|
|
|
+ parent.reLoad();
|
|
|
+ var index = parent.layer.getFrameIndex(window.name); // 获取窗口索引
|
|
|
+ parent.layer.close(index);
|
|
|
+ // }
|
|
|
+ // parent.layer.msg("操作成功");
|
|
|
+ } else {
|
|
|
+ parent.layer.alert(data.response.msg)
|
|
|
+ }
|
|
|
+ }).on('fileerror', function (event, data, msg) {//异步上传错误结果处理
|
|
|
+ console.log("fileerror");
|
|
|
+ console.log("event" + event);
|
|
|
+ console.log("data" + data);
|
|
|
+ console.log("msg" + msg);
|
|
|
+ });
|
|
|
+ /* $('#uploadfile').on('filebatchuploaderror', function(event, data, msg) {//同步上传错误结果处理
|
|
|
+ console.log("filebatchuploaderror");
|
|
|
+ console.log("event"+event);
|
|
|
+ console.log("data"+data);
|
|
|
+ console.log("msg"+msg);
|
|
|
+ });
|
|
|
+ $('#uploadfile').on('filebatchuploadsuccess', function(event, data, previewId, index) {//同步上传成功结果处理
|
|
|
+ console.log("filebatchuploadsuccess");
|
|
|
+ console.log("event"+event);
|
|
|
+ console.log("data"+data);
|
|
|
+ console.log("previewId"+previewId);
|
|
|
+ console.log("index"+index);
|
|
|
+ });
|
|
|
+ $('#uploadfile').on('filebatchuploadcomplete',function (event,files,extra) {
|
|
|
+ console.log("filebatchuploadcomplete");
|
|
|
+ });*/
|
|
|
+}
|
|
|
+
|
|
|
+//返回
|
|
|
+$("#go_back").click(function () {
|
|
|
+ var index = parent.layer.getFrameIndex(window.name); // 获取窗口索引
|
|
|
+ parent.layer.close(index);
|
|
|
+});
|