57 lines
1.1 KiB
Vue
Raw Normal View History

2025-03-21 09:20:29 +08:00
<template>
2025-04-08 00:14:08 +08:00
<el-dialog :model-value="props.showes" width="70%">
<ceshi ref="ceshiRef"></ceshi>
<div class="btnList">
<el-button type="primary" @click="printElement">打印</el-button>
</div>
</el-dialog>
2025-03-21 09:20:29 +08:00
</template>
<script setup lang="ts">
2025-04-08 00:14:08 +08:00
import { defineProps, reactive, ref, nextTick } from 'vue';
import ceshi from './ceshi.vue';
import printJS from 'print-js';
const ceshiRef = ref(null);
2025-03-21 09:20:29 +08:00
const props = defineProps({
2025-04-08 00:14:08 +08:00
listData: {
type: Array,
default: () => [],
},
showes: {
type: Boolean,
default: true,
},
2025-03-21 09:20:29 +08:00
});
const state = reactive({
2025-04-08 00:14:08 +08:00
dialogVisible: true,
2025-03-21 09:20:29 +08:00
});
2025-04-08 00:14:08 +08:00
const printElement = () => {
// 获取 DOM 元素的 HTML
nextTick(() => {
console.log(ceshiRef.value.orderPrintingRef);
// // 使用 print-js 打印
printJS({
printable: ceshiRef.value.orderPrintingRef,
type: 'html', // 指定打印 HTML 内容
style: `
@page {
margin: 0;
size: auto;
}
@page :header, @page :footer {
display: none;
}
`,
});
});
};
2025-03-21 09:20:29 +08:00
</script>
<style scoped lang="scss">
2025-04-08 00:14:08 +08:00
.btnList {
margin-top: 26px;
display: flex;
justify-content: center;
2025-03-21 09:20:29 +08:00
}
2025-04-08 00:14:08 +08:00
</style>