diff --git a/src/main/resources/static/js/basic/lineManagement/child/importTower.js b/src/main/resources/static/js/basic/lineManagement/child/importTower.js index 8141774..a9917db 100644 --- a/src/main/resources/static/js/basic/lineManagement/child/importTower.js +++ b/src/main/resources/static/js/basic/lineManagement/child/importTower.js @@ -1,6 +1,8 @@ let form, layer, util,laydate, idParam, phoneParam,proId; let arr = ['background', 'web', 'mobile', 'wx']; let background, web, mobile, wx; +let selectedFile = null; // 用于存储选中的文件 + function setParams(params) { console.log(params) idParam = JSON.parse(params).id; @@ -41,105 +43,115 @@ function setParams(params) { layer.msg('开始下载2000国家大地坐标系模板'); // 实际项目中替换为真实的下载链接 window.location.href = ctxPath +'/download/download?filename=杆塔管理-2000国家大地坐标系导入模版.xlsx'; - }); - - let WG = { - uploadType: '1', - proId:proId - } - console.log("WG",WG) - let paramsWG = { - encryptedData: encryptCBC(JSON.stringify(WG)) - } - - let WG2 = { - uploadType: '2', - proId:proId - } - console.log("WG2",WG2) - let paramsWG2 = { - encryptedData: encryptCBC(JSON.stringify(WG2)) - } + }) // WGS-84坐标系文件上传 upload.render({ elem: '#uploadFileWGS84', - url: ctxPath + '/tbTower/tbTowerImport', // 上传接口 - headers: { - "token": tokens - }, + auto: false, accept: 'file', exts: 'xls|xlsx', - size: 10240, // 限制文件大小10MB - data: paramsWG, - before: function(obj) { - layer.load(); // 上传loading - }, - done: function(res) { - layer.closeAll('loading'); - if (res.code == 0) { - layer.msg('WGS-84坐标系文件上传成功'); - } else { - layer.msg('上传失败'); - } - }, - error: function() { - layer.closeAll('loading'); - layer.msg('上传出错'); + size: 10240, + choose: function(obj) { + obj.preview(function(index, file, result) { + if(file.size > 10240 * 1024) { + layer.msg('文件大小不能超过10MB', {icon: 2}); + return; + } + selectedFile = { + file: file, + type: 'wgs84' + }; + // 显示文件名 + $('#wgs84FileName').text(file.name); + $('#wgs84FileBox').show(); + layer.msg('文件已选择: ' + file.name); + }); } }); // 2000国家大地坐标系文件上传 upload.render({ elem: '#uploadFile2000', - url: ctxPath + '/tbTower/tbTowerImport', // 上传接口 - headers: { - "token": tokens - }, + auto: false, accept: 'file', exts: 'xls|xlsx', - size: 10240, // 限制文件大小10MB - data: paramsWG2, - before: function(obj) { - layer.load(); // 上传loading - }, - done: function(res) { - layer.closeAll('loading'); - if (res.code == 0) { - layer.msg('2000国家大地坐标系文件上传成功'); - } else { - layer.msg('上传失败'); - } - }, - error: function() { - layer.closeAll('loading'); - layer.msg('上传出错'); + size: 10240, + choose: function(obj) { + obj.preview(function(index, file, result) { + if(file.size > 10240 * 1024) { + layer.msg('文件大小不能超过10MB', {icon: 2}); + return; + } + selectedFile = { + file: file, + type: '2000' + }; + // 显示文件名 + $('#2000FileName').text(file.name); + $('#2000FileBox').show(); + layer.msg('文件已选择: ' + file.name); + }); } }); - // 取消按钮 - document.getElementById('cancelBtn').addEventListener('click', function() { - layer.confirm('确定要取消操作吗?', { - btn: ['确定', '取消'] - }, function() { - // 确定取消 - layer.msg('已取消'); - // 实际项目中可能需要返回上一页或关闭弹窗 - // window.history.back(); - }); - }); - - // 保存按钮 + // 保存按钮点击事件 document.getElementById('saveBtn').addEventListener('click', function() { + if (!selectedFile) { + layer.msg('请先选择要上传的文件', {icon: 2}); + return; + } + // 获取选中的坐标系 - var selectedSystem = document.querySelector('.coordinate-option.active').getAttribute('data-system'); + let selectedSystem = document.querySelector('.coordinate-option.active').getAttribute('data-system'); + + // 验证文件类型与选择的坐标系是否匹配 + if (selectedSystem !== selectedFile.type) { + layer.msg('请选择与坐标系对应的文件', {icon: 2}); + return; + } - // 检查是否已上传文件 - // 实际项目中应该有更完善的验证 + let formData = new FormData(); + formData.append('file', selectedFile.file); + formData.append('params', JSON.stringify({ + uploadType: selectedSystem === 'wgs84' ? '1' : '2', + proId: proId + })); - layer.msg('保存成功,选择的坐标系: ' + selectedSystem); - // 实际项目中这里应该提交表单或调用API + let loadingMsg = layer.msg('数据上传中,请稍候...', {icon: 16, time: 0}); + + // 发送上传请求 + $.ajax({ + url: ctxPath + '/tbTower/tbTowerImport', + type: 'POST', + data: formData, + processData: false, + contentType: false, + headers: { + "token": tokens + }, + success: function(res) { + layer.close(loadingMsg); + if (res.code === 200) { + layer.msg(res.data, {icon: 1}); + closePage(1); // 关闭页面并刷新父页面 + } else { + layer.msg(res.data || '上传失败', {icon: 2}); + } + }, + error: function() { + layer.close(loadingMsg); + layer.msg('上传出错', {icon: 2}); + } + }); }); }); } +function closePage(type) { + let index = parent.layer.getFrameIndex(window.name); + parent.layer.close(index); + if (type === 1) { + parent.reloadData() + } +} \ No newline at end of file diff --git a/src/main/resources/static/pages/basic/lineManagement/child/importTower.html b/src/main/resources/static/pages/basic/lineManagement/child/importTower.html index b28edf4..6dd0212 100644 --- a/src/main/resources/static/pages/basic/lineManagement/child/importTower.html +++ b/src/main/resources/static/pages/basic/lineManagement/child/importTower.html @@ -197,11 +197,13 @@