Merge remote-tracking branch 'gitee/0.8.X' into 0.8.X
# Conflicts: # klp-ui/src/views/wms/coil/panels/LabelRender/ProductionTagPreview.vue
This commit is contained in:
@@ -4,13 +4,13 @@
|
||||
<!-- 调整第一行结构,左侧内容扩大,右侧二维码减小边距 -->
|
||||
<tr>
|
||||
<td colspan="2" style="padding: 0; width: 50%;">
|
||||
<div
|
||||
<div
|
||||
style="
|
||||
display: flex;
|
||||
display: flex;
|
||||
height: 100%;
|
||||
align-items: space-evenly;
|
||||
text-align: center;
|
||||
justify-content: space-evenly;
|
||||
align-items: space-evenly;
|
||||
text-align: center;
|
||||
justify-content: space-evenly;
|
||||
flex-direction: column;
|
||||
font-size: 13px;
|
||||
">
|
||||
@@ -137,11 +137,11 @@ export default {
|
||||
// 使用 matchMedia 监听打印状态(更可靠)
|
||||
this.printMediaQuery = window.matchMedia('print');
|
||||
this.printMediaQuery.addListener(this.handlePrintMediaChange);
|
||||
|
||||
|
||||
// 监听打印事件作为备用
|
||||
window.addEventListener('beforeprint', this.handleBeforePrint);
|
||||
window.addEventListener('afterprint', this.handleAfterPrint);
|
||||
|
||||
|
||||
// 计算初始缩放比例
|
||||
this.$nextTick(() => {
|
||||
this.calculatePrintScale();
|
||||
@@ -177,41 +177,41 @@ export default {
|
||||
this.$nextTick(() => {
|
||||
const container = this.$el;
|
||||
if (!container) return;
|
||||
|
||||
|
||||
// 纸张尺寸:180mm x 100mm
|
||||
const dpi = 96; // 标准 DPI
|
||||
const mmToPx = dpi / 25.4; // 1mm = 3.779527559px
|
||||
|
||||
|
||||
const paperWidthMm = this.paperWidthMm || 100;
|
||||
const paperHeightMm = this.paperHeightMm || 80;
|
||||
const marginMm = 2;
|
||||
|
||||
|
||||
const paperWidthPx = paperWidthMm * mmToPx;
|
||||
const paperHeightPx = paperHeightMm * mmToPx;
|
||||
const marginPx = marginMm * mmToPx;
|
||||
|
||||
|
||||
// 获取内容实际尺寸
|
||||
const rect = container.getBoundingClientRect();
|
||||
let contentWidth = rect.width;
|
||||
let contentHeight = rect.height;
|
||||
|
||||
|
||||
// 如果尺寸为0或无效,尝试使用 scrollWidth/scrollHeight
|
||||
if (contentWidth === 0 || contentHeight === 0) {
|
||||
contentWidth = container.scrollWidth || contentWidth;
|
||||
contentHeight = container.scrollHeight || contentHeight;
|
||||
}
|
||||
|
||||
|
||||
// 计算可用空间(减去边距)
|
||||
const availableWidth = paperWidthPx - marginPx * 2;
|
||||
const availableHeight = paperHeightPx - marginPx * 2;
|
||||
|
||||
|
||||
// 计算缩放比例
|
||||
const scaleX = contentWidth > 0 ? availableWidth / contentWidth : 1;
|
||||
const scaleY = contentHeight > 0 ? availableHeight / contentHeight : 1;
|
||||
|
||||
|
||||
// 取较小的缩放比例,确保内容完全适配(不超过1,不放大)
|
||||
this.printScale = Math.min(scaleX, scaleY, 1);
|
||||
|
||||
|
||||
// 设置CSS变量和内联样式
|
||||
container.style.setProperty('--print-scale', this.printScale);
|
||||
container.style.setProperty('--paper-width', `${paperWidthMm}mm`);
|
||||
@@ -320,15 +320,15 @@ export default {
|
||||
break-before: avoid !important;
|
||||
orphans: 999 !important;
|
||||
widows: 999 !important;
|
||||
|
||||
|
||||
/* 应用动态缩放,保持原有样式 */
|
||||
transform: scale(var(--print-scale, 1)) !important;
|
||||
transform-origin: top left !important;
|
||||
|
||||
|
||||
/* 确保缩放后不超出纸张 */
|
||||
max-width: var(--paper-width, 100mm) !important;
|
||||
max-height: var(--paper-height, 80mm) !important;
|
||||
overflow: hidden !important;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
</style>
|
||||
|
||||
Reference in New Issue
Block a user