ol-base-components 3.0.0 → 3.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/App.vue +257 -7
- package/src/package/print/index.js +37 -15
- package/src/package/print/src/components/PaperSelector.vue +123 -0
- package/src/package/print/src/index.vue +117 -65
package/package.json
CHANGED
package/src/App.vue
CHANGED
|
@@ -502,12 +502,146 @@ export default {
|
|
|
502
502
|
}
|
|
503
503
|
},
|
|
504
504
|
aaa() {
|
|
505
|
-
this.$hiprint(
|
|
506
|
-
|
|
505
|
+
// const printEnpty = this.$hiprint({
|
|
506
|
+
// printData: {
|
|
507
|
+
// name: "CcSimple",
|
|
508
|
+
// barcode: "33321323",
|
|
509
|
+
// table: [
|
|
510
|
+
// { id: "1", name: "王小可123", gender: "男", count: "120", amount: "9089元" },
|
|
511
|
+
// { id: "2", name: "梦之遥", gender: "女", count: "20", amount: "89元" },
|
|
512
|
+
// ],
|
|
513
|
+
// table1: [
|
|
514
|
+
// { id: "1", name: "王小可11", gender: "男", count: "120", amount: "9089元" },
|
|
515
|
+
// { id: "2", name: "梦之遥", gender: "女", count: "20", amount: "89元" },
|
|
516
|
+
// ],
|
|
517
|
+
// },
|
|
518
|
+
// onPrintData: data => {
|
|
519
|
+
// return data;
|
|
520
|
+
// },
|
|
521
|
+
// onTemplate: data => {
|
|
522
|
+
// return data;
|
|
523
|
+
// },
|
|
524
|
+
// defaultTemplate: {
|
|
525
|
+
// panels: [
|
|
526
|
+
// {
|
|
527
|
+
// index: 0,
|
|
528
|
+
// name: 1,
|
|
529
|
+
// paperType: "A4",
|
|
530
|
+
// height: 297,
|
|
531
|
+
// width: 210,
|
|
532
|
+
// paperHeader: 0,
|
|
533
|
+
// paperFooter: 841.8897637795277,
|
|
534
|
+
// printElements: [
|
|
535
|
+
// {
|
|
536
|
+
// options: {
|
|
537
|
+
// left: 117,
|
|
538
|
+
// top: 94.5,
|
|
539
|
+
// height: 9.75,
|
|
540
|
+
// width: 120,
|
|
541
|
+
// field: "name",
|
|
542
|
+
// testData: "内容",
|
|
543
|
+
// title: "文本",
|
|
544
|
+
// qid: "name",
|
|
545
|
+
// },
|
|
546
|
+
// printElementType: {
|
|
547
|
+
// title: "文本",
|
|
548
|
+
// type: "text",
|
|
549
|
+
// },
|
|
550
|
+
// },
|
|
551
|
+
// {
|
|
552
|
+
// options: {
|
|
553
|
+
// left: 160.5,
|
|
554
|
+
// top: 174,
|
|
555
|
+
// height: 36,
|
|
556
|
+
// width: 550,
|
|
557
|
+
// fields: [],
|
|
558
|
+
// field: "table",
|
|
559
|
+
// qid: "table",
|
|
560
|
+
// columns: [
|
|
561
|
+
// [
|
|
562
|
+
// {
|
|
563
|
+
// width: 137.5,
|
|
564
|
+
// title: "名称",
|
|
565
|
+
// field: "name",
|
|
566
|
+
// checked: true,
|
|
567
|
+
// columnId: "name",
|
|
568
|
+
// fixed: false,
|
|
569
|
+
// rowspan: 1,
|
|
570
|
+
// colspan: 1,
|
|
571
|
+
// align: "center",
|
|
572
|
+
// },
|
|
573
|
+
// {
|
|
574
|
+
// width: 137.5,
|
|
575
|
+
// title: "性别",
|
|
576
|
+
// field: "gender",
|
|
577
|
+
// checked: true,
|
|
578
|
+
// columnId: "gender",
|
|
579
|
+
// fixed: false,
|
|
580
|
+
// rowspan: 1,
|
|
581
|
+
// colspan: 1,
|
|
582
|
+
// align: "center",
|
|
583
|
+
// },
|
|
584
|
+
// {
|
|
585
|
+
// width: 137.5,
|
|
586
|
+
// title: "数量",
|
|
587
|
+
// field: "count",
|
|
588
|
+
// checked: true,
|
|
589
|
+
// columnId: "count",
|
|
590
|
+
// fixed: false,
|
|
591
|
+
// rowspan: 1,
|
|
592
|
+
// colspan: 1,
|
|
593
|
+
// align: "center",
|
|
594
|
+
// },
|
|
595
|
+
// {
|
|
596
|
+
// width: 137.5,
|
|
597
|
+
// title: "金额",
|
|
598
|
+
// field: "amount",
|
|
599
|
+
// checked: true,
|
|
600
|
+
// columnId: "amount",
|
|
601
|
+
// fixed: false,
|
|
602
|
+
// rowspan: 1,
|
|
603
|
+
// colspan: 1,
|
|
604
|
+
// align: "center",
|
|
605
|
+
// },
|
|
606
|
+
// ],
|
|
607
|
+
// ],
|
|
608
|
+
// },
|
|
609
|
+
// printElementType: {
|
|
610
|
+
// title: "表格",
|
|
611
|
+
// type: "table",
|
|
612
|
+
// editable: true,
|
|
613
|
+
// columnDisplayEditable: true,
|
|
614
|
+
// columnDisplayIndexEditable: true,
|
|
615
|
+
// columnTitleEditable: true,
|
|
616
|
+
// columnResizable: true,
|
|
617
|
+
// columnAlignEditable: true,
|
|
618
|
+
// isEnableEditField: true,
|
|
619
|
+
// isEnableContextMenu: true,
|
|
620
|
+
// isEnableInsertRow: true,
|
|
621
|
+
// isEnableDeleteRow: true,
|
|
622
|
+
// isEnableInsertColumn: true,
|
|
623
|
+
// isEnableDeleteColumn: true,
|
|
624
|
+
// isEnableMergeCell: true,
|
|
625
|
+
// },
|
|
626
|
+
// },
|
|
627
|
+
// ],
|
|
628
|
+
// paperNumberContinue: true,
|
|
629
|
+
// watermarkOptions: {},
|
|
630
|
+
// panelLayoutOptions: {},
|
|
631
|
+
// },
|
|
632
|
+
// ],
|
|
633
|
+
// },
|
|
634
|
+
// onSubmit: data => {
|
|
635
|
+
// console.log(6666, data);
|
|
636
|
+
// },
|
|
637
|
+
// });
|
|
638
|
+
|
|
639
|
+
this.$hiprint.print({
|
|
640
|
+
printData: {
|
|
507
641
|
name: "CcSimple",
|
|
508
642
|
barcode: "33321323",
|
|
509
643
|
table: [
|
|
510
|
-
{ id: "1", name: "王小可", gender: "男", count: "120", amount: "9089元" },
|
|
644
|
+
{ id: "1", name: "王小可123", gender: "男", count: "120", amount: "9089元" },
|
|
511
645
|
{ id: "2", name: "梦之遥", gender: "女", count: "20", amount: "89元" },
|
|
512
646
|
],
|
|
513
647
|
table1: [
|
|
@@ -515,10 +649,126 @@ export default {
|
|
|
515
649
|
{ id: "2", name: "梦之遥", gender: "女", count: "20", amount: "89元" },
|
|
516
650
|
],
|
|
517
651
|
},
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
}
|
|
521
|
-
|
|
652
|
+
onPrintData: data => {
|
|
653
|
+
return data;
|
|
654
|
+
},
|
|
655
|
+
onTemplate: data => {
|
|
656
|
+
return data;
|
|
657
|
+
},
|
|
658
|
+
defaultTemplate: {
|
|
659
|
+
panels: [
|
|
660
|
+
{
|
|
661
|
+
index: 0,
|
|
662
|
+
name: 1,
|
|
663
|
+
paperType: "A4",
|
|
664
|
+
height: 297,
|
|
665
|
+
width: 210,
|
|
666
|
+
paperHeader: 0,
|
|
667
|
+
paperFooter: 841.8897637795277,
|
|
668
|
+
printElements: [
|
|
669
|
+
{
|
|
670
|
+
options: {
|
|
671
|
+
left: 117,
|
|
672
|
+
top: 94.5,
|
|
673
|
+
height: 9.75,
|
|
674
|
+
width: 120,
|
|
675
|
+
field: "name",
|
|
676
|
+
testData: "内容",
|
|
677
|
+
title: "文本",
|
|
678
|
+
qid: "name",
|
|
679
|
+
},
|
|
680
|
+
printElementType: {
|
|
681
|
+
title: "文本",
|
|
682
|
+
type: "text",
|
|
683
|
+
},
|
|
684
|
+
},
|
|
685
|
+
{
|
|
686
|
+
options: {
|
|
687
|
+
left: 160.5,
|
|
688
|
+
top: 174,
|
|
689
|
+
height: 36,
|
|
690
|
+
width: 550,
|
|
691
|
+
fields: [],
|
|
692
|
+
field: "table",
|
|
693
|
+
qid: "table",
|
|
694
|
+
columns: [
|
|
695
|
+
[
|
|
696
|
+
{
|
|
697
|
+
width: 137.5,
|
|
698
|
+
title: "名称",
|
|
699
|
+
field: "name",
|
|
700
|
+
checked: true,
|
|
701
|
+
columnId: "name",
|
|
702
|
+
fixed: false,
|
|
703
|
+
rowspan: 1,
|
|
704
|
+
colspan: 1,
|
|
705
|
+
align: "center",
|
|
706
|
+
},
|
|
707
|
+
{
|
|
708
|
+
width: 137.5,
|
|
709
|
+
title: "性别",
|
|
710
|
+
field: "gender",
|
|
711
|
+
checked: true,
|
|
712
|
+
columnId: "gender",
|
|
713
|
+
fixed: false,
|
|
714
|
+
rowspan: 1,
|
|
715
|
+
colspan: 1,
|
|
716
|
+
align: "center",
|
|
717
|
+
},
|
|
718
|
+
{
|
|
719
|
+
width: 137.5,
|
|
720
|
+
title: "数量",
|
|
721
|
+
field: "count",
|
|
722
|
+
checked: true,
|
|
723
|
+
columnId: "count",
|
|
724
|
+
fixed: false,
|
|
725
|
+
rowspan: 1,
|
|
726
|
+
colspan: 1,
|
|
727
|
+
align: "center",
|
|
728
|
+
},
|
|
729
|
+
{
|
|
730
|
+
width: 137.5,
|
|
731
|
+
title: "金额",
|
|
732
|
+
field: "amount",
|
|
733
|
+
checked: true,
|
|
734
|
+
columnId: "amount",
|
|
735
|
+
fixed: false,
|
|
736
|
+
rowspan: 1,
|
|
737
|
+
colspan: 1,
|
|
738
|
+
align: "center",
|
|
739
|
+
},
|
|
740
|
+
],
|
|
741
|
+
],
|
|
742
|
+
},
|
|
743
|
+
printElementType: {
|
|
744
|
+
title: "表格",
|
|
745
|
+
type: "table",
|
|
746
|
+
editable: true,
|
|
747
|
+
columnDisplayEditable: true,
|
|
748
|
+
columnDisplayIndexEditable: true,
|
|
749
|
+
columnTitleEditable: true,
|
|
750
|
+
columnResizable: true,
|
|
751
|
+
columnAlignEditable: true,
|
|
752
|
+
isEnableEditField: true,
|
|
753
|
+
isEnableContextMenu: true,
|
|
754
|
+
isEnableInsertRow: true,
|
|
755
|
+
isEnableDeleteRow: true,
|
|
756
|
+
isEnableInsertColumn: true,
|
|
757
|
+
isEnableDeleteColumn: true,
|
|
758
|
+
isEnableMergeCell: true,
|
|
759
|
+
},
|
|
760
|
+
},
|
|
761
|
+
],
|
|
762
|
+
paperNumberContinue: true,
|
|
763
|
+
watermarkOptions: {},
|
|
764
|
+
panelLayoutOptions: {},
|
|
765
|
+
},
|
|
766
|
+
],
|
|
767
|
+
},
|
|
768
|
+
onSubmit: data => {
|
|
769
|
+
console.log(6666, data);
|
|
770
|
+
},
|
|
771
|
+
});
|
|
522
772
|
},
|
|
523
773
|
},
|
|
524
774
|
};
|
|
@@ -11,7 +11,8 @@ let container = null;
|
|
|
11
11
|
|
|
12
12
|
const Hiprint = {
|
|
13
13
|
install(Vue) {
|
|
14
|
-
|
|
14
|
+
const hiprint = function (options) {
|
|
15
|
+
const { printData, onPrintData, defaultTemplate, onTemplate, onSubmit } = options;
|
|
15
16
|
// 销毁旧实例
|
|
16
17
|
if (printInstance) {
|
|
17
18
|
printInstance.$destroy();
|
|
@@ -27,26 +28,47 @@ const Hiprint = {
|
|
|
27
28
|
document.body.appendChild(container);
|
|
28
29
|
|
|
29
30
|
const PrintComponent = Vue.extend(OlPrint);
|
|
31
|
+
const propsData = {};
|
|
32
|
+
if (printData) {
|
|
33
|
+
propsData.printData = printData;
|
|
34
|
+
}
|
|
35
|
+
if (onPrintData) {
|
|
36
|
+
propsData.onPrintData = onPrintData;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
if (onTemplate) {
|
|
40
|
+
propsData.onTemplate = onTemplate;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
if (defaultTemplate) {
|
|
44
|
+
propsData.defaultTemplate = defaultTemplate;
|
|
45
|
+
}
|
|
46
|
+
|
|
30
47
|
printInstance = new PrintComponent({
|
|
31
|
-
propsData
|
|
32
|
-
printData: data || {},
|
|
33
|
-
onTemplate: template,
|
|
34
|
-
},
|
|
48
|
+
propsData,
|
|
35
49
|
});
|
|
36
50
|
|
|
51
|
+
// 监听 submit 事件
|
|
52
|
+
if (onSubmit && typeof onSubmit === "function") {
|
|
53
|
+
printInstance.$on("submit", json => {
|
|
54
|
+
onSubmit(json);
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
|
|
37
58
|
printInstance.$mount(container);
|
|
59
|
+
|
|
60
|
+
// 返回实例,方便外部调用
|
|
61
|
+
return printInstance;
|
|
38
62
|
};
|
|
63
|
+
Vue.prototype.$hiprint = hiprint;
|
|
39
64
|
|
|
40
|
-
//
|
|
41
|
-
Vue.prototype.$hiprint.
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
printInstance = null;
|
|
48
|
-
container = null;
|
|
49
|
-
}
|
|
65
|
+
// 快捷方法:直接打印
|
|
66
|
+
Vue.prototype.$hiprint.print = function (options) {
|
|
67
|
+
const instance = hiprint(options);
|
|
68
|
+
instance.print();
|
|
69
|
+
instance.$nextTick(() => {
|
|
70
|
+
instance.close();
|
|
71
|
+
});
|
|
50
72
|
};
|
|
51
73
|
},
|
|
52
74
|
};
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div class="paper-selector">
|
|
3
|
+
<el-button-group>
|
|
4
|
+
<el-button
|
|
5
|
+
v-for="(value, type) in paperTypes"
|
|
6
|
+
:key="type"
|
|
7
|
+
:type="curPaperType === type ? 'primary' : 'default'"
|
|
8
|
+
size="small"
|
|
9
|
+
@click="setPaper(type, value)"
|
|
10
|
+
>
|
|
11
|
+
{{ type }}
|
|
12
|
+
</el-button>
|
|
13
|
+
<el-button
|
|
14
|
+
:type="curPaperType === 'other' ? 'primary' : 'default'"
|
|
15
|
+
size="small"
|
|
16
|
+
@click="showPaperPop"
|
|
17
|
+
>
|
|
18
|
+
自定义纸张
|
|
19
|
+
</el-button>
|
|
20
|
+
</el-button-group>
|
|
21
|
+
|
|
22
|
+
<el-dialog
|
|
23
|
+
title="设置纸张宽高(mm)"
|
|
24
|
+
:visible.sync="paperPopVisible"
|
|
25
|
+
width="400px"
|
|
26
|
+
:append-to-body="true"
|
|
27
|
+
>
|
|
28
|
+
<el-form label-width="80px">
|
|
29
|
+
<el-form-item label="纸张宽度">
|
|
30
|
+
<el-input v-model="paperWidth" type="number" placeholder="宽(mm)" />
|
|
31
|
+
</el-form-item>
|
|
32
|
+
<el-form-item label="纸张高度">
|
|
33
|
+
<el-input v-model="paperHeight" type="number" placeholder="高(mm)" />
|
|
34
|
+
</el-form-item>
|
|
35
|
+
</el-form>
|
|
36
|
+
<span slot="footer">
|
|
37
|
+
<el-button @click="hidePaperPop">取消</el-button>
|
|
38
|
+
<el-button type="primary" @click="setPaperOther">确定</el-button>
|
|
39
|
+
</span>
|
|
40
|
+
</el-dialog>
|
|
41
|
+
</div>
|
|
42
|
+
</template>
|
|
43
|
+
|
|
44
|
+
<script>
|
|
45
|
+
export default {
|
|
46
|
+
name: "PaperSelector",
|
|
47
|
+
props: {
|
|
48
|
+
hiprintTemplate: {
|
|
49
|
+
type: Object,
|
|
50
|
+
required: true,
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
data() {
|
|
54
|
+
return {
|
|
55
|
+
curPaper: {
|
|
56
|
+
type: "A4",
|
|
57
|
+
width: 210,
|
|
58
|
+
height: 296.6,
|
|
59
|
+
},
|
|
60
|
+
paperTypes: {
|
|
61
|
+
A3: { width: 420, height: 296.6 },
|
|
62
|
+
A4: { width: 210, height: 296.6 },
|
|
63
|
+
A5: { width: 210, height: 147.6 },
|
|
64
|
+
B3: { width: 500, height: 352.6 },
|
|
65
|
+
B4: { width: 250, height: 352.6 },
|
|
66
|
+
B5: { width: 250, height: 175.6 },
|
|
67
|
+
},
|
|
68
|
+
paperPopVisible: false,
|
|
69
|
+
paperWidth: "220",
|
|
70
|
+
paperHeight: "80",
|
|
71
|
+
};
|
|
72
|
+
},
|
|
73
|
+
computed: {
|
|
74
|
+
curPaperType() {
|
|
75
|
+
let type = "other";
|
|
76
|
+
let types = this.paperTypes;
|
|
77
|
+
for (const key in types) {
|
|
78
|
+
let item = types[key];
|
|
79
|
+
let { width, height } = this.curPaper;
|
|
80
|
+
if (item.width === width && item.height === height) {
|
|
81
|
+
type = key;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
return type;
|
|
85
|
+
},
|
|
86
|
+
},
|
|
87
|
+
methods: {
|
|
88
|
+
showPaperPop() {
|
|
89
|
+
this.paperPopVisible = true;
|
|
90
|
+
},
|
|
91
|
+
hidePaperPop() {
|
|
92
|
+
this.paperPopVisible = false;
|
|
93
|
+
},
|
|
94
|
+
setPaper(type, value) {
|
|
95
|
+
try {
|
|
96
|
+
if (Object.keys(this.paperTypes).includes(type)) {
|
|
97
|
+
this.curPaper = { type: type, width: value.width, height: value.height };
|
|
98
|
+
this.hiprintTemplate.setPaper(value.width, value.height);
|
|
99
|
+
} else {
|
|
100
|
+
this.curPaper = { type: "other", width: value.width, height: value.height };
|
|
101
|
+
this.hiprintTemplate.setPaper(value.width, value.height);
|
|
102
|
+
}
|
|
103
|
+
this.$emit("change", this.curPaper);
|
|
104
|
+
} catch (error) {
|
|
105
|
+
this.$message.error(`操作失败: ${error}`);
|
|
106
|
+
}
|
|
107
|
+
},
|
|
108
|
+
setPaperOther() {
|
|
109
|
+
let value = {};
|
|
110
|
+
value.width = Number(this.paperWidth);
|
|
111
|
+
value.height = Number(this.paperHeight);
|
|
112
|
+
this.paperPopVisible = false;
|
|
113
|
+
this.setPaper("other", value);
|
|
114
|
+
},
|
|
115
|
+
},
|
|
116
|
+
};
|
|
117
|
+
</script>
|
|
118
|
+
|
|
119
|
+
<style scoped>
|
|
120
|
+
.paper-selector {
|
|
121
|
+
display: inline-block;
|
|
122
|
+
}
|
|
123
|
+
</style>
|
|
@@ -14,21 +14,31 @@
|
|
|
14
14
|
<i class="iconfont close-btn" @click="close">x</i>
|
|
15
15
|
</div>
|
|
16
16
|
<div class="print-dialog-body">
|
|
17
|
-
<div class="
|
|
18
|
-
<
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
<
|
|
28
|
-
|
|
29
|
-
|
|
17
|
+
<div class="header-box" style="margin-bottom: 10px">
|
|
18
|
+
<paper-selector :hiprint-template="hiprintTemplate" ref="paperSelector" />
|
|
19
|
+
<div>
|
|
20
|
+
<slot
|
|
21
|
+
:hiprint-template="hiprintTemplate"
|
|
22
|
+
:print="print"
|
|
23
|
+
:clear-paper="clearPaper"
|
|
24
|
+
:export-json="exportJson"
|
|
25
|
+
>
|
|
26
|
+
</slot>
|
|
27
|
+
<el-button type="primary" size="small" @click="print">
|
|
28
|
+
<i class="iconfont sv-printer" />
|
|
29
|
+
浏览器预览
|
|
30
|
+
</el-button>
|
|
31
|
+
<el-button type="danger" size="small" @click="clearPaper" style="margin-left: 10px">
|
|
32
|
+
<i class="iconfont sv-clear" />
|
|
33
|
+
清空纸张
|
|
34
|
+
</el-button>
|
|
35
|
+
<el-button type="success" size="small" @click="exportJson" style="margin-left: 10px">
|
|
36
|
+
<i class="iconfont sv-export" />
|
|
37
|
+
保存
|
|
38
|
+
</el-button>
|
|
39
|
+
</div>
|
|
30
40
|
</div>
|
|
31
|
-
<div class="flex-row" style="height: 87vh">
|
|
41
|
+
<div class="main flex-row" style="height: 87vh">
|
|
32
42
|
<div class="flex-2 left flex-col">
|
|
33
43
|
<!-- provider1 的容器; 加上 class "rect-printElement-types" 使用默认样式 -->
|
|
34
44
|
<!-- 当然可以 重写 或者 自定义样式 -->
|
|
@@ -52,39 +62,56 @@
|
|
|
52
62
|
// import { onMounted } from "vue";
|
|
53
63
|
import { hiprint } from "vue-plugin-hiprint";
|
|
54
64
|
import { provider1 } from "./provide/provider1.js";
|
|
65
|
+
import PaperSelector from "./components/PaperSelector.vue";
|
|
66
|
+
|
|
55
67
|
export default {
|
|
56
68
|
name: "print",
|
|
69
|
+
components: {
|
|
70
|
+
PaperSelector,
|
|
71
|
+
},
|
|
57
72
|
props: {
|
|
58
73
|
// 打印数据
|
|
59
74
|
printData: {
|
|
60
75
|
type: Object,
|
|
61
|
-
default: () =>
|
|
62
|
-
name: "CcSimple",
|
|
63
|
-
barcode: "33321323",
|
|
64
|
-
table: [
|
|
65
|
-
{ id: "1", name: "王小可", gender: "男", count: "120", amount: "9089元" },
|
|
66
|
-
{ id: "2", name: "梦之遥", gender: "女", count: "20", amount: "89元" },
|
|
67
|
-
],
|
|
68
|
-
table1: [
|
|
69
|
-
{ id: "1", name: "王小可11", gender: "男", count: "120", amount: "9089元" },
|
|
70
|
-
{ id: "2", name: "梦之遥", gender: "女", count: "20", amount: "89元" },
|
|
71
|
-
],
|
|
72
|
-
}),
|
|
76
|
+
default: () => {},
|
|
73
77
|
},
|
|
74
|
-
//
|
|
75
|
-
|
|
78
|
+
// {
|
|
79
|
+
// name: "CcSimple",
|
|
80
|
+
// barcode: "33321323",
|
|
81
|
+
// table: [
|
|
82
|
+
// { id: "1", name: "王小可", gender: "男", count: "120", amount: "9089元" },
|
|
83
|
+
// { id: "2", name: "梦之遥", gender: "女", count: "20", amount: "89元" },
|
|
84
|
+
// ],
|
|
85
|
+
// table1: [
|
|
86
|
+
// { id: "1", name: "王小可11", gender: "男", count: "120", amount: "9089元" },
|
|
87
|
+
// { id: "2", name: "梦之遥", gender: "女", count: "20", amount: "89元" },
|
|
88
|
+
// ],
|
|
89
|
+
// }
|
|
90
|
+
onPrintData: {
|
|
76
91
|
type: Function,
|
|
92
|
+
default: null,
|
|
93
|
+
},
|
|
94
|
+
// {panels:[]}
|
|
95
|
+
defaultTemplate: {
|
|
96
|
+
type: Object,
|
|
77
97
|
default: () => {},
|
|
78
98
|
},
|
|
99
|
+
// 模板数据前置钩子
|
|
100
|
+
onTemplate: {
|
|
101
|
+
type: Function,
|
|
102
|
+
default: null,
|
|
103
|
+
},
|
|
104
|
+
grid: {
|
|
105
|
+
type: Boolean,
|
|
106
|
+
default: false,
|
|
107
|
+
},
|
|
79
108
|
},
|
|
80
109
|
data() {
|
|
81
110
|
return {
|
|
82
|
-
hiprintTemplate:
|
|
111
|
+
hiprintTemplate: {},
|
|
83
112
|
};
|
|
84
113
|
},
|
|
85
114
|
created() {
|
|
86
|
-
console.log("初始化打印弹框");
|
|
87
|
-
|
|
88
115
|
hiprint.init({
|
|
89
116
|
// providers: [defaultElementTypeProvider()],
|
|
90
117
|
providers: [provider1()],
|
|
@@ -102,52 +129,63 @@ export default {
|
|
|
102
129
|
// eslint-disable-next-line no-undef
|
|
103
130
|
// hiprint.PrintElementTypeManager.buildByHtml($(".ep-draggable-item"));
|
|
104
131
|
},
|
|
105
|
-
buildDesigner() {
|
|
132
|
+
async buildDesigner() {
|
|
106
133
|
// eslint-disable-next-line no-undef
|
|
107
134
|
$("#hiprint-printTemplate").empty(); // 先清空, 避免重复构建
|
|
108
|
-
// 判断用户是否传了onTemplate
|
|
109
|
-
if (this.onTemplate) {
|
|
110
|
-
console.log(123123);
|
|
111
135
|
|
|
112
|
-
|
|
136
|
+
let template = this.defaultTemplate;
|
|
137
|
+
if (this.onTemplate) {
|
|
138
|
+
try {
|
|
139
|
+
const result = await this.onTemplate(this.defaultTemplate);
|
|
140
|
+
if (result) {
|
|
141
|
+
template = result;
|
|
142
|
+
}
|
|
143
|
+
} catch (error) {
|
|
144
|
+
console.error("onTemplate 执行失败:", error);
|
|
145
|
+
}
|
|
113
146
|
}
|
|
147
|
+
|
|
114
148
|
this.hiprintTemplate = new hiprint.PrintTemplate({
|
|
149
|
+
template,
|
|
115
150
|
settingContainer: "#PrintElementOptionSetting", // 元素参数容器
|
|
116
151
|
// paginationContainer: ".hiprint-printPagination", //多页打印
|
|
117
152
|
history: true,
|
|
118
153
|
onDataChanged: (type, json) => {
|
|
119
|
-
// 模板发生改变回调
|
|
120
154
|
console.log(type); // 新增、移动、删除、修改(参数调整)、大小、旋转
|
|
121
155
|
console.log(json); // 返回 template
|
|
122
156
|
},
|
|
123
|
-
// fontList: [
|
|
124
|
-
// { title: "微软雅黑", value: "Microsoft YaHei" },
|
|
125
|
-
// { title: "黑体", value: "STHeitiSC-Light" },
|
|
126
|
-
// { title: "思源黑体", value: "SourceHanSansCN-Normal" },
|
|
127
|
-
// { title: "王羲之书法体", value: "王羲之书法体" },
|
|
128
|
-
// { title: "宋体", value: "SimSun" },
|
|
129
|
-
// { title: "华为楷体", value: "STKaiti" },
|
|
130
|
-
// { title: "cursive", value: "cursive" },
|
|
131
|
-
// ],
|
|
132
157
|
});
|
|
158
|
+
this.$refs.paperSelector.curPaper = { width: 210, height: 296.6 };
|
|
133
159
|
// 构建 并填充到 容器中
|
|
134
160
|
// 可以先 console.log($("#hiprint-printTemplate")) 看看是否有该 dom
|
|
135
|
-
this.hiprintTemplate.design("#hiprint-printTemplate"
|
|
161
|
+
this.hiprintTemplate.design("#hiprint-printTemplate", {
|
|
162
|
+
grid: this.grid,
|
|
163
|
+
});
|
|
136
164
|
},
|
|
137
|
-
print() {
|
|
165
|
+
async print() {
|
|
138
166
|
// 使用外部传入的打印数据
|
|
139
167
|
let data = this.printData;
|
|
168
|
+
if (this.onPrintData) {
|
|
169
|
+
try {
|
|
170
|
+
const result = await this.onPrintData(this.printData);
|
|
171
|
+
if (result) {
|
|
172
|
+
data = result;
|
|
173
|
+
}
|
|
174
|
+
} catch (error) {
|
|
175
|
+
console.error("onPrintData 执行失败:", error);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
140
178
|
// 参数: 打印时设置 左偏移量,上偏移量
|
|
141
179
|
let options = { leftOffset: -1, topOffset: -1 };
|
|
142
180
|
// 扩展
|
|
143
181
|
let ext = {
|
|
144
|
-
callback: () => {
|
|
145
|
-
|
|
146
|
-
},
|
|
147
|
-
styleHandler: () => {
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
},
|
|
182
|
+
// callback: () => {
|
|
183
|
+
// console.log("浏览器打印窗口已打开");
|
|
184
|
+
// },
|
|
185
|
+
// styleHandler: () => {
|
|
186
|
+
// // 重写 文本 打印样式
|
|
187
|
+
// return "<style>.hiprint-printElement-text{color:red !important;}</style>";
|
|
188
|
+
// },
|
|
151
189
|
};
|
|
152
190
|
// 调用浏览器打印
|
|
153
191
|
this.hiprintTemplate.print(data, options, ext);
|
|
@@ -156,15 +194,18 @@ export default {
|
|
|
156
194
|
const json = this.hiprintTemplate.getJson();
|
|
157
195
|
const dataStr = JSON.stringify(json, null, 2);
|
|
158
196
|
const blob = new Blob([dataStr], { type: "application/json" });
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
document.
|
|
164
|
-
link.
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
197
|
+
console.log("保存", JSON.parse(dataStr));
|
|
198
|
+
this.$emit("submit", JSON.parse(dataStr));
|
|
199
|
+
this.close();
|
|
200
|
+
// const url = URL.createObjectURL(blob);
|
|
201
|
+
// const link = document.createElement("a");
|
|
202
|
+
// link.href = url;
|
|
203
|
+
// link.download = `print-template-${Date.now()}.json`;
|
|
204
|
+
// document.body.appendChild(link);
|
|
205
|
+
// link.click();
|
|
206
|
+
// document.body.removeChild(link);
|
|
207
|
+
// URL.revokeObjectURL(url);
|
|
208
|
+
// alert("导出成功!");
|
|
168
209
|
},
|
|
169
210
|
clearPaper() {
|
|
170
211
|
this.hiprintTemplate.clear();
|
|
@@ -525,7 +566,7 @@ button i {
|
|
|
525
566
|
display: flex;
|
|
526
567
|
align-items: center;
|
|
527
568
|
justify-content: center;
|
|
528
|
-
z-index:
|
|
569
|
+
z-index: 2000;
|
|
529
570
|
}
|
|
530
571
|
|
|
531
572
|
.print-dialog {
|
|
@@ -563,6 +604,12 @@ button i {
|
|
|
563
604
|
flex: 1;
|
|
564
605
|
overflow: hidden;
|
|
565
606
|
padding: 10px;
|
|
607
|
+
display: flex;
|
|
608
|
+
flex-direction: column;
|
|
609
|
+
}
|
|
610
|
+
.print-dialog-body .main {
|
|
611
|
+
flex: 1;
|
|
612
|
+
overflow: hidden;
|
|
566
613
|
}
|
|
567
614
|
</style>
|
|
568
615
|
|
|
@@ -570,4 +617,9 @@ button i {
|
|
|
570
617
|
.button-item {
|
|
571
618
|
height: 40px;
|
|
572
619
|
}
|
|
620
|
+
.header-box {
|
|
621
|
+
display: flex;
|
|
622
|
+
align-items: center;
|
|
623
|
+
justify-content: space-between;
|
|
624
|
+
}
|
|
573
625
|
</style>
|