打印hiprint 打印测试

This commit is contained in:
zgf 2023-09-05 20:32:46 +08:00
parent 5c13b2a85c
commit 49078aaf0e
3 changed files with 159 additions and 76 deletions

View File

@ -30,6 +30,38 @@ namespace HHWMS.Web.Controllers
}
#endregion Search
[HttpPost]
public ActionResult ScanCode(string code)
{
var material = _unitwork.FindSingle<Material>(x => x.QRCode.Equals(code));
if (material == null)
{
return JsonMore(null, 500, $"二维码{code}不存在!");
}
else
{
return JsonMore(null);
}
}
[HttpPost]
public ActionResult GenCode(string code)
{
var material = _unitwork.FindSingle<Material>(x => x.QRCode.Equals(code));
if (material == null)
{
return JsonMore(null, 500, $"二维码{code}不存在!");
}
else
{
var prefix = code.Split("@")[1].Substring(2);
var unique = _unitwork.GetSerialNumber(prefix, 8);
var uniqueCode = prefix + unique;
material.UniqueCode = uniqueCode;
return JsonMore(uniqueCode);
}
}
}
}

View File

@ -1,86 +1,134 @@
<el-row id="print">
<el-input v-model="code"
placeholder="请扫描散料盒编码">
<el-row>
<el-col :span="16">
<el-input v-model="qrcode"
placeholder="请扫描二维码"
@@change="scanCode">
</el-input>
</el-col>
<el-col :span="8">
<el-button type="primary" @@click="genCode">生成</el-button>
</el-col>
</el-row>
<div style="margin: 20px 0;"></div>
@* 富文本 *@
<el-input type="textarea"
:autosize="{ minRows: 4}"
readonly
v-model="gendCode">
</el-input>
<el-button type="primary" @@click="print">打印</el-button>
<el-button style="float: right" type="primary" @@click="print">打印</el-button>
</el-row>
<script>
$(document).ready(function () {
let code1 = [{
qrcode: '18279822586'
}];
let template1 = {
"panels": [
{
"index": 0,
"name": 1,
"height": 25,
"width": 35,
"paperHeader": 49.5,
"paperFooter": 65.65656565656563,
"printElements": [
{
"options": {
"left": 12.5,
"top": 7.5,
"height": 55,
"width": 70,
"title": "文本",
"field": "qrcode",
"right": 79.99609375,
"bottom": 59.2421875,
"vCenter": 44.99609375,
"hCenter": 31.7421875,
"coordinateSync": false,
"widthHeightSync": false,
"textType": "qrcode",
"barcodeMode": "CODE39",
"qrCodeLevel": 0
},
"printElementType": {
"title": "这是更新后的元素",
"type": "text"
}
}
],
"paperNumberLeft": 69,
"paperNumberTop": 48,
"paperNumberDisabled": true,
"paperNumberContinue": true,
"watermarkOptions": {
"content": "vue-plugin-hiprint",
"rotate": 25,
"timestamp": true,
"format": "YYYY-MM-DD HH:mm"
}
}
]
}
let testhiprintTemplate = new hiprint.PrintTemplate({
template: template1
});
console.log(testhiprintTemplate);
let $html = testhiprintTemplate.getSimpleHtml(code1);
console.log($html);
});
var app = new Vue({
el: "#print",
data() {
return {
code: '123',
printData:[],
gendCode: '',
qrcode: '',
template: {
"panels": [
{
"index": 0,
"height": 20,
"width": 30,
"paperHeader": 43.5,
"paperFooter": 56.69,
"printElements": [
{
"options": {
"left": 15,
"top": 5,
"height": 44,
"width": 54,
"title": "",
"field": "uniqueCode",
"testData": "",
"textType": "qrcode",
"barcodeMode": "CODE39"
},
"printElementType": {
"type": "text"
}
}
],
"paperNumberLeft": 55.5,
"paperNumberTop": 34.5,
"paperNumberDisabled": true
}
]
}
}
},
mettods: {
print() {
// this.$print(undefined, template, "123123", {})
$html.jqprint({
debug: false, //如果是true则可以显示iframe查看效果(iframe默认高和宽都很小,可以再源码中调大),默认是false
importCSS: true, //true表示引进原来的页面的css,默认是true。(如果是true,先会找$("link[media=print]"),若没有会去找$("link")中的css文件)
printContainer: true, //表示如果原来选择的对象必须被纳入打印(注意:设置为false可能会打破你的CSS规则)。
operaSupport: false //表示如果插件也必须支持歌opera浏览器,在这种情况下,它提供了建立一个临时的打印选项卡。默认是true
methods: {
scanCode() {
var _this = this;
// 调用后台方法,判断是否在物料表内
$.ajax({
type: "post",
dataType: "json",
data: { code: _this.qrcode },
url: "/configs/Print/ScanCode",
success: function (json) {
if (json.Code != 200) {
_this.$message({
message: "扫描失败!" + json.Msg,
type: "warning",
duration: "10000",
});
}
},
error: function (json) {
_this.$message({
message: "扫描失败!",
type: "error",
duration: "10000",
});
},
});
},
genCode() {
var _this = this;
// 调用后台方法,生成唯一码,(流水号)
$.ajax({
type: "post",
dataType: "json",
data: { code: _this.qrcode },
url: "/configs/Print/GenCode",
success: function (json) {
if (json.Code != 200) {
_this.$message({
message: "生成失败!" + json.Msg,
type: "warning",
duration: "10000",
});
return;
}
else{
_this.gendCode += json.Data + '\n';
_this.printData.push({ uniqueCode: json.Data });
}
},
error: function (json) {
_this.$message({
message: "生成失败!",
type: "error",
duration: "10000",
});
},
});
//清空
this.qrcode = '';
},
print() {
hiprint.init();
var hiprintTemplate = new hiprint.PrintTemplate({
template: this.template
})
hiprintTemplate.print(this.printData);
}
}
})
});
</script>

View File

@ -20,8 +20,10 @@
<!-- import JavaScript -->
<script src="lib/element-ui/lib/index.js"></script>
<link rel="stylesheet" href="/hiprint/css/hiprint.css" />
<link rel="stylesheet" href="/hiprint/css/print-lock.css" />
<link rel="stylesheet" href="/hiprint/css/print-lock.css" media="print" />
</head>
<body>
@ -42,11 +44,12 @@
<script src="/echarts/wonderland.js"></script>
<script src="/_js/framework_layui.js?time=@DateTime.Now.Ticks"></script>
<script src="/hiprint/plugins/jquery.minicolors.min.js"></script>
<script src="/hiprint/plugins/qrcode.js"></script>
<script src="/hiprint/polyfill.min.js"></script>
<script src="/hiprint/hiprint.bundle.js"></script>
<script src="/hiprint/plugins/qrcode.js"></script>
<script src="/hiprint/plugins/jquery.minicolors.min.js"></script>
<script src="/hiprint/plugins/jquery.hiwprint.js"></script>
<script src="/hiprint/plugins/jquery.jqprint-0.3.js"></script>
<script src="/hiprint/plugins/jquery.jqprint-0.3.js"></script>
<script>
var DONOTUSE_IGNOREHASH = false;
var DONOTUSE_COOKIEPRE = '@ViewData["DONOTUSE_COOKIEPRE"]';