yh-hiprint 2.5.2 → 3.0.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.
@@ -37,13 +37,13 @@
37
37
  v-model="paperWidth"
38
38
  type="number">
39
39
  <template #prepend>宽</template>
40
- <template #append>px</template>
40
+ <template #append>mm</template>
41
41
  </el-input>
42
42
  <el-input
43
43
  v-model="paperHeight"
44
44
  type="number">
45
45
  <template #prepend>高</template>
46
- <template #append>px</template>
46
+ <template #append>mm</template>
47
47
  </el-input>
48
48
  <el-button
49
49
  type="primary"
@@ -437,6 +437,7 @@ import {useRoute, onBeforeRouteUpdate} from 'vue-router';
437
437
  import {toValue} from '@vueuse/core';
438
438
  import {ElMessageBox, ElMessage} from 'element-plus';
439
439
  import axios from '@/libs/api.request';
440
+ import previewHiprint from './libs/previewHiprint';
440
441
 
441
442
  interface HiprintTemplate {
442
443
  setPaper: (width: number, height: number) => void;
@@ -449,11 +450,6 @@ const route = useRoute();
449
450
  const hiprintTemplate = shallowRef<HiprintTemplate | null>(null);
450
451
 
451
452
  const {paperType, paperTypeName, paperTypesObj, paperWidth, paperHeight, setPaper} = usePaper();
452
- function setPaperHandler(type) {
453
- setPaper(type, () => {
454
- hiprintTemplate.value?.setPaper(paperWidth.value, paperHeight.value);
455
- });
456
- }
457
453
 
458
454
  const canvasRef = ref();
459
455
  const {scaleValue, scalePercentage, canZoomIn, canZoomOut, zoomIn, zoomOut} = useScale(() => {
@@ -461,50 +457,8 @@ const {scaleValue, scalePercentage, canZoomIn, canZoomOut, zoomIn, zoomOut} = us
461
457
  canvasRef?.value.update();
462
458
  });
463
459
 
464
- const previewShow = ref(false);
465
- const previewHtml = ref('');
466
460
  async function previewPrint() {
467
- let {
468
- data: {list, json},
469
- } = await axios.request({
470
- url: `/printTemplate/data/${detailData.value.code}`,
471
- method: 'post',
472
- type: 'json',
473
- data: [
474
- {
475
- code: '50101820',
476
- },
477
- ],
478
- });
479
- if (json) {
480
- if (Array.isArray(list) && list.length > 0) {
481
- list = list.map((item) => {
482
- let printData = {};
483
- let datas = Object.entries(item);
484
- datas.forEach((arr) => {
485
- if (Array.isArray(arr[1])) {
486
- printData[arr[0]] = arr[1];
487
- } else {
488
- if (arr[1] !== null) {
489
- let itemsEntries = Object.entries(arr[1]);
490
- itemsEntries.forEach((cArr) => {
491
- printData[`$${arr[0]}[${cArr[0]}]`] = cArr[1];
492
- });
493
- }
494
- }
495
- });
496
- return printData;
497
- });
498
- } else {
499
- list = [];
500
- }
501
- previewHtml.value = new hiprint.PrintTemplate({template: JSON.parse(json)}).getHtml(list)[0].innerHTML;
502
- previewShow.value = true;
503
- } else {
504
- ElMessage.warning({
505
- message: '模板配置不存在,请检查',
506
- });
507
- }
461
+ previewHiprint(detailData.value.code);
508
462
  }
509
463
 
510
464
  function saveConfig() {
@@ -538,13 +492,6 @@ function clearPrint() {
538
492
  hiprintTemplate.value?.clear();
539
493
  }
540
494
 
541
- function testUpdate() {
542
- let els = hiprintTemplate.value.getSelectEls();
543
- window.a = els[0];
544
- a.options.top = a.options.top + 10;
545
- hiprintJQuery(a.designTarget[0]).css('top', a.options.displayTop());
546
- }
547
-
548
495
  const {detailData, getDetail, listCode, dataSourceList, listColumns, formCode, formColumns, dataSourceForm, getDataSourceList} = useDataSource(axios);
549
496
 
550
497
  watch(
@@ -763,145 +710,7 @@ function tableColumnCancel() {
763
710
  selectedTableEle.value = null;
764
711
  }
765
712
 
766
- function init() {
767
- try {
768
- hiprint.init({
769
- host: 'http://localhost:17521',
770
- providers: [new defaultElementTypeProvider()],
771
- });
772
- hiprint.setConfig();
773
- hiprint.setConfig({
774
- optionItems: [fontSize, scale, zIndex],
775
- movingDistance: 2.5,
776
- text: {
777
- tabs: [
778
- {
779
- options: [],
780
- },
781
- {
782
- name: '样式',
783
- options: [
784
- {
785
- name: 'scale',
786
- after: 'transform',
787
- hidden: false,
788
- },
789
- ],
790
- },
791
- ],
792
- supportOptions: [
793
- {
794
- name: 'styler',
795
- hidden: true,
796
- },
797
- {
798
- name: 'scale',
799
- after: 'transform',
800
- hidden: false,
801
- },
802
- {
803
- name: 'formatter',
804
- hidden: true,
805
- },
806
- ],
807
- },
808
- image: {
809
- tabs: [
810
- {
811
- replace: true,
812
- name: '基本',
813
- options: [
814
- {
815
- name: 'field',
816
- hidden: false,
817
- },
818
- {
819
- name: 'src',
820
- hidden: false,
821
- },
822
- {
823
- name: 'fit',
824
- hidden: false,
825
- },
826
- ],
827
- },
828
- ],
829
- },
830
- table: {
831
- tabs: [{options: [{name: 'field', hidden: true}]}],
832
- },
833
- });
834
-
835
- hiprint.PrintElementTypeManager.buildByHtml(hiprintJQuery('.ep-draggable-item'));
836
- hiprintJQuery('#hiprint-printTemplate').empty();
837
- let template = JSON.parse(detailData.value.json) || panel;
838
- hiprintTemplate.value = new hiprint.PrintTemplate({
839
- template,
840
- onImageChooseClick: (target) => {
841
- console.log(target);
842
- },
843
- fontList: [
844
- {title: '微软雅黑', value: 'Microsoft YaHei'},
845
- {title: '黑体', value: 'STHeitiSC-Light'},
846
- {title: '思源黑体', value: 'SourceHanSansCN-Normal'},
847
- {title: '宋体', value: 'SimSun'},
848
- {title: '华为楷体', value: 'STKaiti'},
849
- {title: 'cursive', value: 'cursive'},
850
- {title: 'Times New Roman', value: 'Times New Roman'},
851
- ],
852
- dataMode: 1,
853
- history: true,
854
- onDataChanged: (type, json) => {},
855
- onUpdateError: (e) => {
856
- console.error(e);
857
- },
858
- settingContainer: '#PrintElementOptionSetting',
859
- paginationContainer: '.hiprint-printPagination',
860
- });
861
-
862
- hiprintTemplate.value?.design('#hiprint-printTemplate', {grid: true});
863
- scaleValue.value = hiprintTemplate.value.editingPanel.scale || 1;
864
- window.ht = hiprintTemplate.value;
865
-
866
- if (formColumns.value) {
867
- hiprintTemplate.value?.setFields(
868
- formColumns.value.map((item) => {
869
- return {
870
- field: item,
871
- text: item,
872
- };
873
- })
874
- );
875
- }
876
- hiprintJQuery('.hiprint-designer').on('mousedown', '.hiprint-printElement', (e) => {
877
- let t = e.currentTarget;
878
- selectedEle.value = hiprintTemplate.value?.getSelectEls() || [];
879
- let pes = hiprintTemplate.value?.editingPanel.printElements;
880
- let index = pes.map((item) => item.designTarget[0]).findIndex((item) => t === item);
881
- let pe = pes[index];
882
- selectedTableEle.value = pe || null;
883
- if (pe && pe.options.field) {
884
- listCode.value = pe.options.field;
885
- }
886
- });
887
- hiprintJQuery('#PrintElementOptionSetting').on('input', 'input[type=number]', ($el) => {
888
- let val = parseInt($el.target.value);
889
- if (val < 1) {
890
- $el.target.value = 1;
891
- }
892
- if (val > 2000) {
893
- $el.target.value = 2000;
894
- }
895
- });
896
- } catch (error) {
897
- console.log(error.message);
898
- clearPrint();
899
- hiprintTemplate.value = null;
900
- if (error.message.indexOf('setTemplateId') > -1) {
901
- ElMessageBox.alert('模板有错误,请返回列表手动修改或这清空模板!');
902
- }
903
- }
904
- }
713
+ function init() {}
905
714
 
906
715
  let updateing = false;
907
716
  async function updateTemplate(code) {
@@ -953,7 +762,6 @@ const hasDataSource = computed(() => {
953
762
  });
954
763
 
955
764
  function wheelHandler(e: MouseEvent) {
956
- console.log(e);
957
765
  if (e.ctrlKey) {
958
766
  const isZoomIn = e.wheelDelta < 0;
959
767
  const isZoomOut = e.wheelDelta > 0;
@@ -1141,6 +949,22 @@ onMounted(async () => {
1141
949
  }
1142
950
  }
1143
951
 
952
+ .print-preview-dialog {
953
+ min-width: 1000px;
954
+ max-width: 1200px;
955
+ .el-message-box__container {
956
+ justify-content: center;
957
+ background-color: #f2f2f2;
958
+ }
959
+ .hiprint-printPaper {
960
+ margin-top: 5px;
961
+ position: relative;
962
+ background-color: #fff;
963
+ &:last-child {
964
+ margin-bottom: 5px;
965
+ }
966
+ }
967
+ }
1144
968
  .paper-setting {
1145
969
  display: flex;
1146
970
  .paper-setting_types {
package/config.json ADDED
@@ -0,0 +1,399 @@
1
+ {
2
+ "panels": [
3
+ {
4
+ "index": 0,
5
+ "name": 1,
6
+ "height": 297,
7
+ "width": 210,
8
+ "paperHeader": 7.5,
9
+ "paperFooter": 780,
10
+ "printElements": [
11
+ {
12
+ "options": {
13
+ "left": 20,
14
+ "top": 20,
15
+ "height": 9.75,
16
+ "width": 120,
17
+ "transform": 12,
18
+ "title": "文本",
19
+ "right": 139.9921875,
20
+ "bottom": 29.7421875,
21
+ "vCenter": 79.9921875,
22
+ "hCenter": 24.8671875,
23
+ "field": "1212",
24
+ "testData": "1212",
25
+ "coordinateSync": false,
26
+ "widthHeightSync": false,
27
+ "dataType": "datetime",
28
+ "format": "M/d",
29
+ "fontFamily": "Microsoft YaHei",
30
+ "fontSize": 4,
31
+ "fontWeight": "lighter",
32
+ "letterSpacing": 0.75,
33
+ "color": "#915c5c",
34
+ "backgroundColor": "#9e7272",
35
+ "textDecoration": "underline",
36
+ "textAlign": "center",
37
+ "textContentVerticalAlign": "middle",
38
+ "textContentWrap": "nowrap",
39
+ "lineHeight": 11.25,
40
+ "scale": 1,
41
+ "zIndex": 2,
42
+ "borderLeft": "solid",
43
+ "borderTop": "solid",
44
+ "borderRight": "solid",
45
+ "borderBottom": "solid",
46
+ "borderWidth": "0.75",
47
+ "borderColor": "#8f7b7b",
48
+ "contentPaddingLeft": 0.75,
49
+ "contentPaddingTop": 0.75,
50
+ "contentPaddingRight": 0.75,
51
+ "contentPaddingBottom": 0.75,
52
+ "barcodeMode": "CODE128A",
53
+ "qrCodeLevel": 1,
54
+ "pageBreak": true,
55
+ "showInPage": "first",
56
+ "unShowInPage": "first",
57
+ "axis": "h",
58
+ "upperCase": "0",
59
+ "formatter": "function(title,value,options.templateData.target){}\n",
60
+ "styler": "function(value,options.target.templateData){}"
61
+ },
62
+ "printElementType": {
63
+ "title": "文本",
64
+ "type": "text"
65
+ }
66
+ },
67
+ {
68
+ "options": {
69
+ "left": 20,
70
+ "top": 52.5,
71
+ "height": 9.75,
72
+ "width": 120,
73
+ "hideTitle": true,
74
+ "title": "值(文本)",
75
+ "right": 142.5,
76
+ "bottom": 63,
77
+ "vCenter": 82.5,
78
+ "hCenter": 58.125
79
+ },
80
+ "printElementType": {
81
+ "title": "值(文本)",
82
+ "type": "text"
83
+ }
84
+ },
85
+ {
86
+ "options": {
87
+ "left": 22.5,
88
+ "top": 85,
89
+ "height": 79.5,
90
+ "width": 61.5,
91
+ "right": 85.2421875,
92
+ "bottom": 165.24609375,
93
+ "vCenter": 54.4921875,
94
+ "hCenter": 125.49609375
95
+ },
96
+ "printElementType": {
97
+ "title": "图片",
98
+ "type": "image"
99
+ }
100
+ },
101
+ {
102
+ "options": {
103
+ "left": 22.5,
104
+ "top": 190,
105
+ "height": 42,
106
+ "width": 550,
107
+ "title": "长文"
108
+ },
109
+ "printElementType": {
110
+ "title": "长文",
111
+ "type": "longText"
112
+ }
113
+ },
114
+ {
115
+ "options": {
116
+ "left": 22.5,
117
+ "top": 240,
118
+ "height": 39,
119
+ "width": 550,
120
+ "field": "",
121
+ "columns": [
122
+ [
123
+ {
124
+ "width": 275,
125
+ "title": "阿恃多伐底",
126
+ "field": "",
127
+ "checked": true,
128
+ "columnId": "asdf",
129
+ "fixed": false,
130
+ "rowspan": 1,
131
+ "colspan": 1
132
+ },
133
+ {
134
+ "width": 275,
135
+ "title": "啊啊啊啊",
136
+ "field": "",
137
+ "checked": true,
138
+ "columnId": "asdf",
139
+ "fixed": false,
140
+ "rowspan": 1,
141
+ "colspan": 1
142
+ }
143
+ ],
144
+ [
145
+ {
146
+ "width": 257.85949999999997,
147
+ "checked": true,
148
+ "fixed": false,
149
+ "rowspan": 1,
150
+ "colspan": 1
151
+ },
152
+ {
153
+ "width": 292.14050000000003,
154
+ "checked": true,
155
+ "fixed": false,
156
+ "rowspan": 1,
157
+ "colspan": 1
158
+ }
159
+ ]
160
+ ]
161
+ },
162
+ "printElementType": {
163
+ "title": "表格",
164
+ "type": "table",
165
+ "editable": true,
166
+ "columnDisplayEditable": true,
167
+ "columnDisplayIndexEditable": true,
168
+ "columnTitleEditable": true,
169
+ "columnResizable": true,
170
+ "columnAlignEditable": true,
171
+ "isEnableEditField": true,
172
+ "isEnableContextMenu": true,
173
+ "isEnableInsertRow": true,
174
+ "isEnableDeleteRow": true,
175
+ "isEnableInsertColumn": true,
176
+ "isEnableDeleteColumn": true,
177
+ "isEnableMergeCell": true
178
+ }
179
+ },
180
+ {
181
+ "options": {
182
+ "left": 22.5,
183
+ "top": 272.5,
184
+ "height": 4,
185
+ "width": 550,
186
+ "field": "",
187
+ "coordinateSync": false,
188
+ "widthHeightSync": false,
189
+ "columns": [
190
+ [
191
+ {
192
+ "width": 250.82074999999998,
193
+ "title": "啊啊啊啊",
194
+ "checked": true,
195
+ "fixed": false,
196
+ "rowspan": 1,
197
+ "colspan": 1
198
+ },
199
+ {
200
+ "width": 299.17925,
201
+ "title": "啊啊啊啊",
202
+ "checked": true,
203
+ "fixed": false,
204
+ "rowspan": 1,
205
+ "colspan": 1
206
+ }
207
+ ]
208
+ ]
209
+ },
210
+ "printElementType": {
211
+ "title": "空白表格",
212
+ "type": "table",
213
+ "editable": true,
214
+ "columnDisplayEditable": true,
215
+ "columnDisplayIndexEditable": true,
216
+ "columnTitleEditable": true,
217
+ "columnResizable": true,
218
+ "columnAlignEditable": true,
219
+ "isEnableEditField": true,
220
+ "isEnableContextMenu": true,
221
+ "isEnableInsertRow": true,
222
+ "isEnableDeleteRow": true,
223
+ "isEnableInsertColumn": true,
224
+ "isEnableDeleteColumn": true,
225
+ "isEnableMergeCell": true
226
+ }
227
+ },
228
+ {
229
+ "options": {
230
+ "left": 22.5,
231
+ "top": 305,
232
+ "height": 90,
233
+ "width": 90,
234
+ "formatter": "function (data, options) {\n return '<div></div>';\n }",
235
+ "right": 114,
236
+ "bottom": 395.49609375,
237
+ "vCenter": 69,
238
+ "hCenter": 350.49609375
239
+ },
240
+ "printElementType": {
241
+ "title": "html",
242
+ "type": "html"
243
+ }
244
+ },
245
+ {
246
+ "options": {
247
+ "left": 30,
248
+ "top": 417.5,
249
+ "height": 9.75,
250
+ "width": 120,
251
+ "title": "自定义文本",
252
+ "right": 148.9921875,
253
+ "bottom": 426.24609375,
254
+ "vCenter": 88.9921875,
255
+ "hCenter": 421.37109375
256
+ },
257
+ "printElementType": {
258
+ "title": "自定义文本",
259
+ "type": "text"
260
+ }
261
+ },
262
+ {
263
+ "options": {
264
+ "left": 30,
265
+ "top": 462.5,
266
+ "height": 32,
267
+ "width": 120,
268
+ "field": "barcode",
269
+ "testData": "lkforntend",
270
+ "fontSize": 12,
271
+ "lineHeight": 18,
272
+ "textType": "barcode",
273
+ "title": "条形码"
274
+ },
275
+ "printElementType": {
276
+ "title": "条形码",
277
+ "type": "text"
278
+ }
279
+ },
280
+ {
281
+ "options": {
282
+ "left": 40,
283
+ "top": 552.5,
284
+ "height": 50,
285
+ "width": 50,
286
+ "testData": "力控元海-技术中心-前端",
287
+ "field": "qrcode",
288
+ "textType": "qrcode",
289
+ "title": "二维码"
290
+ },
291
+ "printElementType": {
292
+ "title": "二维码",
293
+ "type": "text"
294
+ }
295
+ },
296
+ {
297
+ "options": {
298
+ "left": 40,
299
+ "top": 645,
300
+ "height": 9,
301
+ "width": 90,
302
+ "right": 131.7421875,
303
+ "bottom": 654.4921875,
304
+ "vCenter": 86.7421875,
305
+ "hCenter": 649.9921875,
306
+ "coordinateSync": false,
307
+ "widthHeightSync": false,
308
+ "borderWidth": "2.25",
309
+ "borderStyle": "solid",
310
+ "borderColor": "#000000"
311
+ },
312
+ "printElementType": {
313
+ "title": "横线",
314
+ "type": "hline"
315
+ }
316
+ },
317
+ {
318
+ "options": {
319
+ "left": 215,
320
+ "top": 677.5,
321
+ "height": 90,
322
+ "width": 90,
323
+ "right": 303.99609375,
324
+ "bottom": 766.74609375,
325
+ "vCenter": 258.99609375,
326
+ "hCenter": 721.74609375,
327
+ "coordinateSync": false,
328
+ "widthHeightSync": false,
329
+ "borderWidth": "1.5",
330
+ "borderStyle": "solid",
331
+ "borderColor": "#000000"
332
+ },
333
+ "printElementType": {
334
+ "title": "矩形",
335
+ "type": "rect"
336
+ }
337
+ },
338
+ {
339
+ "options": {
340
+ "left": 122.5,
341
+ "top": 687.5,
342
+ "height": 90,
343
+ "width": 9,
344
+ "coordinateSync": false,
345
+ "widthHeightSync": false,
346
+ "borderWidth": "1.5",
347
+ "borderStyle": "solid",
348
+ "borderColor": "#000000"
349
+ },
350
+ "printElementType": {
351
+ "title": "竖线",
352
+ "type": "vline"
353
+ }
354
+ },
355
+ {
356
+ "options": {
357
+ "left": 382.5,
358
+ "top": 690,
359
+ "height": 90,
360
+ "width": 90,
361
+ "coordinateSync": false,
362
+ "widthHeightSync": false,
363
+ "borderWidth": "0.75",
364
+ "borderStyle": "solid",
365
+ "borderColor": "#000000"
366
+ },
367
+ "printElementType": {
368
+ "title": "椭圆",
369
+ "type": "oval"
370
+ }
371
+ }
372
+ ],
373
+ "paperNumberLeft": 565,
374
+ "paperNumberTop": 45,
375
+ "paperNumberContinue": false,
376
+ "paperNumberFormat": "1",
377
+ "panelPaperRule": "odd",
378
+ "panelPageRule": "none",
379
+ "firstPaperFooter": 1,
380
+ "evenPaperFooter": 1,
381
+ "oddPaperFooter": 1,
382
+ "lastPaperFooter": 1,
383
+ "topOffset": 1,
384
+ "fontFamily": "Microsoft YaHei",
385
+ "leftOffset": 1,
386
+ "orient": 1,
387
+ "watermarkOptions": {
388
+ "content": "阿恃多伐底",
389
+ "rotate": 25,
390
+ "timestamp": true,
391
+ "format": "YYYY-MM-DD HH:mm",
392
+ "fillStyle": "rgba(184, 184, 184, 0.3)",
393
+ "fontSize": "14px",
394
+ "width": 200,
395
+ "height": 200
396
+ }
397
+ }
398
+ ]
399
+ }