122 lines
3.2 KiB
HTML
122 lines
3.2 KiB
HTML
<!DOCTYPE html>
|
||
<html lang="en">
|
||
<head>
|
||
<meta charset="UTF-8">
|
||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||
<title>标签打印系统</title>
|
||
<script src="../x_admin/js/jq.js"></script>
|
||
<style>
|
||
body {
|
||
margin: 0;
|
||
padding: 20px;
|
||
font-family: Arial, sans-serif;
|
||
background-color: white;
|
||
text-align: center;
|
||
}
|
||
|
||
h1 {
|
||
font-size: 24px;
|
||
font-weight: bold;
|
||
margin-bottom: 10px;
|
||
}
|
||
|
||
.description {
|
||
font-size: 16px;
|
||
margin-bottom: 20px;
|
||
}
|
||
|
||
#barcodeContainer {
|
||
margin: 20px auto;
|
||
padding: 10px;
|
||
border: 2px dashed black;
|
||
display: inline-block;
|
||
}
|
||
|
||
#barcodeImage {
|
||
width: 600px;
|
||
height: 200px;
|
||
display: block;
|
||
margin: 0 auto;
|
||
/* border: 1px solid red; */
|
||
}
|
||
|
||
#printBtn {
|
||
display: block;
|
||
width: 200px;
|
||
margin: 20px auto;
|
||
padding: 10px;
|
||
background-color: #1E88E5;
|
||
color: white;
|
||
border: none;
|
||
border-radius: 4px;
|
||
font-size: 16px;
|
||
cursor: pointer;
|
||
}
|
||
|
||
@media print {
|
||
body * {
|
||
visibility: hidden;
|
||
}
|
||
#barcodeContainer, #barcodeContainer * {
|
||
visibility: visible;
|
||
}
|
||
#barcodeContainer {
|
||
position: absolute;
|
||
left: 0;
|
||
top: 0;
|
||
border: none;
|
||
}
|
||
}
|
||
</style>
|
||
</head>
|
||
<body>
|
||
<h1>标签打印系统</h1>
|
||
<div class="description">440×147px图片打印到60×20mm标签纸</div>
|
||
|
||
<div id="barcodeContainer">
|
||
<img id="barcodeImage" src="">
|
||
</div>
|
||
|
||
<button id="printBtn" onclick="dayin()">直接打印</button>
|
||
|
||
<script>
|
||
$(document).ready(function() {
|
||
loadBarcode();
|
||
|
||
// $('#printBtn').click(function() {
|
||
// window.print();
|
||
// });
|
||
});
|
||
|
||
function loadBarcode() {
|
||
console.log(Date.now)
|
||
$.ajax({
|
||
url: "/z/print_device_barcode",
|
||
type: "POST",
|
||
dataType: "json",
|
||
success: function(response) {
|
||
if(response.code == 10002) {
|
||
setTimeout(loadBarcode, 1000);
|
||
}
|
||
else if(response.code == 10003) {
|
||
alert(response.msg);
|
||
}
|
||
else if(response.data) {
|
||
$('#barcodeImage').attr('src', response.data.image);
|
||
// setTimeout(() => {
|
||
// dayin()
|
||
// }, 500);
|
||
}
|
||
},
|
||
error: function(xhr, status, error) {
|
||
console.error("请求出错:", error);
|
||
setTimeout(loadBarcode, 3000);
|
||
}
|
||
});
|
||
}
|
||
function dayin(){
|
||
window.print();
|
||
}
|
||
</script>
|
||
</body>
|
||
</html> |