1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
| <template>
| <div id="goods-template" class="print-hide">
| <div v-for="i in goods" :key="i.id" style="width: 370px; height: 200px">
| <div style="display: flex; justify-content: center">
| <qrcode-vue
| :size="120"
| :margin="0"
| :auto-color="true"
| :dot-scale="1"
| :text="i.assembleCode"
| />
| </div>
| <div
| style="
| line-height: 30px;
| display: flex;
| justify-content: center;
| margin-top: 10px;
| "
| >
| {{ i.assembleCode }}
| </div>
| <div style="line-height: 30px; display: flex; justify-content: center">
| {{ i.assembleName }}
| </div>
| </div>
| </div>
| </template>
|
| <script>
| import printJS from "print-js";
| import QrcodeVue from "vue-qr/src/packages/vue-qr.vue";
|
| export default {
| components: {
| QrcodeVue,
| },
| props: {
| goods: {
| type: Object,
| default: () => [],
| },
| },
| mounted() {
| console.log(this.goods);
|
| setTimeout(() => {
| this.handlePrint();
| }, 500);
| },
| beforeUnmount() {
| clearTimeout();
| },
| methods: {
| handlePrint() {
| // 获取打印模板的DOM元素
| const printElement = document.getElementById("goods-template");
| console.log(printElement);
| if (printElement) {
| // 显示打印模板,以便能够打印
| printElement.classList.remove("print-hide");
| // 使用vue-printjs打印模板内容
| printJS({
| printable: printElement,
| scanStyles: false,
| type: "html",
| error: (err) => {
| console.log("err", err);
| },
| });
| // 打印完成后隐藏打印模板
| printElement.classList.add("print-hide");
| //向父组件发送打印完成事件
| this.$emit("print-complete");
| }
| },
| },
| };
| </script>
| <style lang="less" scoped>
| .print-hide {
| display: block;
| /* 在屏幕上隐藏打印模板 */
| }
| </style>
|
|