ol-base-components 2.9.4 → 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.
@@ -0,0 +1,573 @@
1
+ <!--
2
+ * @Description: 使用 — 入门篇;
3
+ * @Author: CcSimple
4
+ * @Github: https://github.com/CcSimple
5
+ * @Date: 2023-02-07 11:52:50
6
+ * @LastEditors: CcSimple
7
+ * @LastEditTime: 2023-02-09 11:25:36
8
+ -->
9
+ <template>
10
+ <div class="print-dialog-overlay">
11
+ <div class="print-dialog">
12
+ <div class="print-dialog-header">
13
+ <span>打印设计器</span>
14
+ <i class="iconfont close-btn" @click="close">x</i>
15
+ </div>
16
+ <div class="print-dialog-body">
17
+ <div class="flex-row justify-center" style="margin-bottom: 10px">
18
+ <button class="secondary circle-10 button-item" @click.stop="print">
19
+ <i class="iconfont sv-printer" />
20
+ 浏览器打印
21
+ </button>
22
+ <button class="api circle-10 ml-10" @click.stop="clearPaper">
23
+ <i class="iconfont sv-clear" />
24
+ 清空纸张
25
+ </button>
26
+ <button class="api circle-10 ml-10 button-item" @click.stop="exportJson">
27
+ <i class="iconfont sv-export" />
28
+ 导出模板 json
29
+ </button>
30
+ </div>
31
+ <div class="flex-row" style="height: 87vh">
32
+ <div class="flex-2 left flex-col">
33
+ <!-- provider1 的容器; 加上 class "rect-printElement-types" 使用默认样式 -->
34
+ <!-- 当然可以 重写 或者 自定义样式 -->
35
+ <div id="provider-container1" class="container rect-printElement-types"></div>
36
+ </div>
37
+ <div class="flex-5 center">
38
+ <!-- 设计器的 容器 -->
39
+ <div id="hiprint-printTemplate"></div>
40
+ </div>
41
+ <div class="flex-2 right">
42
+ <!-- 元素参数的 容器 -->
43
+ <div id="PrintElementOptionSetting"></div>
44
+ </div>
45
+ </div>
46
+ </div>
47
+ </div>
48
+ </div>
49
+ </template>
50
+
51
+ <script>
52
+ // import { onMounted } from "vue";
53
+ import { hiprint } from "vue-plugin-hiprint";
54
+ import { provider1 } from "./provide/provider1.js";
55
+ export default {
56
+ name: "print",
57
+ props: {
58
+ // 打印数据
59
+ printData: {
60
+ 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
+ }),
73
+ },
74
+ // 模板加载前回调函数
75
+ onTemplate: {
76
+ type: Function,
77
+ default: () => {},
78
+ },
79
+ },
80
+ data() {
81
+ return {
82
+ hiprintTemplate: null,
83
+ };
84
+ },
85
+ created() {
86
+ console.log("初始化打印弹框");
87
+
88
+ hiprint.init({
89
+ // providers: [defaultElementTypeProvider()],
90
+ providers: [provider1()],
91
+ });
92
+ },
93
+ mounted() {
94
+ this.buildLeftElement();
95
+ this.buildDesigner();
96
+ },
97
+ methods: {
98
+ buildLeftElement() {
99
+ $("#provider-container1").empty();
100
+ hiprint.PrintElementTypeManager.build($("#provider-container1"), "providerModule1");
101
+
102
+ // eslint-disable-next-line no-undef
103
+ // hiprint.PrintElementTypeManager.buildByHtml($(".ep-draggable-item"));
104
+ },
105
+ buildDesigner() {
106
+ // eslint-disable-next-line no-undef
107
+ $("#hiprint-printTemplate").empty(); // 先清空, 避免重复构建
108
+ // 判断用户是否传了onTemplate
109
+ if (this.onTemplate) {
110
+ console.log(123123);
111
+
112
+ // this.onTemplate(this.hiprintTemplate);
113
+ }
114
+ this.hiprintTemplate = new hiprint.PrintTemplate({
115
+ settingContainer: "#PrintElementOptionSetting", // 元素参数容器
116
+ // paginationContainer: ".hiprint-printPagination", //多页打印
117
+ history: true,
118
+ onDataChanged: (type, json) => {
119
+ // 模板发生改变回调
120
+ console.log(type); // 新增、移动、删除、修改(参数调整)、大小、旋转
121
+ console.log(json); // 返回 template
122
+ },
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
+ });
133
+ // 构建 并填充到 容器中
134
+ // 可以先 console.log($("#hiprint-printTemplate")) 看看是否有该 dom
135
+ this.hiprintTemplate.design("#hiprint-printTemplate");
136
+ },
137
+ print() {
138
+ // 使用外部传入的打印数据
139
+ let data = this.printData;
140
+ // 参数: 打印时设置 左偏移量,上偏移量
141
+ let options = { leftOffset: -1, topOffset: -1 };
142
+ // 扩展
143
+ let ext = {
144
+ callback: () => {
145
+ console.log("浏览器打印窗口已打开");
146
+ },
147
+ styleHandler: () => {
148
+ // 重写 文本 打印样式
149
+ return "<style>.hiprint-printElement-text{color:red !important;}</style>";
150
+ },
151
+ };
152
+ // 调用浏览器打印
153
+ this.hiprintTemplate.print(data, options, ext);
154
+ },
155
+ exportJson() {
156
+ const json = this.hiprintTemplate.getJson();
157
+ const dataStr = JSON.stringify(json, null, 2);
158
+ const blob = new Blob([dataStr], { type: "application/json" });
159
+ const url = URL.createObjectURL(blob);
160
+ const link = document.createElement("a");
161
+ link.href = url;
162
+ link.download = `print-template-${Date.now()}.json`;
163
+ document.body.appendChild(link);
164
+ link.click();
165
+ document.body.removeChild(link);
166
+ URL.revokeObjectURL(url);
167
+ alert("导出成功!");
168
+ },
169
+ clearPaper() {
170
+ this.hiprintTemplate.clear();
171
+ },
172
+ close() {
173
+ this.$destroy();
174
+ this.$el.remove();
175
+ },
176
+ },
177
+ };
178
+ </script>
179
+
180
+ <style>
181
+ /* flex */
182
+ .flex-row {
183
+ display: flex;
184
+ }
185
+ .flex-col {
186
+ display: flex;
187
+ flex-direction: column;
188
+ }
189
+ .flex-wrap {
190
+ flex-wrap: wrap;
191
+ }
192
+ .align-center {
193
+ align-items: center;
194
+ }
195
+ .justify-center {
196
+ justify-content: center;
197
+ }
198
+
199
+ .flex-1 {
200
+ flex: 1;
201
+ }
202
+ .flex-2 {
203
+ flex: 2;
204
+ }
205
+ .flex-3 {
206
+ flex: 3;
207
+ }
208
+ .flex-4 {
209
+ flex: 4;
210
+ }
211
+ .flex-5 {
212
+ flex: 5;
213
+ }
214
+
215
+ .ml-10 {
216
+ margin-left: 10px;
217
+ }
218
+ .mr-10 {
219
+ margin-right: 10px;
220
+ }
221
+ .mt-10 {
222
+ margin-top: 10px;
223
+ }
224
+ .mb-10 {
225
+ margin-bottom: 10px;
226
+ }
227
+
228
+ /* button 样式 为了好看点 */
229
+ button {
230
+ padding: 10px;
231
+ min-width: 40px;
232
+ color: white;
233
+ opacity: 0.9;
234
+ cursor: pointer;
235
+ border-width: 0;
236
+ border: 1px solid #d9d9d9;
237
+ }
238
+ button:hover {
239
+ opacity: 1;
240
+ }
241
+ button i {
242
+ font-size: 16px !important;
243
+ }
244
+ .circle,
245
+ .circle-4 {
246
+ border-radius: 4px !important;
247
+ }
248
+ .circle-10 {
249
+ border-radius: 10px !important;
250
+ }
251
+ /* 按钮颜色 */
252
+ .primary {
253
+ background: purple;
254
+ }
255
+ .info {
256
+ color: #000;
257
+ background: none;
258
+ }
259
+ .info:hover {
260
+ color: purple;
261
+ border-color: purple;
262
+ }
263
+ .secondary {
264
+ background: #1976d2;
265
+ }
266
+ .warning {
267
+ background: #d32f2f;
268
+ }
269
+
270
+ /* modal */
271
+ .modal {
272
+ padding: 0;
273
+ margin: 0;
274
+ }
275
+ .modal .mask {
276
+ position: fixed;
277
+ top: 0;
278
+ right: 0;
279
+ bottom: 0;
280
+ left: 0;
281
+ z-index: 1000;
282
+ height: 100%;
283
+ background-color: #00000073;
284
+ }
285
+ .modal .wrap {
286
+ position: fixed;
287
+ top: 0;
288
+ right: 0;
289
+ bottom: 0;
290
+ left: 0;
291
+ z-index: 1000;
292
+ overflow: auto;
293
+ background-color: #00000073;
294
+ outline: 0;
295
+ }
296
+ .modal .wrap .box {
297
+ position: relative;
298
+ margin: 10% auto;
299
+ width: 40%;
300
+ background: #fff;
301
+ border-radius: 4px;
302
+ z-index: 1001;
303
+ box-shadow: 0 5px 10px rgba(0, 0, 0, 0.2);
304
+ transition: all 0.3s ease;
305
+ }
306
+ .modal-box__header {
307
+ padding: 10px 14px;
308
+ border-bottom: 1px solid #e9e9e9;
309
+ }
310
+ .modal-box__footer {
311
+ text-align: end;
312
+ }
313
+ .modal-box__footer button {
314
+ min-width: 100px;
315
+ }
316
+ .modal-box__footer button:not(:last-child) {
317
+ margin-right: 10px;
318
+ }
319
+
320
+ /* 重写全局 hiprint 样式 */
321
+ .hiprint-headerLine,
322
+ .hiprint-footerLine {
323
+ border-color: purple !important;
324
+ }
325
+
326
+ .hiprint-headerLine:hover,
327
+ .hiprint-footerLine:hover {
328
+ border-top: 3px dashed purple !important;
329
+ }
330
+
331
+ .hiprint-headerLine:hover:before {
332
+ content: "页眉线";
333
+ left: calc(50% - 18px);
334
+ position: relative;
335
+ background: #ffff;
336
+ top: -14px;
337
+ color: purple;
338
+ font-size: 12px;
339
+ }
340
+
341
+ .hiprint-footerLine:hover:before {
342
+ content: "页脚线";
343
+ left: calc(50% - 18px);
344
+ position: relative;
345
+ color: purple;
346
+ background: #ffff;
347
+ top: -14px;
348
+ font-size: 12px;
349
+ }
350
+ </style>
351
+
352
+ <style>
353
+ /* 重写默认的一个样式 */
354
+ .rect-printElement-types .hiprint-printElement-type > li > ul > li > a {
355
+ color: #000 !important;
356
+ display: flex;
357
+ align-items: center;
358
+ justify-content: center;
359
+ }
360
+
361
+ /* 自定义 provider 构建样式 */
362
+ .custom-style-types .hiprint-printElement-type {
363
+ display: block;
364
+ }
365
+ .custom-style-types .hiprint-printElement-type {
366
+ padding: 0 0 0 0;
367
+ list-style: none;
368
+ }
369
+ .custom-style-types .hiprint-printElement-type > li > .title {
370
+ display: block;
371
+ padding: 4px 0px;
372
+ color: rgb(0, 58, 230);
373
+ clear: both;
374
+ }
375
+ .custom-style-types .hiprint-printElement-type > li > ul {
376
+ padding: 0 0 0 0;
377
+ display: block;
378
+ list-style: none;
379
+ }
380
+ .custom-style-types .hiprint-printElement-type > li > ul > li {
381
+ display: block;
382
+ width: 50%;
383
+ float: left;
384
+ max-width: 100px;
385
+ }
386
+ .custom-style-types .hiprint-printElement-type > li > ul > li > a {
387
+ padding: 12px 6px;
388
+ color: #1296db;
389
+ text-decoration: none;
390
+ background: #fff;
391
+ border: 1px solid #ddd;
392
+ margin-right: 5px;
393
+ width: 95%;
394
+ max-width: 100px;
395
+ display: inline-block;
396
+ text-align: center;
397
+ margin-bottom: 7px;
398
+ box-sizing: border-box;
399
+ border: 1px solid rgba(0, 0, 0, 0.2);
400
+ border-radius: 4px;
401
+ box-shadow: 0 1px 0 0 rgba(0, 0, 0, 0.15);
402
+ }
403
+ </style>
404
+ <style scoped>
405
+ /* api按钮 */
406
+ .api {
407
+ background: #00acc1;
408
+ }
409
+ .auto {
410
+ width: auto !important;
411
+ }
412
+ /* 纸张 */
413
+ .paper {
414
+ margin-right: 10px;
415
+ }
416
+ .paper button:not(class*="auto") {
417
+ width: 60px !important;
418
+ }
419
+ /* 多个 button 间距 */
420
+ .paper button + button {
421
+ margin-left: -1px;
422
+ }
423
+ .paper button:first-child:last-child {
424
+ border-radius: 4px;
425
+ }
426
+ /* 两边的 btn 圆角 */
427
+ .paper button:first-child:not(:last-child) {
428
+ border-top-left-radius: 4px;
429
+ border-bottom-left-radius: 4px;
430
+ }
431
+ .paper button:last-child:not(:first-child) {
432
+ border-top-right-radius: 4px;
433
+ border-bottom-right-radius: 4px;
434
+ }
435
+ .popover {
436
+ position: absolute;
437
+ margin-top: 10px;
438
+ z-index: 10;
439
+ }
440
+ .popover .popover-content {
441
+ background: white;
442
+ border-radius: 4px;
443
+ padding: 10px 14px;
444
+ box-shadow: 2px 2px 2px 4px rgb(128 0 128 / 20%);
445
+ }
446
+ .popover .input {
447
+ height: 24px;
448
+ padding: 2px 4px;
449
+ }
450
+ .popover .input:hover {
451
+ border-color: rgb(245, 155, 241);
452
+ border-radius: 4px;
453
+ }
454
+
455
+ /* 区域 */
456
+ .left {
457
+ background: white;
458
+ border-radius: 4px;
459
+ border: 1px solid #d9d9d9;
460
+ box-shadow: 2px 2px 2px 0px rgb(128 0 128 / 20%);
461
+ overflow: auto;
462
+ }
463
+ .left .container {
464
+ height: 100%;
465
+ overflow: auto;
466
+ padding: 0 10%;
467
+ background: rgba(92, 91, 92, 0.1);
468
+ }
469
+ .left .container[id*="provider-container2"] {
470
+ margin-bottom: 10px;
471
+ background: rgba(92, 91, 92, 0.1);
472
+ }
473
+ .center {
474
+ margin: 0 10px;
475
+ background: white;
476
+ border-radius: 4px;
477
+ border: 1px solid #d9d9d9;
478
+ padding: 20px;
479
+ box-shadow: 2px 2px 2px 0px rgb(128 0 128 / 20%);
480
+ overflow: auto;
481
+ }
482
+ .right {
483
+ background: white;
484
+ border-radius: 4px;
485
+ border: 1px solid #d9d9d9;
486
+ padding: 10px 0;
487
+ box-shadow: 2px 2px 2px 0px rgb(128 0 128 / 20%);
488
+ overflow: auto;
489
+ }
490
+ /* 左侧拖拽元素样式 */
491
+ .title {
492
+ font-size: 16px;
493
+ font-weight: 500;
494
+ margin: 4px 0 4px 10px;
495
+ }
496
+ .item {
497
+ display: flex;
498
+ flex-direction: column;
499
+ align-items: center;
500
+ background: white;
501
+ padding: 4px 10px;
502
+ margin: 10px 8px 4px 8px;
503
+ width: 38%;
504
+ min-height: 60px;
505
+ border-radius: 4px;
506
+ box-shadow: 2px 2px 2px 2px rgba(171, 171, 171, 0.2);
507
+ }
508
+ .item .iconfont {
509
+ font-size: 1.5rem;
510
+ }
511
+ .item span {
512
+ font-size: 14px;
513
+ }
514
+ </style>
515
+
516
+ <!-- 弹框样式 -->
517
+ <style scoped>
518
+ .print-dialog-overlay {
519
+ position: fixed;
520
+ top: 0;
521
+ left: 0;
522
+ right: 0;
523
+ bottom: 0;
524
+ background: rgba(0, 0, 0, 0.5);
525
+ display: flex;
526
+ align-items: center;
527
+ justify-content: center;
528
+ z-index: 9999;
529
+ }
530
+
531
+ .print-dialog {
532
+ background: #fff;
533
+ width: 95vw;
534
+ height: 95vh;
535
+ border-radius: 8px;
536
+ box-shadow: 0 2px 12px rgba(0, 0, 0, 0.15);
537
+ display: flex;
538
+ flex-direction: column;
539
+ }
540
+
541
+ .print-dialog-header {
542
+ display: flex;
543
+ justify-content: space-between;
544
+ align-items: center;
545
+ padding: 12px 20px;
546
+ border-bottom: 1px solid #e8e8e8;
547
+ font-size: 16px;
548
+ font-weight: 500;
549
+ }
550
+
551
+ .close-btn {
552
+ cursor: pointer;
553
+ font-size: 20px;
554
+ color: #000;
555
+ font-style: normal;
556
+ }
557
+
558
+ .close-btn:hover {
559
+ color: #606266;
560
+ }
561
+
562
+ .print-dialog-body {
563
+ flex: 1;
564
+ overflow: hidden;
565
+ padding: 10px;
566
+ }
567
+ </style>
568
+
569
+ <style scoped>
570
+ .button-item {
571
+ height: 40px;
572
+ }
573
+ </style>
@@ -0,0 +1,110 @@
1
+ {
2
+ "panels": [
3
+ {
4
+ "index": 0,
5
+ "name": 1,
6
+ "paperType": "A4",
7
+ "height": 297,
8
+ "width": 210,
9
+ "paperHeader": 0,
10
+ "paperFooter": 841.8897637795277,
11
+ "printElements": [
12
+ {
13
+ "options": {
14
+ "left": 117,
15
+ "top": 94.5,
16
+ "height": 9.75,
17
+ "width": 120,
18
+ "field": "name",
19
+ "testData": "内容",
20
+ "title": "文本",
21
+ "qid": "name"
22
+ },
23
+ "printElementType": {
24
+ "title": "文本",
25
+ "type": "text"
26
+ }
27
+ },
28
+ {
29
+ "options": {
30
+ "left": 160.5,
31
+ "top": 174,
32
+ "height": 36,
33
+ "width": 550,
34
+ "fields": [],
35
+ "field": "table",
36
+ "qid": "table",
37
+ "columns": [
38
+ [
39
+ {
40
+ "width": 137.5,
41
+ "title": "名称",
42
+ "field": "name",
43
+ "checked": true,
44
+ "columnId": "name",
45
+ "fixed": false,
46
+ "rowspan": 1,
47
+ "colspan": 1,
48
+ "align": "center"
49
+ },
50
+ {
51
+ "width": 137.5,
52
+ "title": "性别",
53
+ "field": "gender",
54
+ "checked": true,
55
+ "columnId": "gender",
56
+ "fixed": false,
57
+ "rowspan": 1,
58
+ "colspan": 1,
59
+ "align": "center"
60
+ },
61
+ {
62
+ "width": 137.5,
63
+ "title": "数量",
64
+ "field": "count",
65
+ "checked": true,
66
+ "columnId": "count",
67
+ "fixed": false,
68
+ "rowspan": 1,
69
+ "colspan": 1,
70
+ "align": "center"
71
+ },
72
+ {
73
+ "width": 137.5,
74
+ "title": "金额",
75
+ "field": "amount",
76
+ "checked": true,
77
+ "columnId": "amount",
78
+ "fixed": false,
79
+ "rowspan": 1,
80
+ "colspan": 1,
81
+ "align": "center"
82
+ }
83
+ ]
84
+ ]
85
+ },
86
+ "printElementType": {
87
+ "title": "表格",
88
+ "type": "table",
89
+ "editable": true,
90
+ "columnDisplayEditable": true,
91
+ "columnDisplayIndexEditable": true,
92
+ "columnTitleEditable": true,
93
+ "columnResizable": true,
94
+ "columnAlignEditable": true,
95
+ "isEnableEditField": true,
96
+ "isEnableContextMenu": true,
97
+ "isEnableInsertRow": true,
98
+ "isEnableDeleteRow": true,
99
+ "isEnableInsertColumn": true,
100
+ "isEnableDeleteColumn": true,
101
+ "isEnableMergeCell": true
102
+ }
103
+ }
104
+ ],
105
+ "paperNumberContinue": true,
106
+ "watermarkOptions": {},
107
+ "panelLayoutOptions": {}
108
+ }
109
+ ]
110
+ }