<%@ page language="java" pageEncoding="UTF-8" %>
|
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
|
<%
|
String path = request.getContextPath();
|
String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
|
+ path + "/";
|
%>
|
|
<!DOCTYPE HTML>
|
<html>
|
<head>
|
<base href="<%=basePath%>">
|
<meta name="viewport" charset="width=device-width, initial-scale=1.0">
|
<meta http-equiv="X-UA-Compatible" content="ie=edge">
|
<title>数据导入</title>
|
<!--[if !IE]><!-->
|
<link href="static/plugins/font-awesome/css/font-awesome.css" rel="stylesheet" type="text/css">
|
<!--<![endif]-->
|
<!--[if gt IE 8]>
|
<link href="static/plugins/font-awesome/css/font-awesome.css" rel="stylesheet" type="text/css">
|
<![endif]-->
|
<link href="static/plugins/jquery-easyui/themes/bootstrap/easyui.css" rel="stylesheet" type="text/css">
|
<link rel="stylesheet" href="static/styles/initialize.css" type="text/css">
|
<link rel="stylesheet" href="static/styles/common.css" type="text/css">
|
<link rel="stylesheet" href="static/plugins/layer/skin/default/layer.css" type="text/css">
|
<link rel="stylesheet" href="static/plugins/webuploader/webuploader.css" type="text/css">
|
|
<script type="text/javascript" src="static/plugins/jquery/jquery.min.js"></script>
|
<script type="text/javascript" src="static/plugins/jquery-easyui/jquery.easyui.min.js"></script>
|
<script type="text/javascript" src="static/plugins/jquery-easyui/locale/easyui-lang-zh_CN.js"></script>
|
<script type="text/javascript" src="static/scripts/easyuiExtend.js"></script>
|
<script type="text/javascript" src="static/scripts/jquery-extend.js"></script>
|
<script type="text/javascript" src="static/plugins/layer/layer.js"></script>
|
<script type="text/javascript" src="static/plugins/slimScroll/jquery.slimscroll.min.js"></script>
|
<script type="text/javascript" src="static/plugins/jquery-easyui-datagrid-dnd/datagrid-dnd.js"></script>
|
<script src="static/plugins/jquery.redirect.js" type="text/javascript"></script>
|
<script type="text/javascript" src="static/plugins/webuploader/webuploader.js"></script>
|
|
<!-- 弹窗加载组件 -->
|
<script type="text/javascript" src="static/plugins/layer/layer.js"></script>
|
<script type="text/javascript" src="static/plugins/spinjs/spin.js"></script>
|
<script type="text/javascript" src="static/plugins/spinjs/jquery.spin.js"></script>
|
<script type="text/javascript" src="static/plugins/jquery.blockUI.js"></script>
|
<!-- wcp组件 -->
|
<script type="text/javascript" src="static/wcp/scripts/wcp.js"></script>
|
<script type="text/javascript" src="static/wcp/scripts/libs/wcp.layer.js"></script>
|
<script type="text/javascript" src="static/wcp/scripts/libs/wcp.blockUI.js"></script>
|
<script type="text/javascript" src="static/wcp/scripts/libs/wcp.spin.js"></script>
|
<script type="text/javascript" src="static/wcp/scripts/libs/wcp.jquery.js"></script>
|
|
<!--[if lt IE 9]>
|
<script type="text/javascript" src="static/plugins/json2.js"></script>
|
<![endif]-->
|
<script type="text/javascript" src="static/wcp/scripts/libs/wcp.infoPicker.js"></script>
|
<style>
|
.combobox-group {
|
clear: both;
|
}
|
|
.combobox-gitem {
|
float: left;
|
padding-right: 10px;
|
}
|
|
.progress {
|
border: 1px solid #1483d8;
|
width: 100%;
|
background: #fff;
|
height: 18px;
|
/*line-height: 20px;*/
|
display: inline-block;
|
text-align: center;
|
color: #6dbfff;
|
position: absolute;
|
margin-right: 10px;
|
top: 290px;
|
}
|
|
.progress span.percentage {
|
width: 0;
|
height: 100%;
|
left: 0;
|
top: 0;
|
background: #1483d8;
|
position: absolute;
|
}
|
|
.progress span.text {
|
position: relative;
|
z-index: 10;
|
}
|
</style>
|
|
</head>
|
<body>
|
<div class="margin-lr">
|
<div class="pt-main-top clear">
|
<div class="pt-nav">
|
<span class="pt-title-icon"> <i class="fa fa-upload"></i>
|
</span>
|
<div class="pt-title">
|
<div>
|
<h4>数据导入信息</h4>
|
</div>
|
</div>
|
</div>
|
</div>
|
<div class="pt-form">
|
<form id="formImportTemplate">
|
<div class="ptbody">
|
<table style="width: 100%;">
|
<tr>
|
<td class="tbtitle">选择模板:</td>
|
<td>
|
<div>
|
<select name="importTemplate" id="importTemplate" style="width: 200px"
|
class="easyui-combobox"
|
data-options="required:true,editable:false,panelHeight:'auto'"></select>
|
<a id="download_but" class="pt-btn pt-btn-primary">下载</a>
|
</div>
|
</td>
|
</tr>
|
<tr>
|
<td class="tbtitle">数据开始行:</td>
|
<td>
|
<div>
|
<input id="startRowNum" class="easyui-numberspinner" style="width:200px"
|
required="required" data-options="min:2,editable:true"><br/>
|
<font color="red">(注:系统默认会根据选择的模板计算开始行,请确保数据开始行的前一行为字段。)</font>
|
</div>
|
</td>
|
</tr>
|
<tr>
|
<td class="tbtitle">文件:</td>
|
<td>
|
<div>
|
<div id="picker">选择文件</div>
|
<font color="red">(注:上传的zip文件中,根目录只解析excel文件和名称为‘附件’的文件夹。其中excel文件有且只能有一个,‘附件’的文件夹可以为空。)</font>
|
<div style="margin-top:10px;">
|
<span id="fileName"></span>
|
</div>
|
</div>
|
</td>
|
</tr>
|
|
<tr name="mountFileElement">
|
<td class="tbtitle">文件关联规则:</td>
|
<td>
|
<label id="regularType"></label>
|
|
<div style="color: red">(注:1、* 表示模糊匹配;2、附件文件夹里的层级可以为:文件夹/文件.pdf 或 文件.pdf )</div>
|
|
<%-- <input class="easyui-textbox" style="float:left;height: 30px;width:300px;" id="regularType" data-options="editable:false,panelHeight:'auto'" />--%>
|
</td>
|
</tr>
|
<tr id="error_Css" style="display:none;">
|
<td class="tbtitle">错误数据:</td>
|
<td>
|
<div>
|
<a class="pt-btn pt-btn-primary" onclick="downloadErrorExcle()">下载查看错误数据</a>
|
</div>
|
</td>
|
</tr>
|
<tr>
|
<td class="tbtitle"> </td>
|
<td>
|
<div>
|
<a id="importLogBtn" style="display: none" class="pt-btn pt-btn-primary"
|
onclick="showImportLog()">查看导入日志</a>
|
</div>
|
</td>
|
</tr>
|
</table>
|
<div class="progress" style="display: none;">
|
<span class="text">0%</span>
|
<span class="percentage"></span>
|
</div>
|
</div>
|
<div class="pt-form-btn">
|
<div class="form-group">
|
<a onclick="showImportAllLog()" class="pt-btn pt-btn-primary">查看导入日志</a>
|
<a id="btnSave" class="pt-btn pt-btn-primary">导入</a>
|
<a id="btnClose" class="pt-btn pt-btn-default">关闭</a>
|
</div>
|
</div>
|
</form>
|
</div>
|
</div>
|
</body>
|
<script type="text/javascript" src="static/scripts/ResizeScroll.js"></script>
|
<script>
|
//窗口参数,用于弹窗传递
|
var params = {
|
callBack: null
|
};
|
var fileName;
|
var uploader;
|
var importTemplateId;
|
var falg = false;
|
var relationKeyId = '${relationKeyId}';
|
var _extensions = "xlsx,xls";
|
var _mimeTypes = ".xlsx,.xls";
|
var _mountFileFlag = false;
|
var _importLogId;
|
$(function () {
|
initImportTemplate();
|
new ResizeScroll({
|
"id": ".ptbody",
|
fun: function () {
|
var wh = $(window).height();
|
$("body").height(wh);
|
return (wh - 69 - 62);
|
}
|
});
|
|
$("#download_but").click(function () {
|
var isValid = $('#formImportTemplate').form('validate');
|
if (!isValid) {
|
wcp.notify.warn('请选择需要下载的模板!');
|
return false;
|
}
|
importTemplateId = $("#importTemplate").combobox("getValue");
|
var url = "general/downloadExcel?importTemplateId=" + importTemplateId;
|
//window.open(url);
|
//alert('dd');
|
// $.redirect(url, {}, "POST", "_blank");
|
//创建form
|
var form = document.getElementById('#downLoadForm');
|
if (form == null) {
|
form = $("<form>");
|
form.attr("id", "downLoadForm");
|
form.attr("style", "display:none");
|
form.attr("target", "");
|
form.attr("method", "post");
|
$("body").append(form);
|
}
|
form.attr("action", url);
|
form.submit();
|
});
|
|
$("#btnSave").click(function () {
|
var isValid = $('#formImportTemplate').form('validate');
|
if (!isValid) {
|
wcp.notify.warn('请选择模板!');
|
return false;
|
}
|
if (!falg) {
|
wcp.notify.warn('请选择文件!');
|
return false;
|
}
|
var obj = $('#formImportTemplate').serializeObject();//new Object();
|
obj.importTemplateId = importTemplateId;
|
obj.viewId = "${viewId}";
|
obj.relationKeyId = relationKeyId;
|
obj.startRowNum = $('#startRowNum').textbox("getValue");
|
//console.info(obj);
|
uploader.options.formData = obj;
|
uploader.upload();
|
});
|
|
$("#btnClose").click(function () {
|
closeWindow();
|
});
|
uploadFile();
|
});
|
|
function initImportTemplate() {
|
$("#importTemplate").empty();
|
var moduleId = "${moduleId}";
|
var data = [];
|
wcp.ui.setBusy("body", wcp.ajax({
|
url: "config/importTemplate/selectImportTemplateList?&moduleId=" + moduleId + "&scene=1",
|
}).done(function (result) {
|
$("tr[name='mountFileElement']").hide();
|
for (var i = 0; i < result.length; i++) {
|
if (i == 0) {
|
data.push({
|
"id": result[i].importTemplateId,
|
"text": result[i].importTemplateName,
|
"mountFile": result[i].mountFile,
|
"ruleCode": result[i].ruleCode,
|
"ruleName": result[i].ruleName,
|
"startRowNum": result[i].startRowNum,
|
"selected": true
|
});
|
} else {
|
data.push({
|
"id": result[i].importTemplateId,
|
"text": result[i].importTemplateName,
|
"mountFile": result[i].mountFile,
|
"ruleCode": result[i].ruleCode,
|
"ruleName": result[i].ruleName,
|
"startRowNum": result[i].startRowNum
|
});
|
}
|
|
}
|
//下拉框设置点击事件
|
$("#importTemplate").combobox({
|
data: data,
|
valueField: 'id',
|
textField: 'text',
|
mountFile: 'mountFile',
|
ruleCode: 'ruleCode',
|
ruleName: 'ruleName',
|
// onChange: function(newV,oldV){
|
// alert(this.mountFile);
|
// },
|
onSelect: function (rec) {
|
// $("#regularType").empty();
|
$('#regularType').html("");
|
$('#startRowNum').textbox("setValue", rec.startRowNum);
|
if (rec.mountFile == 1) {
|
_mountFileFlag = true;
|
$("tr[name='mountFileElement']").show();
|
// $("#mountFileElementZdy").hide();
|
_extensions = "ZIP压缩文件";
|
_mimeTypes = ".zip";
|
|
//从模块表里取
|
$('#regularType').html(rec.ruleName);
|
|
/*
|
//从字表里取 多规则扩展
|
var _jsonObj = {};
|
_jsonObj.ruleType = 1;
|
wcp.ui.setBusy("body", wcp.ajax({
|
url: 'config/importTemplate/ruleConfigList?importTemplateId='+rec.id,
|
data: JSON.stringify(_jsonObj)
|
}).done(function (result2) {
|
var _data = [];
|
for (var i = 0; i < result2.length; i++) {
|
_data.push({
|
"ruleId": result2[i].ruleId,
|
"ruleName":result2[i].ruleName,
|
"selected": i==0?true:false
|
});
|
}
|
$("#regularType").combobox({
|
data: _data,
|
valueField: 'ruleId',
|
textField: 'ruleName',
|
onSelect: function(rec2){
|
if(rec2.ruleId == 0){
|
$("#mountFileElementZdy").show();
|
}
|
else{
|
$("#mountFileElementZdy").hide();
|
}
|
}
|
});
|
})
|
|
|
|
);*/
|
|
|
} else {
|
_mountFileFlag = false;
|
$("tr[name='mountFileElement']").hide();
|
_extensions = "xlsx,xls";
|
_mimeTypes = ".xlsx,.xls";
|
}
|
}
|
});
|
}));
|
}
|
|
function uploadBtn() {
|
var file = $("#file").val();
|
if (file == '') {
|
layer.alert("请选择excel,再上传");
|
} else if (file.lastIndexOf(".xls") < 0 || file.lastIndexOf(".xlsx") < 0) { //可判断以.xls和.xlsx结尾的excel
|
layer.alert("只能上传Excel文件");
|
} else {
|
var formData = new FormData($('form')[0]);
|
var importTemplateId = $("#importTemplate").combobox("getValue");
|
var url = "general/importExcel?importTemplateId=" + importTemplateId;
|
wcp.ui.setBusy("body", wcp.ajax({
|
url: url,
|
type: 'POST',
|
async: false,
|
dataType: "text",
|
data: formData,
|
// 告诉jQuery不要去处理发送的数据,用于对data参数进行序列化处理 这里必须false
|
processData: false,
|
// 告诉jQuery不要去设置Content-Type请求头
|
contentType: false, //必须
|
beforeSend: function () {
|
layer.alert("正在进行,请稍候");
|
},
|
success: function (data) {
|
var obj = JSON.parse(data);
|
// var errorCount = obj.error;
|
// wcp.notify.warn('导入完成!');
|
//
|
// importSuccess(obj.success, errorCount);
|
// if (errorCount > 0) {
|
// fileName = obj.fileName;
|
// $("#error_Css").show();
|
// }
|
// //判断是否需要执行回调函数
|
// if (params.callBack) {
|
// params.callBack();
|
// }
|
}
|
}));
|
}
|
}
|
|
function downloadErrorExcle() {
|
// var url = "general/downloadErrorExcel";
|
// var form = document.getElementById('#downloadErrorForm');
|
// $.redirect(url, {
|
// "fileName": fileName
|
// }, "POST", "_blank");
|
//创建form
|
var url = "general/downloadErrorExcel";
|
var form = document.getElementById('#downLoadForm');
|
if (form == null) {
|
form = $("<form>");
|
form.attr("id", "downLoadForm");
|
form.attr("style", "display:none");
|
form.attr("target", "");
|
form.attr("method", "post");
|
$("body").append(form);
|
}
|
form.attr("action", url);
|
//附件物理名称
|
var inputPhysicalName = document.getElementById('#iptphysicalName');
|
if (inputPhysicalName == null) {
|
inputPhysicalName = $("<input>");
|
inputPhysicalName.attr("id", "iptphysicalName");
|
form.append(inputPhysicalName);
|
}
|
//inputPhysicalName.attr("type", "hidden");
|
inputPhysicalName.attr("name", "fileName");
|
inputPhysicalName.val(fileName);
|
form.submit();
|
}
|
|
function showImportLog() {
|
if (_importLogId == null || _importLogId == '') {
|
wcp.notify.warn('当前没有导入日志!');
|
return;
|
}
|
var url = "management/log/index?parentTable=cnf_import_log&parentKey=" + _importLogId;
|
|
top.layer.open({
|
title: "导入日志",
|
type: 2,
|
area: ["1200px", "600px"],
|
fixed: false,
|
content: url,
|
success: function (layero, index) {
|
var body = window.top.layer.getChildFrame('body', index);
|
var iframeWin = window.top[layero.find('iframe')[0]['name']]; //得到iframe页的窗口对象
|
|
//将回调函数传给子页面
|
iframeWin.params.callBack = refreshData;
|
}
|
});
|
}
|
|
function showImportAllLog() {
|
|
var url = "general/importLogView?moduleId=${moduleId}&viewId=${viewId}";
|
|
top.layer.open({
|
title: "导入日志",
|
type: 2,
|
area: ["1200px", "600px"],
|
fixed: false,
|
content: url,
|
success: function (layero, index) {
|
var body = window.top.layer.getChildFrame('body', index);
|
var iframeWin = window.top[layero.find('iframe')[0]['name']]; //得到iframe页的窗口对象
|
|
//将回调函数传给子页面
|
iframeWin.params.callBack = refreshData;
|
}
|
});
|
}
|
|
|
function closeWindow() {
|
var index = top.layer.getFrameIndex(window.name); //获取窗口索引
|
top.layer.close(index);
|
}
|
|
function uploadFile() {
|
//var imgFileExtensions = 'xlsx,xls';
|
uploader = WebUploader.create({
|
swf: 'static/plugins/webuploader/Uploader.swf',
|
server: 'general/importExcel',
|
timeout: 0,
|
pick: {
|
id: "#picker",
|
multiple: false
|
},
|
accept: {
|
title: '选择文件',
|
extensions: "xlsx,xls,zip",
|
mimeTypes: '.xlsx,.xls,.zip'
|
},
|
auto: false,
|
duplicate: true
|
});
|
uploader.on("uploadSuccess", function (file, response) { //上传成功事件
|
//console.info(response);
|
var obj = response;
|
if (obj.success != undefined) {
|
//ie8无需转换
|
} else {
|
obj = eval('(' + response + ')');
|
}
|
if (_mountFileFlag) {
|
//系统校验拦截时返回错误信息
|
if (obj.error != undefined && obj.error.message != undefined) {
|
layer.alert(obj.error.message);
|
} else {
|
layer.alert(
|
"<strong>数据导入:</strong></br>"
|
+ " 成功:" + obj.success + "条 失败:" + obj.error + "条</br>"
|
+ "<strong>文件关联:</strong></br>"
|
+ " 成功:" + (obj.successFile ? obj.successFile : '-') + "条 失败:" + (obj.errorFile ? obj.errorFile : '-') + "条"
|
);
|
if (obj.error > 0 || obj.errorFile > 0) {
|
fileName = obj.fileName;
|
$("#error_Css").show();
|
}
|
}
|
|
} else {
|
layer.alert("数据导入成功:" + obj.success + "条! 失败:" + obj.error + "条!");
|
}
|
wcp.ui.clearBusy("body");
|
$(".progress").hide();
|
if (obj.error > 0) {
|
fileName = obj.fileName;
|
$("#error_Css").show();
|
}
|
//不需要显示此次导入日志,注释
|
/*if(obj.importLogId != undefined){
|
_importLogId = obj.importLogId;
|
$("#importLogBtn").show();
|
}else{
|
$("#importLogBtn").hide();
|
}*/
|
falg = false;
|
$("#fileName").html("");
|
//判断是否需要执行回调函数
|
if (params.callBack) {
|
params.callBack();
|
}
|
|
});
|
uploader.on("uploadError", function (file, reason) { //上传失败
|
wcp.message.error("上传失败:" + reason, "错误");
|
wcp.ui.clearBusy("body");
|
$(".progress").hide();
|
falg = false;
|
$("#fileName").html("");
|
});
|
uploader.on("beforeFileQueued", function (file) {
|
var ext = file.ext;
|
if (_mimeTypes.indexOf(ext.toLowerCase()) == -1) {
|
wcp.message.error("请选择" + _mimeTypes + "文件!", "错误");
|
return false;
|
}
|
var _regularTypeV = $("#regularType").html()
|
if (_mountFileFlag && _regularTypeV == '') {
|
wcp.message.error("当前模板未配置规则!", "错误");
|
return false;
|
}
|
});
|
uploader.on("fileQueued", function (file) {
|
falg = true;
|
$("#fileName").html(file.name);
|
importTemplateId = $("#importTemplate").combobox("getValue");
|
});
|
uploader.on("uploadProgress", function (file, percentage) {
|
var per = Math.trunc(percentage * 100);
|
if (per != 100) {
|
$(".progress .text").text(per + "%");
|
} else {
|
$(".progress .text").text("上传完成,正在处理数据...");
|
}
|
|
$(".progress .percentage").css('width', per + '%');
|
});
|
// 开始上传时添加显示
|
uploader.on('startUpload', function () {
|
$(".progress").show();
|
wcp.ui.setBusy("body");
|
});
|
}
|
</script>
|
</html>
|