index.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. <template>
  2. <div class="bgColor" v-if="modelValue" @click.stop="close">
  3. <div class="body">
  4. <div class="header">
  5. <div class="text">报告预览</div>
  6. <div class="delete">
  7. <el-button
  8. style="margin-right: 10px"
  9. type="primary"
  10. size="small"
  11. class="btn"
  12. v-print="'#print'"
  13. >打印</el-button
  14. >
  15. <span style="padding: 20px" @click="close">X</span>
  16. </div>
  17. </div>
  18. <div class="box">
  19. <el-scrollbar>
  20. <div id="print">
  21. <div class="tableInfo">
  22. <div class="title" style="text-align: center">质量日报</div>
  23. <div class="info">
  24. <div class="text">产品批次:</div>
  25. <div class="text">产品型号:</div>
  26. <div class="text">报告日期:2024年04月23日</div>
  27. </div>
  28. <table>
  29. <thead>
  30. <tr>
  31. <th>Name</th>
  32. <th>Age</th>
  33. <th>Country</th>
  34. <th>Country</th>
  35. <th>Country</th>
  36. </tr>
  37. </thead>
  38. <tbody>
  39. <tr v-for="item in 30">
  40. <td>John Doe</td>
  41. <td>30</td>
  42. <td>USA</td>
  43. <td>Canada</td>
  44. <td>Canada</td>
  45. </tr>
  46. <tr>
  47. <td>Jane Smith</td>
  48. <td>25</td>
  49. <td>Canada</td>
  50. <td>Canada</td>
  51. <td>Canada</td>
  52. </tr>
  53. <tr>
  54. <td>Maria Garcia</td>
  55. <td>35</td>
  56. <td>Spain</td>
  57. <td>Canada</td>
  58. <td>Canada</td>
  59. </tr>
  60. </tbody>
  61. </table>
  62. </div>
  63. </div>
  64. </el-scrollbar>
  65. </div>
  66. </div>
  67. </div>
  68. </template>
  69. <script setup>
  70. const props = defineProps({
  71. modelValue: {
  72. type: [Boolean],
  73. },
  74. });
  75. const emits = defineEmits(["update:modelValue"]);
  76. const close = () => {
  77. emits("update:modelValue", false);
  78. };
  79. // import html2canvas from "html2canvas";
  80. // const downloadPNG = async () => {
  81. // try {
  82. // const canvas = await html2canvas(document.getElementById("print"));
  83. // const imgData = canvas.toDataURL("image/png");
  84. // const downloadLink = document.createElement("a");
  85. // downloadLink.href = imgData;
  86. // downloadLink.download = "download.png";
  87. // downloadLink.click();
  88. // } catch (error) {
  89. // console.error("Error generating PNG:", error);
  90. // }
  91. // };
  92. </script>
  93. <style lang="scss" scoped>
  94. @media print {
  95. #print {
  96. position: absolute; /* 或 absolute, fixed, 根据需要调整 */
  97. top: 20px; /* 调整顶部位置 */
  98. margin: 0; /* 重置边距 */
  99. width: 700px;
  100. }
  101. }
  102. table {
  103. width: 100%;
  104. border-collapse: collapse; /* 合并表格边框 */
  105. }
  106. th,
  107. td {
  108. border: 1px solid rgba(0, 0, 0, 0.3); /* 设置所有单元格的边框 */
  109. padding: 8px;
  110. text-align: left;
  111. }
  112. th {
  113. background-color: #f2f2f2; /* 设置表头的背景颜色 */
  114. }
  115. .bgColor {
  116. position: fixed;
  117. width: 100vw;
  118. height: 100vh;
  119. z-index: 99999;
  120. background-color: rgba(0, 0, 0, 0.3);
  121. top: 0;
  122. display: flex;
  123. align-items: center;
  124. justify-content: center;
  125. left: 0;
  126. .body {
  127. width: 800px;
  128. height: 85vh;
  129. background-color: white;
  130. display: flex;
  131. flex-direction: column;
  132. padding: 20px;
  133. .header {
  134. width: 100%;
  135. height: 40px;
  136. display: flex;
  137. padding-bottom: 10px;
  138. justify-content: space-between;
  139. border-bottom: 1px solid rgba(0, 0, 0, 0.3);
  140. }
  141. .box {
  142. height: calc(100% - 40px);
  143. }
  144. }
  145. }
  146. .tableInfo {
  147. width: 100%;
  148. height: 60px;
  149. .title {
  150. margin: 10px 0;
  151. font-size: 20px;
  152. font-weight: 600;
  153. }
  154. .info {
  155. display: flex;
  156. padding: 0 20px;
  157. justify-content: space-between;
  158. }
  159. }
  160. </style>