Files
43-VPSA-MES_Manage/webpage/SQLDemo2Excel.html
2026-06-08 17:14:28 +08:00

129 lines
5.2 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<meta charset="utf-8" />
<script src="../JS/jquery-3.2.1.min.js"></script>
<script type="text/javascript">
function btnTest() {
var param = '{"Type":"' + $("#TYPE").val() + '","UserID":"' + $("#USERID").val() + '","ModularID":"' + $("#MODULARID").val() + '","Name":"' + $("#NAME").val() + '","Param":"'+ $("#PARAM1value").val() + '"}'
console.log(param)
$.ajax({
url: $("#URL").val(),
type: 'POST',
contentType: "application/json; charset=utf-8",
dataType: 'json',
data: param,
success: function (data) {
$("#testResult").val(JSON.stringify(data));
},
error: function (data) {
$("#testResult").val('error');
}
});
}
// 导出
function downloadExcel() {
var param = '{"Type":"' + $("#TYPE").val() + '","UserID":"' + $("#USERID").val() + '","ModularID":"' + $("#MODULARID").val() + '","Name":"' + $("#NAME").val() + '","Param":"'+ $("#PARAM1value").val() + '"}'
const _ExcelDownLoad = '../submit/MESCommonBase.ashx'
download(`${_ExcelDownLoad}?param=${param}`)
};
// 导出Demo
function downloadExcelDemo() {
var param = '{"Type":"' + $("#TYPE").val() + '","UserID":"' + $("#USERID").val() + '","ModularID":"' + $("#MODULARID").val() + '","Name":"' + $("#NAME").val() + '","Param":"'+ $("#PARAM1value").val() + '"}'
const _ExcelDownLoad = '../submit/MESCommonBase.ashx'
download(`${_ExcelDownLoad}?param=${param}`)
};
function download(url) {
getBlob(url, function(blob, filename) {
saveAs(blob, filename)
})
};
function decodeUtf8(bytes) { var encoded = ""; for (var i = 0; i < bytes.length; i++) { encoded += '%' + bytes[i].toString(16); } return decodeURIComponent(encoded); }
function getBlob(url, cb) {
var xhr = new XMLHttpRequest()
xhr.open('GET', url, true)
xhr.responseType = 'blob'
xhr.onload = function () {
if (xhr.status === 200) {
const name = xhr.getResponseHeader('content-disposition').split('=')[1]
var filename1 = decodeURIComponent(name)
cb(xhr.response, filename1)
}
}
xhr.send();
};
function saveAs(blob, filename = '下载文件.xls') {
if (window.navigator.msSaveOrOpenBlob) {
navigator.msSaveBlob(blob, filename)
} else {
var link = document.createElement('a')
var body = document.querySelector('body')
link.href = window.URL.createObjectURL(blob)
link.download = filename
// fix Firefox
link.style.display = 'none'
body.appendChild(link)
link.click()
body.removeChild(link)
window.URL.revokeObjectURL(link.href)
}
};
</script>
<style>
.td{
width:400px;
}
input{
width:100%;
}
</style>
</head>
<body>
<table style="width:600px;">
<tr>
<td>URL:</td>
<td class=".td"><input id="URL" type="text" value="../submit/MESCommonBase.ashx" /></td>
</tr>
<tr>
<td>USERID:</td>
<td class=".td"><input id="USERID" type="text" />(日志用)</td>
</tr>
<tr>
<td>TYPE:</td>
<td class=".td"><input id="TYPE" type="text" />(2001导出Excel报表11 查询 12 增删改)</td>
</tr>
<tr>
<td>NAME:</td>
<td class=".td"><input id="NAME" type="text" value="_T00" />(存储过程名称)</td>
</tr>
<tr>
<td>PARAM: </td>
<td class=".td"><input id="PARAM1value" type="text" value="" />(存储过程参数)</td>
<h>PARAM示例[{\"name\":\"检测点代码\",\"value\":15},{\"name\":\"原材料_check\",\"value\":1},{\"name\":\"原材料代码\",\"value\":12}]</h>
</tr>
<tr>
<td>MODULARID: </td>
<td class=".td"><input id="MODULARID" type="text" />(主模块编号)</td>
</tr>
<tr>
<td>Pagination: </td>
<td class=".td"><input id="Pagination" type="text" />(分页的参数)</td>
</tr>
<tr>
<td><input type="button" onclick="btnTest()" value="testBtn" /></td>
<td><input type="button" onclick="downloadExcel()" value="导出Excel" /></td>
<!--<td><input type="button" onclick="downloadExcelDemo()" value="导出ExcelDemo" /></td>-->
</tr>
<tr style="height:400px;">
<td style="height:100%;" colspan="2">返回数据:<textarea id="testResult" style="width:100%;height:90%;" rows="30" cols="20"></textarea></td>
</tr>
</table>
</body>
</html>