新增 hiprint 打印设计
This commit is contained in:
1 parent
aacf491051
commit
79c22c6348
27 files changed
+11515
-235
No files matched your search
@@ -12,7 +12,7 @@ using WalkingTec.Mvvm.Mvc;
|
||||
namespace HHWMS.Web.Controllers
|
||||
{
|
||||
[Area("configs")]
|
||||
[ActionDescription("打印管理")]
|
||||
[ActionDescription("打印设计")]
|
||||
public partial class PrintController : BaseController
|
||||
{
|
||||
private readonly IUnitWork _unitwork;
|
||||
@@ -27,62 +27,9 @@ namespace HHWMS.Web.Controllers
|
||||
[ActionDescription("Sys.Search")]
|
||||
public ActionResult Index()
|
||||
{
|
||||
var inv = _unitwork.Find<Inventory>(x => x.TaskStatus != InventoryTaskStatus.任务中)
|
||||
.ToList()
|
||||
.GroupBy(x => x.ContainerCode);
|
||||
var vm = Wtm.CreateVM<ContainerListVM>();
|
||||
return PartialView(vm);
|
||||
}
|
||||
#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, int num = 1)
|
||||
{
|
||||
var material = _unitwork.FindSingle<Material>(x => x.QRCode.Equals(code));
|
||||
if (material == null)
|
||||
{
|
||||
return JsonMore(null, 500, $"二维码{code}不存在!");
|
||||
}
|
||||
else
|
||||
{
|
||||
var materialQrList = new List<MaterialQr>();
|
||||
var printList = new List<dynamic>();
|
||||
for (int i = 0; i < num; i++)
|
||||
{
|
||||
var prefix = code.Split("@")[1].Substring(2);
|
||||
var uniqueCode = _unitwork.GetSerialNumber(prefix, length: 8);
|
||||
//var uniqueCode = prefix + unique;
|
||||
|
||||
materialQrList.Add(new MaterialQr
|
||||
{
|
||||
QRCode = code,
|
||||
UniqueCode = uniqueCode,
|
||||
CreateTime = DateTime.Now,
|
||||
CreateBy = Wtm.LoginUserInfo.ITCode
|
||||
});
|
||||
printList.Add(new
|
||||
{
|
||||
UniqueCode = uniqueCode,
|
||||
Batch = material.Batch
|
||||
});
|
||||
}
|
||||
_unitwork.BatchAdd(materialQrList.ToArray());
|
||||
return JsonMore(printList);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,174 +1,297 @@
|
||||
<el-row id="print">
|
||||
<el-row>
|
||||
<el-col :span="12">
|
||||
<el-input v-model="qrcode"
|
||||
placeholder="请扫描二维码"
|
||||
@@change="scanCode" ref="QrCode">
|
||||
</el-input>
|
||||
</el-col>
|
||||
<el-col :span="8">
|
||||
<el-input v-model.number="num"
|
||||
placeholder="请输入数量">
|
||||
</el-input>
|
||||
</el-col>
|
||||
<el-col :span="4">
|
||||
<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 style="float: right" type="primary" @@click="print">打印</el-button>
|
||||
</el-row>
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<link href="bootstrap-3.4.1-dist/css/bootstrap.min.css" rel="stylesheet">
|
||||
</head>
|
||||
<body>
|
||||
<layout class="layout hinnn-layout hinnn-layout-has-sider height-100-per" style="background:#fff;">
|
||||
|
||||
<script>
|
||||
var app = new Vue({
|
||||
el: "#print",
|
||||
data() {
|
||||
return {
|
||||
printData:[],
|
||||
gendCode: '',
|
||||
qrcode: '',
|
||||
num: 1,
|
||||
clear: false,
|
||||
template: {
|
||||
"panels": [
|
||||
{
|
||||
"index": 0,
|
||||
"height": 20,
|
||||
"width": 30,
|
||||
"paperHeader": 43.5,
|
||||
"paperFooter": 56.69,
|
||||
"printElements": [
|
||||
{
|
||||
"options": {
|
||||
"left": 0,
|
||||
"top": 2,
|
||||
"height": 52,
|
||||
"width": 81,
|
||||
"title": "",
|
||||
"field": "uniqueCode",
|
||||
"testData": "",
|
||||
"textType": "qrcode",
|
||||
"barcodeMode": "CODE39"
|
||||
},
|
||||
"printElementType": {
|
||||
"type": "text"
|
||||
}
|
||||
}
|
||||
],
|
||||
"paperNumberLeft": 55.5,
|
||||
"paperNumberTop": 34.5,
|
||||
"paperNumberDisabled": true
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
scanCode() {
|
||||
var _this = this;
|
||||
// 调用后台方法,判断是否在物料表内
|
||||
$.ajax({
|
||||
type: "post",
|
||||
dataType: "json",
|
||||
data: { code: _this.qrcode },
|
||||
url: "/configs/Print/ScanCode",
|
||||
success: function (json) {
|
||||
// console.log(json);
|
||||
if (json.Code != 200) {
|
||||
_this.$message({
|
||||
message: "扫描失败!" + json.Msg,
|
||||
type: "warning",
|
||||
duration: "10000",
|
||||
});
|
||||
}
|
||||
if (_this.clear) {
|
||||
_this.gendCode = "";
|
||||
_this.printData = [];
|
||||
}
|
||||
},
|
||||
error: function (json) {
|
||||
_this.$message({
|
||||
message: "扫描失败!",
|
||||
type: "error",
|
||||
duration: "10000",
|
||||
});
|
||||
},
|
||||
});
|
||||
},
|
||||
genCode() {
|
||||
var _this = this;
|
||||
if (_this.qrcode == "") {
|
||||
_this.$message({
|
||||
message: "请扫描二维码后再操作!",
|
||||
type: "warning",
|
||||
duration: "500",
|
||||
});
|
||||
return;
|
||||
}
|
||||
if (_this.num == "") {
|
||||
_this.$message({
|
||||
message: "请输入数量后再操作!",
|
||||
type: "warning",
|
||||
duration: "500",
|
||||
});
|
||||
return;
|
||||
}
|
||||
// 调用后台方法,生成唯一码,(流水号)
|
||||
$.ajax({
|
||||
type: "post",
|
||||
dataType: "json",
|
||||
data: { code: _this.qrcode, num: _this.num },
|
||||
url: "/configs/Print/GenCode",
|
||||
success: function (json) {
|
||||
if (json.Code != 200) {
|
||||
_this.$message({
|
||||
message: "生成失败!" + json.Msg,
|
||||
type: "warning",
|
||||
duration: "10000",
|
||||
});
|
||||
return;
|
||||
}
|
||||
else{
|
||||
// console.log(json);
|
||||
json.Data.forEach(function (item) {
|
||||
_this.gendCode += item.UniqueCode + '\n';
|
||||
_this.gendCode += item.Batch + '\n';
|
||||
_this.printData.push({ uniqueCode: item.UniqueCode });
|
||||
_this.printData.push({ uniqueCode: item.Batch });
|
||||
});
|
||||
|
||||
}
|
||||
},
|
||||
error: function (json) {
|
||||
_this.$message({
|
||||
message: "生成失败!",
|
||||
type: "error",
|
||||
duration: "10000",
|
||||
});
|
||||
},
|
||||
<content class="hinnn-layout-content" style="border-left:1px solid #e8e8e8;">
|
||||
<div class="container-fluid height-100-per print-content">
|
||||
|
||||
<div class="row">
|
||||
<div class="col-sm-10">
|
||||
<div class="row">
|
||||
<div class="col-sm-3 col-md-2" style="padding-right:0px;">
|
||||
|
||||
<div class="rect-printElement-types hiprintEpContainer">
|
||||
<ul class="hiprint-printElement-type">
|
||||
|
||||
<li>
|
||||
<span class="title"><code>拖拽列表</code></span>
|
||||
<ul>
|
||||
<li>
|
||||
<a class="ep-draggable-item" tid="testModule.text" style="">
|
||||
|
||||
<span class="glyphicon glyphicon-text-width" aria-hidden="true"></span>
|
||||
<span class="glyphicon-class">文本</span>
|
||||
</a>
|
||||
</li>
|
||||
|
||||
<li>
|
||||
<a class="ep-draggable-item" tid="testModule.image" style="">
|
||||
<span class="glyphicon glyphicon-picture" aria-hidden="true"></span>
|
||||
<span class="glyphicon-class">图片</span>
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a class="ep-draggable-item" tid="testModule.longText">
|
||||
<span class="glyphicon glyphicon-subscript" aria-hidden="true"></span>
|
||||
<span class="glyphicon-class">长文</span>
|
||||
|
||||
|
||||
</a>
|
||||
</li>
|
||||
|
||||
<li>
|
||||
<a class="ep-draggable-item" tid="testModule.tableCustom" style="">
|
||||
<span class="glyphicon glyphicon-th" aria-hidden="true"></span>
|
||||
<span class="glyphicon-class">表格</span>
|
||||
</a>
|
||||
</li>
|
||||
|
||||
<li>
|
||||
<a class="ep-draggable-item" tid="testModule.html">
|
||||
<span class="glyphicon glyphicon-header" aria-hidden="true"></span>
|
||||
<span class="glyphicon-class">html</span>
|
||||
</a>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
<li>
|
||||
<span class="title">辅助</span>
|
||||
<ul>
|
||||
<li>
|
||||
<a class="ep-draggable-item" tid="testModule.hline" style="">
|
||||
|
||||
<span class="glyphicon glyphicon-resize-horizontal" aria-hidden="true"></span>
|
||||
<span class="glyphicon-class">横线</span>
|
||||
</a>
|
||||
</li>
|
||||
|
||||
<li>
|
||||
<a class="ep-draggable-item" tid="testModule.vline" style="">
|
||||
<span class="glyphicon glyphicon-resize-vertical" aria-hidden="true"></span>
|
||||
<span class="glyphicon-class">竖线</span>
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a class="ep-draggable-item" tid="testModule.rect">
|
||||
<span class="glyphicon glyphicon-unchecked" aria-hidden="true"></span>
|
||||
<span class="glyphicon-class">矩形</span>
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a class="ep-draggable-item" tid="testModule.oval">
|
||||
<span class="glyphicon glyphicon-record" aria-hidden="true"></span>
|
||||
<span class="glyphicon-class">椭圆</span>
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<div class="col-sm-9 col-md-10">
|
||||
<div class="hiprint-toolbar" style="margin-top:15px;">
|
||||
<ul>
|
||||
<li><a class="hiprint-toolbar-item" onclick="setPaper('A3')">A3</a></li>
|
||||
<li><a class="hiprint-toolbar-item" onclick="setPaper('A4')">A4</a></li>
|
||||
<li><a class="hiprint-toolbar-item" onclick="setPaper('A5')">A5</a></li>
|
||||
<li><a class="hiprint-toolbar-item" onclick="setPaper('B3')">B3</a></li>
|
||||
<li><a class="hiprint-toolbar-item" onclick="setPaper('B4')">B4</a></li>
|
||||
<li><a class="hiprint-toolbar-item" onclick="setPaper('B5')">B5</a></li>
|
||||
|
||||
<li><a class="hiprint-toolbar-item"><input type="text" id="customWidth" style="width: 50px;height: 19px;border: 0px;" placeholder="宽/mm" /></a></li>
|
||||
<li><a class="hiprint-toolbar-item"><input type="text" id="customHeight" style="width: 50px;height: 19px;border: 0px;" placeholder="高/mm" /></a></li>
|
||||
|
||||
<li><a class="hiprint-toolbar-item" onclick="setPaper($('#customWidth').val(),$('#customHeight').val())">自定义</a></li>
|
||||
<li><a class="hiprint-toolbar-item" onclick="rotatePaper()">旋转</a></li>
|
||||
<li><a class="hiprint-toolbar-item" onclick="clearTemplate()">清空</a></li>
|
||||
|
||||
<li>
|
||||
<a class="btn hiprint-toolbar-item " style="color: #fff;
|
||||
background-color: #d9534f;
|
||||
border-color: #d43f3a;" id="A4_preview">快速预览</a>
|
||||
</li>
|
||||
<li>
|
||||
<a id="A4_directPrint" class="btn hiprint-toolbar-item " style="color: #fff;
|
||||
background-color: #d9534f;
|
||||
border-color: #d43f3a;">打印</a>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
<div style="clear:both;"></div>
|
||||
</div>
|
||||
<div id="hiprint-printTemplate" class="hiprint-printTemplate" style="margin-top:20px;">
|
||||
</div>
|
||||
<div style="padding-top:15px;">
|
||||
<button type="button" class="btn btn-primary" id="A4_getJson_toTextarea">生成json到textarea</button>
|
||||
<button type="button" class="btn btn-primary" id="A4_getJson_toDesign">生成打印设计 json to 模板</button>
|
||||
</div>
|
||||
<div class="hinnn-callout hinnn-callout-danger">
|
||||
<p><code>可视化</code>结果以Json的形式存在,用户可以<code>编辑Json</code>实现特殊化操作,如:数据<code>formatter</code>,<code>文本变色</code>,单元格<code>改变背景</code>等。具体请参考文档。</p>
|
||||
</div>
|
||||
<textarea class="form-control" rows="10" id="A4_textarea_json"></textarea>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-sm-2">
|
||||
<sider class="hinnn-layout-sider" style="">
|
||||
<div class="container height-100-per" style="width:250px;">
|
||||
<div class="row">
|
||||
<div class="col-sm-12">
|
||||
<div id="PrintElementOptionSetting" style="margin-top:10px;"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
</sider>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</content>
|
||||
|
||||
</layout>
|
||||
|
||||
|
||||
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
|
||||
<div class="modal-dialog modal-lg" role="document" style="width: 825px;">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
|
||||
<h4 class="modal-title" id="myModalLabel">打印预览</h4>
|
||||
</div>
|
||||
|
||||
<div class="modal-body">
|
||||
<button type="button" class="btn btn-danger" id="A4_printByHtml">打印</button>
|
||||
<div class="prevViewDiv"></div>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<!--[[ 测试专用 单独使用无需引入 -->
|
||||
<script src="custom_test/custom-etype-provider.js"></script>
|
||||
<script src="custom_test/custom-print-json.js"></script>
|
||||
<script src="custom_test/print-data.js"></script>
|
||||
<!--测试专用 单独使用无需引入 ]] -->
|
||||
<!--单独使用无需引入 -->
|
||||
|
||||
<script src="bootstrap-3.4.1-dist/js/bootstrap.min.js"></script>
|
||||
|
||||
<script>
|
||||
var hiprintTemplate;
|
||||
$(document).ready(function () {
|
||||
|
||||
//初始化打印插件
|
||||
hiprint.init({
|
||||
providers: [new customElementTypeProvider()]
|
||||
});
|
||||
|
||||
// hiprint.PrintElementTypeManager.build('.hiprintEpContainer', 'testModule');
|
||||
//设置左侧拖拽事件
|
||||
hiprint.PrintElementTypeManager.buildByHtml($('.ep-draggable-item'));
|
||||
|
||||
hiprintTemplate = new hiprint.PrintTemplate({
|
||||
template: customPrintJson,
|
||||
settingContainer: '#PrintElementOptionSetting',
|
||||
paginationContainer: '.hiprint-printPagination'
|
||||
});
|
||||
//打印设计
|
||||
hiprintTemplate.design('#hiprint-printTemplate');
|
||||
|
||||
$('#A4_preview').click(function () {
|
||||
$('#myModal .modal-body .prevViewDiv').html(hiprintTemplate.getHtml(printData))
|
||||
$('#myModal').modal('show')
|
||||
});
|
||||
$('#A4_directPrint').click(function () {
|
||||
hiprintTemplate.print(printData);
|
||||
});
|
||||
$('#A4_printByHtml').click(function () {
|
||||
hiprintTemplate.printByHtml($('#myModal .modal-body .prevViewDiv'));
|
||||
})
|
||||
$('#A4_getJson_toTextarea').click(function () {
|
||||
$('#A4_textarea_json').html(JSON.stringify(hiprintTemplate.getJson()))
|
||||
})
|
||||
$('#A4_getJson_toDesign').click(function () {
|
||||
hiprintTemplate = new hiprint.PrintTemplate({
|
||||
template: JSON.parse($('#A4_textarea_json').val()),
|
||||
settingContainer: '#PrintElementOptionSetting',
|
||||
paginationContainer: '.hiprint-printPagination'
|
||||
});
|
||||
_this.num = 1;
|
||||
},
|
||||
print() {
|
||||
var _this = this;
|
||||
// _this.gendCode = "";
|
||||
hiprint.init();
|
||||
var hiprintTemplate = new hiprint.PrintTemplate({
|
||||
template: this.template
|
||||
})
|
||||
hiprintTemplate.print(this.printData);
|
||||
// _this.printData = [];
|
||||
_this.clear = true;
|
||||
//清空
|
||||
_this.qrcode = '';
|
||||
_this.num = 1;
|
||||
}
|
||||
$('#hiprint-printTemplate').html('');
|
||||
hiprintTemplate.design('#hiprint-printTemplate');
|
||||
})
|
||||
});
|
||||
|
||||
//调整纸张
|
||||
var setPaper = function (paperTypeOrWidth, height) {
|
||||
hiprintTemplate.setPaper(paperTypeOrWidth, height);
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
//旋转
|
||||
var rotatePaper = function () {
|
||||
hiprintTemplate.rotatePaper();
|
||||
}
|
||||
var clearTemplate = function () {
|
||||
hiprintTemplate.clear();
|
||||
}
|
||||
|
||||
</script>
|
||||
|
||||
<script>
|
||||
$(document).ready(function () {
|
||||
//设置左侧拖拽事件
|
||||
var hiprintTemplate_bill = new hiprint.PrintTemplate({
|
||||
template: JSON.parse($('#textarea_bill').val()),
|
||||
settingContainer: '#PrintElementOptionSetting'
|
||||
});
|
||||
//打印设计
|
||||
hiprintTemplate_bill.design('#hiprint-printTemplate_bill');
|
||||
|
||||
$('#bill_preview').click(function () {
|
||||
$('#myModal .modal-body .prevViewDiv').html(hiprintTemplate_bill.getHtml(printData))
|
||||
$('#myModal').modal('show')
|
||||
});
|
||||
$('#bill_print').click(function () {
|
||||
hiprintTemplate_bill.print(printData);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
</script>
|
||||
|
||||
<script type="text/javascript">
|
||||
$(document).ready(function () {
|
||||
$('#barcode_button_preview').click(function () {
|
||||
var barCodehiprintTemplate = new hiprint.PrintTemplate({ template: JSON.parse($('#textarea_barcode').val()) });
|
||||
|
||||
var $html = barCodehiprintTemplate.getHtml([{ name: '黄山', barcode: '13234567' }, { name: '黄波', barcode: '1224567' }, { name: '黄磊', barcode: '1234567' }, { name: '黄磊', barcode: '1234567' }, { name: '古丽娜', barcode: '7654321' }])
|
||||
|
||||
$('#myModal .modal-body .prevViewDiv').html($html)
|
||||
$('#myModal').modal('show')
|
||||
});
|
||||
|
||||
$('#barcode_button_print').click(function () {
|
||||
var barCodehiprintTemplate = new hiprint.PrintTemplate({ template: JSON.parse($('#textarea_barcode').val()) });
|
||||
|
||||
var $html = barCodehiprintTemplate.getHtml([{ name: '黄山', barcode: '13234567' }, { name: '黄波', barcode: '1224567' }, { name: '黄磊', barcode: '1234567' }, { name: '黄磊', barcode: '1234567' }, { name: '古丽娜', barcode: '7654321' }])
|
||||
barCodehiprintTemplate.printByHtml($html);
|
||||
|
||||
});
|
||||
})
|
||||
</script>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
Reference in new issue
Block a user