pull/1/head
z 2024-01-11 14:40:34 +08:00
parent 5db9c3f30a
commit 20a8d64ea1
3 changed files with 13 additions and 13 deletions

View File

@ -1,11 +1,10 @@
import { ref } from "vue"; import { ref } from "vue";
export default function usePrint(THEAD_HEIGHT) { export default function usePrint() {
const buttonRef = ref(null); const buttonRef = ref(null);
const A4_HEIGHT_MM = 297; const A4_HEIGHT_MM = 297;
const A4_HEIGHT_MM_TO_PX_PROPORTION = 3.78; const A4_HEIGHT_MM_TO_PX_PROPORTION = 3.78;
let A4_HEIGHT_PX = let A4_HEIGHT_PX = A4_HEIGHT_MM * A4_HEIGHT_MM_TO_PX_PROPORTION;
A4_HEIGHT_MM * A4_HEIGHT_MM_TO_PX_PROPORTION - THEAD_HEIGHT;
let elements = []; let elements = [];
const printObj = { const printObj = {
id: "printContent", id: "printContent",
@ -16,9 +15,9 @@ export default function usePrint(THEAD_HEIGHT) {
const fnPrint = () => { const fnPrint = () => {
document.querySelector("#printContent").style.overflow = "visible"; document.querySelector("#printContent").style.overflow = "visible";
elements = document.querySelectorAll("#printContent > table > tr"); elements = document.querySelectorAll("#printContent > table > tr");
if (!document.querySelector("#printContent > table thead")) { const thead = document.querySelector("#printContent > table thead");
A4_HEIGHT_PX = A4_HEIGHT_PX + THEAD_HEIGHT; if (thead) A4_HEIGHT_PX = A4_HEIGHT_PX - thead.offsetHeight;
} else A4_HEIGHT_PX = A4_HEIGHT_PX + thead.offsetHeight;
fnIsPaging(); fnIsPaging();
buttonRef.value.$el.click(); buttonRef.value.$el.click();
}; };

View File

@ -1,5 +1,9 @@
<template> <template>
<el-dialog title="文档" :model-value="visible && model === 'dialog'"> <el-dialog
title="文档"
:model-value="visible && model === 'dialog'"
@update:model-value="visible = false"
>
<div v-if="visible && model === 'dialog'"> <div v-if="visible && model === 'dialog'">
<vue-pdf <vue-pdf
ref="pdfRef" ref="pdfRef"
@ -53,6 +57,7 @@ const pdfRef = ref(null);
const numOfPages = ref(0); const numOfPages = ref(0);
watchEffect(() => { watchEffect(() => {
if (props.visible) { if (props.visible) {
console.log(1111);
const loadingTask = createLoadingTask(VITE_FILE_URL + props.src); const loadingTask = createLoadingTask(VITE_FILE_URL + props.src);
loadingTask.promise loadingTask.promise
.then((pdf) => { .then((pdf) => {

View File

@ -28,17 +28,13 @@ import usePrint from "@/assets/js/usePrint.js";
defineOptions({ defineOptions({
name: "LayoutPrintTablePackage", name: "LayoutPrintTablePackage",
}); });
const props = defineProps({ defineProps({
theadHeight: {
type: Number,
default: 81.59,
},
entrance: { entrance: {
type: String, type: String,
default: "", default: "",
}, },
}); });
const { fnPrint, printObj, buttonRef } = usePrint(props.theadHeight); const { fnPrint, printObj, buttonRef } = usePrint();
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>