You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

291 lines
8.9 KiB

3 years ago
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>打印</title>
3 years ago
<script language="javascript" src="/admin/jquery.js"></script>
<script language="javascript" src="/admin/jquery.qrcode.js"></script>
3 years ago
<script>
//二维码宽高
3 years ago
var qrcodewidth = 100;
var qrcodeheight = 100;
3 years ago
var qrcodeleft = 30;
var qrcodetop = 50;
//canvas宽高
3 years ago
var canvaswidth = 302;
var canvasheight = 188;
var VUE_APP_BASE_API = window.location.protocol+"//"+window.location.host
// var VUE_APP_BASE_API="http://hd-wuziguanli-test.ali251.langye.net"
3 years ago
//文字描述位置
var textleft = qrcodewidth / 2;
var texttop = qrcodeheight + 70;
$(function() {
console.log(VUE_APP_BASE_API)
3 years ago
$(".wrap").html("")
3 years ago
var ids = getIds('ids').split(",")
for (var i = 0; i < ids.length; i++) {
getListByid(i + 1, ids[i])
3 years ago
}
})
3 years ago
function getListByid(index, id) {
$.ajax({
type: "get",
timeout: 15000,
async: false,
contentType: 'application/json',
data: {
id: id,
table_name: 'inventorys'
},
url: VUE_APP_BASE_API+'/api/admin/base-form/show',
3 years ago
dataType: "json",
success: function(result) {
var printObj = result
$(".wrap").append("<li id='page" + index + "' style='width: 9cm; height: 5cm;'>" +
"<img src='' style='display: block;width:8cm; height:5cm;'>" +
"</li>")
createCode("#page" + index, printObj)
$(".load").remove()
},
complete: function(xhr, textStatus) {
}
});
}
3 years ago
// 生成二维码
function utf16to8(str) {
var out, i, len, c;
out = "";
len = str.length;
for (i = 0; i < len; i++) {
c = str.charCodeAt(i);
if ((c >= 0x0001) && (c <= 0x007F)) {
out += str.charAt(i);
} else if (c > 0x07FF) {
out += String.fromCharCode(0xE0 | ((c >> 12) & 0x0F));
out += String.fromCharCode(0x80 | ((c >> 6) & 0x3F));
out += String.fromCharCode(0x80 | ((c >> 0) & 0x3F));
} else {
out += String.fromCharCode(0xC0 | ((c >> 6) & 0x1F));
out += String.fromCharCode(0x80 | ((c >> 0) & 0x3F));
}
}
return out;
}
3 years ago
function createCode(id, printObji) {
// alert(id)
3 years ago
var qrcode = $(id).qrcode({
render: 'canvas',
text:VUE_APP_BASE_API+'/admin/printShow.html',
3 years ago
width: qrcodewidth,
height: qrcodeheight,
background: '#ffffff',
foreground: '#000000',
});
var canvas = qrcode.find('canvas').get(0);
3 years ago
var img = new Image();
3 years ago
var str = decodeURI(decodeURI(printObji['zichanmingcheng'])).replace(/\s+/g,'')
3 years ago
var wzlx = decodeURI(decodeURI(printObji['wuzileixing']))
var zcbm = decodeURI(decodeURI(printObji['wuzibianma']))
3 years ago
img.src = canvas.toDataURL('image/png');
img.onload = function() {
canvas.width = canvaswidth;
canvas.height = canvasheight;
var ctx = canvas.getContext('2d');
ctx.fillStyle = '#ffffff';
ctx.fillRect(0, 0, canvas.width, canvas.height);
//设置文字样式
ctx.fillStyle = '#000000';
3 years ago
ctx.font = 'bold ' + 18 + 'px Arial';
3 years ago
ctx.textAlign = 'left';
//文字描述
3 years ago
ctx.fillText("苏州河道管理处", 100, 30);
3 years ago
ctx.fillText("编码:" + zcbm, qrcodeleft + 110, 65);
if(str.length<=6){
ctx.fillText("类型:" + wzlx, qrcodeleft + 110, 95);
ctx.fillText("名称:"+str, qrcodeleft + 110, 125);
3 years ago
}else{
3 years ago
ctx.fillText("类型:" + wzlx, qrcodeleft + 110, 95);
ctx.fillText("名称:"+str.substring(0,6), qrcodeleft + 110, 125);
ctx.fillText(str.substring(6,str.length), qrcodeleft + 110, 155);
3 years ago
}
3 years ago
ctx.drawImage(img, qrcodeleft, qrcodetop);
var data = canvas.toDataURL('image/png', 1);
var imgOk = new Image();
imgOk.src = data;
$(id).children('img').attr('src', imgOk.src)
$(id).children('canvas').remove()
}
}
function doPrint(obj) {
if ($(obj).hasClass("disabled")) {
alert("已经打印过了,如要重新打印请刷新本页");
return false;
}
$(obj).addClass("disabled");
var myDoc = {
settings: {
topMargin: 0,
leftMargin: 0,
bottomMargin: 0,
rightMargin: 0
}, // 设置上下左距页边距为10毫米注意单位是 1/10毫米
documents: document,
marginIgnored: true,
copyrights: '杰创软件拥有版权 www.jatools.com'
};
3 years ago
document.getElementById("jatoolsPrinter").print(myDoc, false); // 直接打印,不弹出打印机设置对话框
3 years ago
// delCookie('objs')
3 years ago
}
function delCookie(name)
{
var exp = new Date();
exp.setTime(exp.getTime() - 1);
var cval = getCookie(name);
if (cval != null)
document.cookie = name + "=" + cval + ";expires=" + exp.toGMTString();
}
function getCookie(cookieName) {
//获取所有的cookie "psw=1234we; rememberme=true; user=Annie"
var totalCookie = document.cookie;
//获取参数所在的位置
var cookieStartAt = totalCookie.indexOf(cookieName + "=");
//判断参数是否存在 不存在直接返回
if (cookieStartAt == -1) {
return;
}
//获取参数值的开始位置
var valueStartAt = totalCookie.indexOf("=", cookieStartAt) + 1;
//以;来获取参数值的结束位置
var valueEndAt = totalCookie.indexOf(";", cookieStartAt);
//如果没有;则是最后一位
if (valueEndAt == -1) {
valueEndAt = totalCookie.length;
}
//截取参数值的字符串
var cookieValue = unescape(totalCookie.substring(valueStartAt, valueEndAt));
return cookieValue;
}
3 years ago
function getIds(name) {
var reg = new RegExp("(^|&)" + name.toLowerCase() + "=([^&]*)(&|$)");
var r = window.location.search.substr(1).toLowerCase().match(reg);
if (r != null) {
return unescape(r[2].replace(new RegExp(/(%25)/g), '%').replace(new RegExp(/(%25)/g), '%'));
}
return null
}
3 years ago
</script>
<style>
body {
font-family: "微软雅黑";
font-size: 12px;
padding: 0;
margin: 0;
background: #000;
}
3 years ago
.load{
color: #fff;
font-size: 20px;
}
3 years ago
ul,
li {
padding: 0;
margin: 0;
list-style: none;
}
.clear {
clear: both;
}
.bar {
position: fixed;
top: 0;
left: 0;
height: 60px;
background: #333;
color: #fff;
line-height: 20px;
width: 100%;
}
.bar A {
color: #fff;
text-decoration: underline;
}
.bar A:hover {
text-decoration: none;
color: #ccc;
}
.bar .wp {
width: 1000px;
margin: auto;
position: relative;
}
.bar .wp .left {
float: left;
}
.bar .wp .right {
float: right;
padding-top: 20px;
}
.lists {
padding-top: 80px;
padding-bottom: 20px;
}
.lists li {
// float: left;
margin-left: 20px;
margin-bottom: 10px;
}
</style>
</head>
<body>
3 years ago
<div class="lists">
<div class="load">加载中...</div>
3 years ago
<ul class="wrap">
<div class="clear"></div>
</ul>
</div>
<div class="bar">
<div class="wp">
<div class="left">生成打印单<br />
本打印功能只能在IE浏览器使用非IE浏览器请采用兼容模式<br />
3 years ago
使用之前需要安装插件(<a href="/admin/jatoolsPrinter_free.zip" target="_blank">点击下载</a>),并正确设置打印机
3 years ago
</div>
<div class="right">
<input type="button" value="打印" onClick='doPrint(this);'>
</div>
</div>
</div>
<OBJECT ID="jatoolsPrinter" CLASSID="CLSID:B43D3361-D075-4BE2-87FE-057188254255"
codebase="jatoolsPrinter.cab#version=8,6,0,0">
</OBJECT>
</body>
3 years ago
</html>