文件上传基本完成

master
rdpnr_hemingxia 2025-04-11 18:31:58 +08:00
parent f81830743d
commit 3b7526f6bd
1 changed files with 54 additions and 20 deletions

View File

@ -4,18 +4,34 @@
<th:block th:include="include :: header('发货清单列表')" />
</head>
<body class="gray-bg">
<div class="col-sm-12 select-table table-striped" th:deliveryId="${deliveryId}">
<input id="uploadInput" type="hidden">
<div class="col-sm-12 select-table table-striped" >
<input id="uploadInput" type="file" accept=".xls,.xlsx" style="display: none">
<div class="col-sm-12 search-collapse" style="display: none" onchange="upLoadFile">
<form id="formId">
<div class="select-list">
<ul>
<li style="display: none">
<label>id</label>
<input th:value="${orderDelivery.id}" type="text" name="deliveryId">
</li>
</ul>
</div>
</form>
</div>
<div class="btn-group-sm" id="toolbar" role="group">
<a class="btn btn-success" onclick="downloadTem()" shiro:hasPermission="manage:delivery:add">
<i class="fa fa-download"></i> 下载模板
</a>
<a class="btn btn-primary" shiro:hasPermission="manage:delivery:edit" id="upload">
<a class="btn btn-primary" onclick="importList()" shiro:hasPermission="manage:delivery:edit" id="upload">
<i class="fa fa-upload"></i> 导入清单
</a>
</div>
<table id="bootstrap-table"></table>
<table id="bootstrap-table" th:deliveryId="${orderDelivery.id}"></table>
</div>
<th:block th:include="include :: footer" />
@ -30,7 +46,7 @@ url: prefix + "/list",
showToggle:false,
showPageGo:true,
params:{
deliveryId:''
deliveryId:$('#bootstrap-table').attr('deliveryid')
},
columns: [{
checkbox: false,
@ -74,22 +90,40 @@ $.table.init(options);
}
function importList(){
$('#uploadInput').click()
}
document.getElementById('uploadInput').addEventListener('change', function(event) {
const file = event.target.files[0];
let data=new FormData()
data.append('file',file)
data.append('deliveryId',$('#bootstrap-table').attr('deliveryid'))
var xhr = new XMLHttpRequest(); // 创建XMLHttpRequest对象
xhr.open('POST',prefix+'/importData', true); // 设置请求类型和URL
// 当请求完成时执行的回调函数
xhr.onload = function (res) {
let data=JSON.parse(res.currentTarget.response)
if (data.code === 0) {
$.modal.msgSuccess('上传成功');
} else {
$.modal.msgError(data.msg);
}
// layui.use('upload',function(){
// var upload = layui.upload;
// // 渲染
// upload.render({
// elem: '#uploadInput',
// url:prefix+'/importData', // 此处配置你自己的上传接口即可
// auto: true,
// // multiple: true,',
// done: function(res){
// layer.msg('上传成功');
// console.log(res)
// }
// });
// });
$('#uploadInput').val('')
$.table.refresh();
};
// 当请求发生错误时执行的回调函数
xhr.onerror = function () {
console.log('上传过程中发生错误');
};
//
// // 发送数据到服务器
xhr.send(data);
});
</script>
</body>