feat(PrintConfig): 添加打印模板设计功能并优化相关视图
- 移除TestData字段的Required验证 - 将Template字段从textbox改为textarea以支持多行输入 - 添加打印模板设计界面,支持拖拽元素和自定义纸张 - 新增GetTemplateByName接口用于获取模板 - 优化视图布局,统一使用单列显示
This commit is contained in:
parent
48c63bb15d
commit
d89f6ffb3e
@ -7,6 +7,7 @@ using WalkingTec.Mvvm.Core.Extensions;
|
||||
using HHWMS.Web;
|
||||
using System.DirectoryServices.Protocols;
|
||||
using System.Web;
|
||||
using HHWMS.Web.Models;
|
||||
|
||||
namespace HHWMS.Web.Controllers
|
||||
{
|
||||
@ -236,5 +237,12 @@ namespace HHWMS.Web.Controllers
|
||||
var vm = Wtm.CreateVM<PrintConfigVM>(id);
|
||||
return PartialView(vm);
|
||||
}
|
||||
|
||||
[ActionDescription("Sys.Search")]
|
||||
public IActionResult GetTemplateByName(string name)
|
||||
{
|
||||
var template = _unitWork.FindSingle<PrintConfig>(x => x.Name == name).Template;
|
||||
return JsonMore(template);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -19,6 +19,24 @@
|
||||
<script>
|
||||
let template =
|
||||
{"panels":[{"index":0,"height":30,"width":60,"paperHeader":0,"paperFooter":85.03937007874016,"printElements":[{"options":{"left":10,"top":9,"height":55,"width":145,"title":"code","testData":"C0006","field":"code","fontSize":12,"textAlign":"center","lineHeight":12,"textType":"barcode"},"printElementType":{"type":"text"}}],"paperNumberLeft":140,"paperNumberTop":63,"paperNumberDisabled":true}]}
|
||||
|
||||
@*let template = ""
|
||||
$.ajax({
|
||||
type: "post",
|
||||
dataType: "json",
|
||||
url: "/configs/PrintConfig/GetTemplateByName/",
|
||||
data:{name:"container"},
|
||||
success: (json) => {
|
||||
if (json.Code == 200) {
|
||||
template = JSON.parse(json.Data.replace(/"/g, '"'))
|
||||
} else {
|
||||
layui.layer.msg(json.Msg || '获取模板失败');
|
||||
}
|
||||
},
|
||||
error: (xhr, status, error) => {
|
||||
layui.layer.msg('获取模板失败:' + error);
|
||||
}
|
||||
});*@
|
||||
|
||||
let printData = [];
|
||||
|
||||
|
||||
@ -2,13 +2,188 @@
|
||||
@inject IStringLocalizer<Program> Localizer;
|
||||
|
||||
<wt:form vm="@Model">
|
||||
<wt:row items-per-row="ItemsPerRowEnum.Two">
|
||||
<wt:row items-per-row="ItemsPerRowEnum.One">
|
||||
<wt:textbox field="Entity.Name" />
|
||||
<wt:textbox field="Entity.Template" />
|
||||
<wt:textbox field="Entity.TestData" />
|
||||
<wt:textarea field="Entity.Template" />
|
||||
</wt:row>
|
||||
<wt:row align="AlignEnum.Right">
|
||||
<wt:submitbutton />
|
||||
<wt:closebutton />
|
||||
</wt:row>
|
||||
</wt:form>
|
||||
|
||||
<link href="/hiprint/content/bootstrap.min.css" rel="stylesheet">
|
||||
<script src="/hiprint/custom/custom-etype-provider.js"></script>
|
||||
|
||||
<wt:row>
|
||||
<!-- 列表 -->
|
||||
<div class="layui-col-xs1 layui-col-md1" 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="layui-col-xs8 layui-col-md8">
|
||||
<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>
|
||||
</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>
|
||||
</div>
|
||||
<textarea class="layui-textarea" id="A4_textarea_json"></textarea>
|
||||
</div>
|
||||
|
||||
<!-- 属性 -->
|
||||
<div class="layui-col-xs3 layui-col-md3">
|
||||
<div id="PrintElementOptionSetting" style="margin-top:10px;"></div>
|
||||
</div>
|
||||
</wt:row>
|
||||
|
||||
<script>
|
||||
var hiprintTemplate;
|
||||
$(document).ready(function () {
|
||||
// 初始化默认值
|
||||
var customPrintJson = {};
|
||||
var templateValue = $('[name="Entity.Template"]').val();
|
||||
if (templateValue && templateValue !== '') {
|
||||
try {
|
||||
customPrintJson = JSON.parse(templateValue);
|
||||
} catch (e) {
|
||||
console.error("模板解析错误:", e);
|
||||
}
|
||||
}
|
||||
|
||||
var printData = {}
|
||||
|
||||
// 初始化打印插件
|
||||
hiprint.init({
|
||||
providers: [new customElementTypeProvider()]
|
||||
});
|
||||
|
||||
// 设置左侧拖拽事件
|
||||
hiprint.PrintElementTypeManager.buildByHtml($('.ep-draggable-item'));
|
||||
|
||||
hiprintTemplate = new hiprint.PrintTemplate({
|
||||
template: customPrintJson,
|
||||
settingContainer: '#PrintElementOptionSetting',
|
||||
paginationContainer: '.hiprint-printPagination'
|
||||
});
|
||||
|
||||
// 打印设计
|
||||
hiprintTemplate.design('#hiprint-printTemplate');
|
||||
|
||||
$('#A4_getJson_toTextarea').click(function () {
|
||||
$('#A4_textarea_json').html(JSON.stringify(hiprintTemplate.getJson()));
|
||||
$('[name="Entity.Template"]').val(JSON.stringify(hiprintTemplate.getJson()));
|
||||
})
|
||||
|
||||
});
|
||||
|
||||
// 调整纸张
|
||||
var setPaper = function (paperTypeOrWidth, height) {
|
||||
hiprintTemplate.setPaper(paperTypeOrWidth, height);
|
||||
}
|
||||
|
||||
// 旋转
|
||||
var rotatePaper = function () {
|
||||
hiprintTemplate.rotatePaper();
|
||||
}
|
||||
|
||||
// 清空模板
|
||||
var clearTemplate = function () {
|
||||
hiprintTemplate.clear();
|
||||
}
|
||||
</script>
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
@inject IStringLocalizer<Program> Localizer;
|
||||
|
||||
<wt:form vm="@Model">
|
||||
<wt:textbox field="Entity.Template" />
|
||||
<wt:textarea field="Entity.Template" />
|
||||
<wt:hidden field="Entity.ID" />
|
||||
<wt:row align="AlignEnum.Right">
|
||||
<wt:submitbutton submit-url="/configs/PrintConfig/Edit"/>
|
||||
|
||||
@ -2,9 +2,9 @@
|
||||
@inject IStringLocalizer<Program> Localizer;
|
||||
|
||||
<wt:form vm="@Model">
|
||||
<wt:row items-per-row="ItemsPerRowEnum.Two">
|
||||
<wt:row items-per-row="ItemsPerRowEnum.One">
|
||||
<wt:textbox field="Entity.Name" />
|
||||
<wt:textbox field="Entity.Template" />
|
||||
<wt:wt:textarea field="Entity.Template" />
|
||||
<wt:textbox field="Entity.TestData" />
|
||||
</wt:row>
|
||||
<wt:hidden field="Entity.ID" />
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
<wt:textbox field="Searcher.Name" />
|
||||
</wt:row>
|
||||
</wt:searchpanel>
|
||||
<wt:grid vm="@Model" url="/configs/PrintConfig/Search" height="400"/>
|
||||
<wt:grid vm="@Model" url="/configs/PrintConfig/Search" />
|
||||
|
||||
<script>
|
||||
|
||||
|
||||
@ -24,7 +24,6 @@ namespace HHWMS.Web.Models
|
||||
public string Template { get; set; }
|
||||
|
||||
[Display(Name = "PrintConfig.TestData", Description = "测试数据")]
|
||||
[Required(ErrorMessage = "Validate.{0}required")]
|
||||
public string TestData { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user