ol-base-components 2.9.4 → 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.
@@ -0,0 +1,625 @@
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="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>
40
+ </div>
41
+ <div class="main flex-row" style="height: 87vh">
42
+ <div class="flex-2 left flex-col">
43
+ <!-- provider1 的容器; 加上 class "rect-printElement-types" 使用默认样式 -->
44
+ <!-- 当然可以 重写 或者 自定义样式 -->
45
+ <div id="provider-container1" class="container rect-printElement-types"></div>
46
+ </div>
47
+ <div class="flex-5 center">
48
+ <!-- 设计器的 容器 -->
49
+ <div id="hiprint-printTemplate"></div>
50
+ </div>
51
+ <div class="flex-2 right">
52
+ <!-- 元素参数的 容器 -->
53
+ <div id="PrintElementOptionSetting"></div>
54
+ </div>
55
+ </div>
56
+ </div>
57
+ </div>
58
+ </div>
59
+ </template>
60
+
61
+ <script>
62
+ // import { onMounted } from "vue";
63
+ import { hiprint } from "vue-plugin-hiprint";
64
+ import { provider1 } from "./provide/provider1.js";
65
+ import PaperSelector from "./components/PaperSelector.vue";
66
+
67
+ export default {
68
+ name: "print",
69
+ components: {
70
+ PaperSelector,
71
+ },
72
+ props: {
73
+ // 打印数据
74
+ printData: {
75
+ type: Object,
76
+ default: () => {},
77
+ },
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: {
91
+ type: Function,
92
+ default: null,
93
+ },
94
+ // {panels:[]}
95
+ defaultTemplate: {
96
+ type: Object,
97
+ default: () => {},
98
+ },
99
+ // 模板数据前置钩子
100
+ onTemplate: {
101
+ type: Function,
102
+ default: null,
103
+ },
104
+ grid: {
105
+ type: Boolean,
106
+ default: false,
107
+ },
108
+ },
109
+ data() {
110
+ return {
111
+ hiprintTemplate: {},
112
+ };
113
+ },
114
+ created() {
115
+ hiprint.init({
116
+ // providers: [defaultElementTypeProvider()],
117
+ providers: [provider1()],
118
+ });
119
+ },
120
+ mounted() {
121
+ this.buildLeftElement();
122
+ this.buildDesigner();
123
+ },
124
+ methods: {
125
+ buildLeftElement() {
126
+ $("#provider-container1").empty();
127
+ hiprint.PrintElementTypeManager.build($("#provider-container1"), "providerModule1");
128
+
129
+ // eslint-disable-next-line no-undef
130
+ // hiprint.PrintElementTypeManager.buildByHtml($(".ep-draggable-item"));
131
+ },
132
+ async buildDesigner() {
133
+ // eslint-disable-next-line no-undef
134
+ $("#hiprint-printTemplate").empty(); // 先清空, 避免重复构建
135
+
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
+ }
146
+ }
147
+
148
+ this.hiprintTemplate = new hiprint.PrintTemplate({
149
+ template,
150
+ settingContainer: "#PrintElementOptionSetting", // 元素参数容器
151
+ // paginationContainer: ".hiprint-printPagination", //多页打印
152
+ history: true,
153
+ onDataChanged: (type, json) => {
154
+ console.log(type); // 新增、移动、删除、修改(参数调整)、大小、旋转
155
+ console.log(json); // 返回 template
156
+ },
157
+ });
158
+ this.$refs.paperSelector.curPaper = { width: 210, height: 296.6 };
159
+ // 构建 并填充到 容器中
160
+ // 可以先 console.log($("#hiprint-printTemplate")) 看看是否有该 dom
161
+ this.hiprintTemplate.design("#hiprint-printTemplate", {
162
+ grid: this.grid,
163
+ });
164
+ },
165
+ async print() {
166
+ // 使用外部传入的打印数据
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
+ }
178
+ // 参数: 打印时设置 左偏移量,上偏移量
179
+ let options = { leftOffset: -1, topOffset: -1 };
180
+ // 扩展
181
+ let ext = {
182
+ // callback: () => {
183
+ // console.log("浏览器打印窗口已打开");
184
+ // },
185
+ // styleHandler: () => {
186
+ // // 重写 文本 打印样式
187
+ // return "<style>.hiprint-printElement-text{color:red !important;}</style>";
188
+ // },
189
+ };
190
+ // 调用浏览器打印
191
+ this.hiprintTemplate.print(data, options, ext);
192
+ },
193
+ exportJson() {
194
+ const json = this.hiprintTemplate.getJson();
195
+ const dataStr = JSON.stringify(json, null, 2);
196
+ const blob = new Blob([dataStr], { type: "application/json" });
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("导出成功!");
209
+ },
210
+ clearPaper() {
211
+ this.hiprintTemplate.clear();
212
+ },
213
+ close() {
214
+ this.$destroy();
215
+ this.$el.remove();
216
+ },
217
+ },
218
+ };
219
+ </script>
220
+
221
+ <style>
222
+ /* flex */
223
+ .flex-row {
224
+ display: flex;
225
+ }
226
+ .flex-col {
227
+ display: flex;
228
+ flex-direction: column;
229
+ }
230
+ .flex-wrap {
231
+ flex-wrap: wrap;
232
+ }
233
+ .align-center {
234
+ align-items: center;
235
+ }
236
+ .justify-center {
237
+ justify-content: center;
238
+ }
239
+
240
+ .flex-1 {
241
+ flex: 1;
242
+ }
243
+ .flex-2 {
244
+ flex: 2;
245
+ }
246
+ .flex-3 {
247
+ flex: 3;
248
+ }
249
+ .flex-4 {
250
+ flex: 4;
251
+ }
252
+ .flex-5 {
253
+ flex: 5;
254
+ }
255
+
256
+ .ml-10 {
257
+ margin-left: 10px;
258
+ }
259
+ .mr-10 {
260
+ margin-right: 10px;
261
+ }
262
+ .mt-10 {
263
+ margin-top: 10px;
264
+ }
265
+ .mb-10 {
266
+ margin-bottom: 10px;
267
+ }
268
+
269
+ /* button 样式 为了好看点 */
270
+ button {
271
+ padding: 10px;
272
+ min-width: 40px;
273
+ color: white;
274
+ opacity: 0.9;
275
+ cursor: pointer;
276
+ border-width: 0;
277
+ border: 1px solid #d9d9d9;
278
+ }
279
+ button:hover {
280
+ opacity: 1;
281
+ }
282
+ button i {
283
+ font-size: 16px !important;
284
+ }
285
+ .circle,
286
+ .circle-4 {
287
+ border-radius: 4px !important;
288
+ }
289
+ .circle-10 {
290
+ border-radius: 10px !important;
291
+ }
292
+ /* 按钮颜色 */
293
+ .primary {
294
+ background: purple;
295
+ }
296
+ .info {
297
+ color: #000;
298
+ background: none;
299
+ }
300
+ .info:hover {
301
+ color: purple;
302
+ border-color: purple;
303
+ }
304
+ .secondary {
305
+ background: #1976d2;
306
+ }
307
+ .warning {
308
+ background: #d32f2f;
309
+ }
310
+
311
+ /* modal */
312
+ .modal {
313
+ padding: 0;
314
+ margin: 0;
315
+ }
316
+ .modal .mask {
317
+ position: fixed;
318
+ top: 0;
319
+ right: 0;
320
+ bottom: 0;
321
+ left: 0;
322
+ z-index: 1000;
323
+ height: 100%;
324
+ background-color: #00000073;
325
+ }
326
+ .modal .wrap {
327
+ position: fixed;
328
+ top: 0;
329
+ right: 0;
330
+ bottom: 0;
331
+ left: 0;
332
+ z-index: 1000;
333
+ overflow: auto;
334
+ background-color: #00000073;
335
+ outline: 0;
336
+ }
337
+ .modal .wrap .box {
338
+ position: relative;
339
+ margin: 10% auto;
340
+ width: 40%;
341
+ background: #fff;
342
+ border-radius: 4px;
343
+ z-index: 1001;
344
+ box-shadow: 0 5px 10px rgba(0, 0, 0, 0.2);
345
+ transition: all 0.3s ease;
346
+ }
347
+ .modal-box__header {
348
+ padding: 10px 14px;
349
+ border-bottom: 1px solid #e9e9e9;
350
+ }
351
+ .modal-box__footer {
352
+ text-align: end;
353
+ }
354
+ .modal-box__footer button {
355
+ min-width: 100px;
356
+ }
357
+ .modal-box__footer button:not(:last-child) {
358
+ margin-right: 10px;
359
+ }
360
+
361
+ /* 重写全局 hiprint 样式 */
362
+ .hiprint-headerLine,
363
+ .hiprint-footerLine {
364
+ border-color: purple !important;
365
+ }
366
+
367
+ .hiprint-headerLine:hover,
368
+ .hiprint-footerLine:hover {
369
+ border-top: 3px dashed purple !important;
370
+ }
371
+
372
+ .hiprint-headerLine:hover:before {
373
+ content: "页眉线";
374
+ left: calc(50% - 18px);
375
+ position: relative;
376
+ background: #ffff;
377
+ top: -14px;
378
+ color: purple;
379
+ font-size: 12px;
380
+ }
381
+
382
+ .hiprint-footerLine:hover:before {
383
+ content: "页脚线";
384
+ left: calc(50% - 18px);
385
+ position: relative;
386
+ color: purple;
387
+ background: #ffff;
388
+ top: -14px;
389
+ font-size: 12px;
390
+ }
391
+ </style>
392
+
393
+ <style>
394
+ /* 重写默认的一个样式 */
395
+ .rect-printElement-types .hiprint-printElement-type > li > ul > li > a {
396
+ color: #000 !important;
397
+ display: flex;
398
+ align-items: center;
399
+ justify-content: center;
400
+ }
401
+
402
+ /* 自定义 provider 构建样式 */
403
+ .custom-style-types .hiprint-printElement-type {
404
+ display: block;
405
+ }
406
+ .custom-style-types .hiprint-printElement-type {
407
+ padding: 0 0 0 0;
408
+ list-style: none;
409
+ }
410
+ .custom-style-types .hiprint-printElement-type > li > .title {
411
+ display: block;
412
+ padding: 4px 0px;
413
+ color: rgb(0, 58, 230);
414
+ clear: both;
415
+ }
416
+ .custom-style-types .hiprint-printElement-type > li > ul {
417
+ padding: 0 0 0 0;
418
+ display: block;
419
+ list-style: none;
420
+ }
421
+ .custom-style-types .hiprint-printElement-type > li > ul > li {
422
+ display: block;
423
+ width: 50%;
424
+ float: left;
425
+ max-width: 100px;
426
+ }
427
+ .custom-style-types .hiprint-printElement-type > li > ul > li > a {
428
+ padding: 12px 6px;
429
+ color: #1296db;
430
+ text-decoration: none;
431
+ background: #fff;
432
+ border: 1px solid #ddd;
433
+ margin-right: 5px;
434
+ width: 95%;
435
+ max-width: 100px;
436
+ display: inline-block;
437
+ text-align: center;
438
+ margin-bottom: 7px;
439
+ box-sizing: border-box;
440
+ border: 1px solid rgba(0, 0, 0, 0.2);
441
+ border-radius: 4px;
442
+ box-shadow: 0 1px 0 0 rgba(0, 0, 0, 0.15);
443
+ }
444
+ </style>
445
+ <style scoped>
446
+ /* api按钮 */
447
+ .api {
448
+ background: #00acc1;
449
+ }
450
+ .auto {
451
+ width: auto !important;
452
+ }
453
+ /* 纸张 */
454
+ .paper {
455
+ margin-right: 10px;
456
+ }
457
+ .paper button:not(class*="auto") {
458
+ width: 60px !important;
459
+ }
460
+ /* 多个 button 间距 */
461
+ .paper button + button {
462
+ margin-left: -1px;
463
+ }
464
+ .paper button:first-child:last-child {
465
+ border-radius: 4px;
466
+ }
467
+ /* 两边的 btn 圆角 */
468
+ .paper button:first-child:not(:last-child) {
469
+ border-top-left-radius: 4px;
470
+ border-bottom-left-radius: 4px;
471
+ }
472
+ .paper button:last-child:not(:first-child) {
473
+ border-top-right-radius: 4px;
474
+ border-bottom-right-radius: 4px;
475
+ }
476
+ .popover {
477
+ position: absolute;
478
+ margin-top: 10px;
479
+ z-index: 10;
480
+ }
481
+ .popover .popover-content {
482
+ background: white;
483
+ border-radius: 4px;
484
+ padding: 10px 14px;
485
+ box-shadow: 2px 2px 2px 4px rgb(128 0 128 / 20%);
486
+ }
487
+ .popover .input {
488
+ height: 24px;
489
+ padding: 2px 4px;
490
+ }
491
+ .popover .input:hover {
492
+ border-color: rgb(245, 155, 241);
493
+ border-radius: 4px;
494
+ }
495
+
496
+ /* 区域 */
497
+ .left {
498
+ background: white;
499
+ border-radius: 4px;
500
+ border: 1px solid #d9d9d9;
501
+ box-shadow: 2px 2px 2px 0px rgb(128 0 128 / 20%);
502
+ overflow: auto;
503
+ }
504
+ .left .container {
505
+ height: 100%;
506
+ overflow: auto;
507
+ padding: 0 10%;
508
+ background: rgba(92, 91, 92, 0.1);
509
+ }
510
+ .left .container[id*="provider-container2"] {
511
+ margin-bottom: 10px;
512
+ background: rgba(92, 91, 92, 0.1);
513
+ }
514
+ .center {
515
+ margin: 0 10px;
516
+ background: white;
517
+ border-radius: 4px;
518
+ border: 1px solid #d9d9d9;
519
+ padding: 20px;
520
+ box-shadow: 2px 2px 2px 0px rgb(128 0 128 / 20%);
521
+ overflow: auto;
522
+ }
523
+ .right {
524
+ background: white;
525
+ border-radius: 4px;
526
+ border: 1px solid #d9d9d9;
527
+ padding: 10px 0;
528
+ box-shadow: 2px 2px 2px 0px rgb(128 0 128 / 20%);
529
+ overflow: auto;
530
+ }
531
+ /* 左侧拖拽元素样式 */
532
+ .title {
533
+ font-size: 16px;
534
+ font-weight: 500;
535
+ margin: 4px 0 4px 10px;
536
+ }
537
+ .item {
538
+ display: flex;
539
+ flex-direction: column;
540
+ align-items: center;
541
+ background: white;
542
+ padding: 4px 10px;
543
+ margin: 10px 8px 4px 8px;
544
+ width: 38%;
545
+ min-height: 60px;
546
+ border-radius: 4px;
547
+ box-shadow: 2px 2px 2px 2px rgba(171, 171, 171, 0.2);
548
+ }
549
+ .item .iconfont {
550
+ font-size: 1.5rem;
551
+ }
552
+ .item span {
553
+ font-size: 14px;
554
+ }
555
+ </style>
556
+
557
+ <!-- 弹框样式 -->
558
+ <style scoped>
559
+ .print-dialog-overlay {
560
+ position: fixed;
561
+ top: 0;
562
+ left: 0;
563
+ right: 0;
564
+ bottom: 0;
565
+ background: rgba(0, 0, 0, 0.5);
566
+ display: flex;
567
+ align-items: center;
568
+ justify-content: center;
569
+ z-index: 2000;
570
+ }
571
+
572
+ .print-dialog {
573
+ background: #fff;
574
+ width: 95vw;
575
+ height: 95vh;
576
+ border-radius: 8px;
577
+ box-shadow: 0 2px 12px rgba(0, 0, 0, 0.15);
578
+ display: flex;
579
+ flex-direction: column;
580
+ }
581
+
582
+ .print-dialog-header {
583
+ display: flex;
584
+ justify-content: space-between;
585
+ align-items: center;
586
+ padding: 12px 20px;
587
+ border-bottom: 1px solid #e8e8e8;
588
+ font-size: 16px;
589
+ font-weight: 500;
590
+ }
591
+
592
+ .close-btn {
593
+ cursor: pointer;
594
+ font-size: 20px;
595
+ color: #000;
596
+ font-style: normal;
597
+ }
598
+
599
+ .close-btn:hover {
600
+ color: #606266;
601
+ }
602
+
603
+ .print-dialog-body {
604
+ flex: 1;
605
+ overflow: hidden;
606
+ padding: 10px;
607
+ display: flex;
608
+ flex-direction: column;
609
+ }
610
+ .print-dialog-body .main {
611
+ flex: 1;
612
+ overflow: hidden;
613
+ }
614
+ </style>
615
+
616
+ <style scoped>
617
+ .button-item {
618
+ height: 40px;
619
+ }
620
+ .header-box {
621
+ display: flex;
622
+ align-items: center;
623
+ justify-content: space-between;
624
+ }
625
+ </style>