Files
print-tag-system/src/components/Main.vue
T
funjia b78d104728 fix: 虚线边框改为「纸上有东西才画」(原 Web 版 + 插件版都改)
用户口径:**没内容时不要打印虚线,有内容时要打印**。
原来只有「空格」满足这条,另有两种状态违反:

- 双击「隐藏(不打印)」的格子:纸上什么都没有,虚线照印;
- 模板选了但内容全空(最典型是 CustomTag 把所有行的文字都清空):
  纸上什么都没有,虚线照印 —— 在纸上看它和空格一模一样。

改成把规则统一成一句话:**边框 = 这一格纸上真的会印出东西**。

- 空格 / 双击隐藏:由格子状态直接判定(LabelCell 新增 blank-on-paper
  类,由页面算好传进来 —— 只有页面知道模板的内容规则);
- 模板内容全空:交给模板自己判。两块代码各自在模板注册表里声明
  `hasContent`(插件在 templates/registry.ts,原 Web 版在 Main.vue 的
  templates 数组里)。

为什么不能让模板「什么都不声明」靠通用扫描:CustomTag 的行是
`{ text, size, bold, color }`,通用扫描扫到 `color: '#000000'` 就认为有内容了,
于是文字全清空的标签仍被判定成有内容。所以 Error / CustomTag 显式声明
hasContent;未声明的模板退回通用兜底 —— 兜底刻意偏「宽松」:多印一个空框
看得见、好排查;把有内容的标签判成空的,用户会以为东西丢了。

另外规格类模板标记 `alwaysPrints`:它们带左侧固定信息区(店铺名 / 电话 /
内置二维码图片),那部分不来自 config,所以「字段被清空」的规格标签仍有内容、
边框必须留 —— 否则用户清空字段后会发现边框莫名其妙没了。

验证(Playwright + 本机 Edge,真实打印管线):
- 插件版 5 项边框断言 + 上一轮的 13 项打印断言,全过;
- 原 Web 版 5 项边框断言全过;
- 两版都生成 PDF 用浏览器 PDF 视图渲染确认纸面:只有真正有内容的格子
  留下边框与内容,隐藏格 / 内容全空格在纸上是空白。
- 插件产物已升版本发布为 funjia.print-tag@1.0.2。
2026-10-04 01:14:04 +08:00

801 lines
24 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<template>
<div class="layout">
<!-- 顶部操作栏 -->
<header class="topbar">
<div class="brand">
<span class="brand-icon">🏷️</span>
<div>
<div class="brand-title">标签打印</div>
<div class="brand-sub">4 × 11 标签排版</div>
</div>
</div>
<div class="toolbar">
<div class="tool-group">
<span class="tool-label">批量模板</span>
<Select :data="people" v-model="selectedPerson" />
</div>
<div class="tool-group">
<span class="tool-label">打印设置</span>
<div class="tool-inputs">
<Input type="number" title="数量" v-model="count" />
<Input type="number" title="上下边距" v-model="marginHeight" />
<Input type="number" title="左右边距" v-model="marginHorizontal" />
</div>
</div>
<div class="tool-buttons">
<button class="btn btn-primary" :disabled="usedCount >= TOTAL" @click="onAddBatch">批量添加</button>
<button class="btn btn-success" :disabled="usedCount === 0" @click="onPrint">打印</button>
<button class="btn btn-ghost" :disabled="usedCount === 0" @click="onRest">清空全部</button>
</div>
<div class="stats">
<span class="chip chip-filled">已填 {{ usedCount }}</span>
<span class="chip">剩余 {{ TOTAL - usedCount }}</span>
</div>
</div>
</header>
<!-- 主体:左侧编辑面板 + 右侧标签纸 -->
<div class="body">
<aside class="panel">
<!-- 批量填充 -->
<section class="card">
<h3><span>① 批量填充设置</span></h3>
<p class="hint">编辑好模板内容后点「保存模板配置」,再点上方「批量添加」依次填入空格。</p>
<DynamicForm :key="'batch-' + selectedPerson.label" :form-config="batchSchema"
:initial-data="batchConfig" submit-text="保存模板配置" @submit="onBatchConfig" />
</section>
<!-- 单格编辑 -->
<section v-if="selectedIndex >= 0" class="card card-cell">
<h3>
<span>② 编辑第 {{ selectedIndex + 1 }} 格</span>
<button class="btn btn-icon-only" title="关闭面板" @click="selectedIndex = -1">✕</button>
</h3>
<p v-if="!hasCellContent" class="hint">这是一个空格:选择模板 → 填内容 → 「填入该格」。</p>
<p v-else class="hint">当前为「{{ selectedSlot.name }}」模板<template v-if="selectedSlot.hidden">,已隐藏不打印</template>。</p>
<div class="cell-template">
<span class="tool-label">该格使用模板</span>
<Select :data="people" v-model="cellTemplate" />
</div>
<DynamicForm :key="cellFormKey" :form-config="cellSchema" :initial-data="cellInitial"
:submit-text="hasCellContent ? '保存到该格' : '填入该格'" @submit="saveCell" />
<div v-if="hasCellContent" class="cell-actions">
<button class="btn btn-ghost btn-sm" @click="toggleCellHidden">
{{ selectedSlot.hidden ? '恢复显示' : '隐藏(不打印)' }}
</button>
<button class="btn btn-danger btn-sm" @click="clearCell">删除该格</button>
</div>
</section>
<!-- 未选中时的提示 -->
<section v-else class="card card-tip">
<h3><span>逐格编辑</span></h3>
<ul class="tips">
<li>单击任意<span class="hl">格子</span> → 编辑这一格的内容</li>
<li>双击格子 → 隐藏 / 恢复内容(打印时留空)</li>
<li>上方「批量添加」可一次填满后续空格</li>
</ul>
</section>
</aside>
<!-- 标签纸 -->
<main class="sheet">
<div class="page">
<LabelCell v-for="(slot, i) in slots" :key="i" :index="i" :item="slot"
:selected="selectedIndex === i" :blank-on-paper="isBlankOnPaper(slot)"
@select="onCellSelect(i)" @toggle-hide="toggleHidden(i)">
<component :is="templateMap.get(slot.name)" v-if="slot.name" :config="slot.config" />
</LabelCell>
</div>
</main>
</div>
</div>
</template>
<script setup>
import { computed, onBeforeUnmount, onMounted, reactive, ref, watch } from "vue";
// 导入所有模板组件(default = 标签内容渲染组件,formSchema/initialValues = 表单配置)
import Error, { formSchema as formSchema_Error, initialValues as initialValues_Error } from './Error.vue';
import I5_10400F_16G_256G_1060, { formSchema as formSchema_I510400F, initialValues as initialValues_I510400F } from "./I5_10400F_16G_256G_1060.vue";
import I5_10400F_16G_512G_2060, { formSchema as formSchema_I510400F2060, initialValues as initialValues_I510400F2060 } from "./I5_10400F_16G_512G_2060.vue";
import I5_9400F_16G_256G_1060, { formSchema as formSchema_I59400F, initialValues as initialValues_I59400F } from "./I5_9400F_16G_256G_1060.vue";
import I5_4590_8G_120G, { formSchema as formSchema_I54590, initialValues as initialValues_I54590 } from './I5_4590_8G_120G.vue';
import I3_4130_8G_120G, { formSchema as formSchema_I34130, initialValues as initialValues_I34130 } from './I3_4130_8G_120G.vue';
import G3260_8G_120G, { formSchema as formSchema_G3260, initialValues as initialValues_G3260 } from './G3260_8G_120G.vue';
import All_in_one_22_4G_120G, { formSchema as formSchema_22AllInOne, initialValues as initialValues_22AllInOne } from "./22寸一体机_4G_120G.vue";
import All_in_one_24_8G_256G, { formSchema as formSchema_24AllInOne, initialValues as initialValues_24AllInOne } from "./24寸一体机_I5_3代_8G_256G.vue";
import HardDisk, { formSchema as formSchema_HardDisk, initialValues as initialValues_HardDisk } from "./HardDisk.vue";
import CustomTag, { formSchema as formSchema_CustomTag, initialValues as initialValues_CustomTag } from "./CustomTag.vue";
import DynamicForm from './DynamicForm.vue';
import Input from './Input/Index.vue';
import Select from './Select/index.vue';
import LabelCell from './LabelCell.vue';
// 深拷贝:避免编辑表单 / 快照进格子时共享引用
const clone = (obj) => JSON.parse(JSON.stringify(obj));
// 模板注册表:新增模板只需在数组中加一项
//
// `alwaysPrints` / `hasContent` 只服务一件事:**决定打印时给不给格子画虚线边框**
// (规则见下面 isBlankOnPaper 的注释)。新增模板时建议一并写清楚,漏写会走通用兜底。
const templates = [
{
label: 'I5_10400F_16G_256G_1060',
component: I5_10400F_16G_256G_1060,
formSchema: formSchema_I510400F,
formData: initialValues_I510400F,
// 带左侧固定信息区(店铺名 / 电话 / 二维码),字段全空也仍有墨
alwaysPrints: true
},
{
label: 'I5_10400F_16G_256G_2060',
component: I5_10400F_16G_512G_2060,
formSchema: formSchema_I510400F2060,
formData: initialValues_I510400F2060,
alwaysPrints: true
},
{
label: 'I5_9400F_16G_256G_1060',
component: I5_9400F_16G_256G_1060,
formSchema: formSchema_I59400F,
formData: initialValues_I59400F,
alwaysPrints: true
},
{
label: 'I5_4590_8G_120G',
component: I5_4590_8G_120G,
formSchema: formSchema_I54590,
formData: initialValues_I54590,
alwaysPrints: true
},
{
label: 'I3_4130_8G_120G',
component: I3_4130_8G_120G,
formSchema: formSchema_I34130,
formData: initialValues_I34130,
alwaysPrints: true
},
{
label: 'G3260_8G_120G',
component: G3260_8G_120G,
formSchema: formSchema_G3260,
formData: initialValues_G3260,
alwaysPrints: true
},
{
label: '24寸一体机_I5_3代_8G_256G',
component: All_in_one_24_8G_256G,
formSchema: formSchema_24AllInOne,
formData: initialValues_24AllInOne,
alwaysPrints: true
},
{
label: '22寸一体机_4G_120G',
component: All_in_one_22_4G_120G,
formSchema: formSchema_22AllInOne,
formData: initialValues_22AllInOne,
alwaysPrints: true
},
{
label: 'HardDisk',
component: HardDisk,
formSchema: formSchema_HardDisk,
formData: initialValues_HardDisk,
alwaysPrints: true
},
{
label: 'Error',
component: Error,
formSchema: formSchema_Error,
formData: initialValues_Error,
// 只显示标题 / 说明 / 时间,三个都空就是纸上没东西
hasContent: (c) => [c?.title, c?.reason, c?.time].some((v) => String(v ?? '').trim() !== '')
},
{
label: 'CustomTag',
component: CustomTag,
formSchema: formSchema_CustomTag,
formData: initialValues_CustomTag,
// 只有「文字非空的那些行」会显示,颜色 / 字号不算内容
hasContent: (c) => (c?.lines || []).some((line) => String(line?.text ?? '').trim() !== '')
}
];
// 下拉数据与名称 → 渲染组件映射
const people = reactive(
templates.map(({ label, formSchema, formData }) => ({ label, formSchema, formData }))
);
const templateMap = new Map(templates.map(({ label, component }) => [label, component]));
const templateByLabel = new Map(templates.map((t) => [t.label, t]));
/**
* 通用兜底:扫一遍 config,只要有**非空白的字符串**就认为有内容,数组逐项下钻。
*
* 只在模板没声明 `hasContent` 时用。它偏宽松 —— 像 CustomTag 的 `color: '#000000'`
* 会被算成内容,所以有意义的模板请自己声明 `hasContent`。
* 偏向「宽松」是故意的:多印一个空框看得见、好排查;把有内容的标签判成空的,
* 用户会以为东西丢了。
*/
const hasVisibleContent = (value) => {
if (typeof value === 'string') return value.trim() !== '';
if (Array.isArray(value)) return value.some(hasVisibleContent);
if (value && typeof value === 'object') return Object.values(value).some(hasVisibleContent);
return false; // 数字 / 布尔不需要「填」,否则 size: 4 会被误判
};
/**
* 这一格**打印出来纸上会不会有东西**。
*
* 用途只有一个:决定要不要画那圈虚线边框。规则一句话 ——
* **边框代表「这一格纸上有东西」**,所以纸上什么都没有的格子不该有边框:
*
* | 情况 | 纸上 | 边框 |
* | --- | --- | --- |
* | 空格(没选模板) | 无 | 不画 |
* | 双击隐藏 | 无 | 不画 |
* | 模板选了但内容全空(如自定义文字所有行都空) | 无 | 不画 |
* | 有内容 | 有 | 画 |
*
* 前两种按状态就能判(name / hidden),第三种要看模板:规格类模板**即使字段全空,
* 左侧固定信息区(店铺名 / 电话 / 内置二维码)照印**,所以直接短路成「有内容」——
* 否则用户把字段清空后会发现边框莫名其妙没了。
*/
const isBlankOnPaper = (slot) => {
if (!slot?.name) return true; // 空格
if (slot.hidden) return true; // 双击隐藏:内容不打印,纸上看和空格一样
const tpl = templateByLabel.get(slot.name);
if (tpl?.alwaysPrints) return false;
const hasContent = tpl?.hasContent || hasVisibleContent;
return !hasContent(slot.config || {});
};
// ---------- 固定 44 个格子(每格可单独编辑) ----------
const TOTAL = 44;
const emptySlot = () => ({ name: null, config: null, hidden: false });
const slots = ref(Array.from({ length: TOTAL }, emptySlot));
const usedCount = computed(() => slots.value.filter((s) => s.name).length);
// 当前选中的格子(-1 = 未选中)
const selectedIndex = ref(-1);
const selectedSlot = computed(() =>
selectedIndex.value >= 0 ? slots.value[selectedIndex.value] : null
);
const hasCellContent = computed(() => !!selectedSlot.value?.name);
// ---------- 批量填充(沿用原有语义) ----------
const selectedPerson = ref(people[0]);
const batchSchema = ref(people[0].formSchema);
const batchConfig = ref(clone(people[0].formData));
watch(selectedPerson, (nv) => {
batchSchema.value = nv.formSchema;
batchConfig.value = clone(nv.formData);
}, { immediate: true });
// 打印数量 / 边距
const count = ref(1);
const marginHeight = ref(0.89);
const marginHorizontal = ref(0.8);
let printStyle = null;
// ---------- 单格编辑 ----------
const cellTemplate = ref(people[0]); // 该格当前使用的模板
const cellRev = ref(0); // 保存后递增,用于刷新表单
const cellSchema = computed(() => cellTemplate.value?.formSchema || people[0].formSchema);
const cellInitial = computed(() => {
const slot = selectedSlot.value;
const tpl = cellTemplate.value;
if (!tpl) return {};
// 已有内容且模板未变 → 回填该格当前配置;否则显示该模板默认值
if (slot?.name && slot.name === tpl.label) return clone(slot.config ?? tpl.formData);
return clone(tpl.formData);
});
const cellFormKey = computed(() =>
`${selectedIndex.value}|${cellTemplate.value?.label || ''}|${cellRev.value}`
);
// 单击选择格子;再次单击取消选择
const onCellSelect = (i) => {
if (selectedIndex.value === i) {
selectedIndex.value = -1;
return;
}
selectedIndex.value = i;
const slot = slots.value[i];
// 有内容的格子:自动把“该格模板”切到它的模板,方便直接修改
if (slot?.name) {
const tpl = people.find((p) => p.label === slot.name);
if (tpl) cellTemplate.value = tpl;
}
};
// 双击:隐藏/恢复该格内容(打印时留空,保留格子边框)
const toggleHidden = (i) => {
const slot = slots.value[i];
if (!slot?.name) return;
slot.hidden = !slot.hidden;
};
// 单格表单提交:填入(空格)或保存(有内容)
const saveCell = (cfg) => {
const i = selectedIndex.value;
if (i < 0) return;
const tpl = cellTemplate.value;
slots.value[i] = {
name: tpl.label,
config: clone(cfg),
hidden: slots.value[i]?.hidden || false
};
cellRev.value++;
};
const clearCell = () => {
const i = selectedIndex.value;
if (i < 0) return;
slots.value[i] = emptySlot();
cellRev.value++;
};
const toggleCellHidden = () => {
const slot = selectedSlot.value;
if (slot) slot.hidden = !slot.hidden;
};
// ---------- 批量操作 ----------
const onBatchConfig = (cfg) => {
batchConfig.value = clone(cfg);
};
const onAddBatch = () => {
const n = Math.min(parseInt(count.value, 10) || 1, TOTAL - usedCount.value);
if (n <= 0) return;
const tpl = selectedPerson.value;
let placed = 0;
slots.value = slots.value.map((s) => {
if (placed < n && !s.name) {
placed++;
return { name: tpl.label, config: clone(batchConfig.value), hidden: false };
}
return s;
});
};
const onRest = () => {
slots.value = Array.from({ length: TOTAL }, emptySlot);
selectedIndex.value = -1;
};
// ---------- 打印 ----------
const onPrint = () => {
applyPrintStyles();
if (window?.electronAPI?.silentPrint) {
window.electronAPI.silentPrint();
} else {
window.print();
}
};
const removePrintStyles = () => {
// 用 `node.remove()` 而不是 `document.head.removeChild(node)`:节点可能已经
// 不在 head 里了(上一次撤过、或宿主清过 DOM),对已脱离的节点调 removeChild
// 会抛 NotFoundError,把整段注入打断在半路 —— 症状是「这次打印什么都没生效」。
// remove() 对已脱离节点是安全的 no-op。
if (printStyle) {
printStyle.remove();
printStyle = null;
}
};
/**
* 打印样式**临时注入、打完就撤**。
*
* ## 为什么 `@page` 的边距是 0
*
* 浏览器会在**页边距那块空白**里画它自己的页眉页脚(左上角日期时间 + 页面标题,
* 底部 URL + 页码)。CSS 里没有「关掉页眉」的开关,把边距设成 0、让那块空白
* 消失,是 Chromium / Edge 上唯一可靠的做法。
*
* 代价是标签纸在纸上的位置不能再靠 `@page margin` 给,改由 `.page` 的
* `left` / `top` 控制 —— 顶栏那两个「上下边距 / 左右边距」的含义变成
* 「标签纸离纸边的距离」,物理结果与之前完全一致。
*
* > 注意:Firefox 的页眉页脚是打印对话框里的独立选项,CSS 控制不了,
* > 需要在打印设置里手动取消勾选。
*/
const applyPrintStyles = () => {
removePrintStyles();
// 负数会让标签跑到纸外,按 0 处理
const offsetX = Math.max(0, Number(marginHorizontal.value) || 0);
const offsetY = Math.max(0, Number(marginHeight.value) || 0);
printStyle = document.createElement('style');
printStyle.setAttribute('media', 'print');
printStyle.textContent = `
/* 边距清零:浏览器就不会在边距里画「日期时间 / 标题 / URL / 页码」 */
@page { margin: 0; }
@media print {
body { margin: 0 !important; padding: 0 !important; }
/* 标签纸钉在「离纸边的偏移」处(边距已经是 0,位置只能自己给) */
.page {
position: absolute;
left: ${offsetX}cm;
top: ${offsetY}cm;
width: 194mm;
}
}
`;
document.head.appendChild(printStyle);
};
// Ctrl+P 不经过 onPrint(),没有这条监听就打不出「只要标签纸」的效果
onMounted(() => {
window.addEventListener('beforeprint', applyPrintStyles);
window.addEventListener('afterprint', removePrintStyles);
});
onBeforeUnmount(() => {
window.removeEventListener('beforeprint', applyPrintStyles);
window.removeEventListener('afterprint', removePrintStyles);
removePrintStyles();
});
</script>
<style>
/* ================= 全局页面布局 ================= */
html,
body {
margin: 0;
padding: 0;
}
body {
font-family: "PingFang SC", "Microsoft YaHei", "Segoe UI", system-ui, sans-serif;
background: #e9eef5;
color: #1e293b;
}
.layout {
display: flex;
flex-direction: column;
gap: 14px;
padding: 16px;
min-height: 100vh;
box-sizing: border-box;
}
/* ---------------- 顶部操作栏 ---------------- */
.topbar {
display: flex;
align-items: center;
gap: 22px;
flex-wrap: wrap;
background: #ffffff;
border-radius: 14px;
padding: 14px 18px;
box-shadow: 0 2px 10px rgba(15, 23, 42, 0.07);
}
.brand {
display: flex;
align-items: center;
gap: 10px;
}
.brand-icon {
font-size: 26px;
line-height: 1;
}
.brand-title {
font-size: 17px;
font-weight: 700;
line-height: 1.2;
}
.brand-sub {
font-size: 12px;
color: #94a3b8;
}
.toolbar {
display: flex;
align-items: flex-end;
gap: 18px;
flex-wrap: wrap;
flex: 1;
min-width: 0;
}
.tool-group {
display: flex;
flex-direction: column;
gap: 6px;
}
.tool-label {
font-size: 12px;
font-weight: 600;
color: #64748b;
}
.tool-inputs {
display: flex;
gap: 10px;
}
.tool-buttons {
display: flex;
gap: 10px;
align-items: flex-end;
}
/* 顶栏与面板内的输入框更紧凑 */
.topbar .input-group,
.panel .input-group {
margin-bottom: 0;
width: 150px;
}
.topbar .input-group input,
.panel .input-group input {
width: 118px;
padding: 8px 12px;
}
.topbar .input-group i {
display: none;
}
.topbar .input-group .floating-label,
.panel .input-group .floating-label {
left: 12px;
}
.stats {
display: flex;
gap: 8px;
margin-left: auto;
align-items: center;
}
.chip {
background: #f1f5f9;
color: #475569;
font-size: 12.5px;
font-weight: 600;
padding: 5px 12px;
border-radius: 999px;
white-space: nowrap;
}
.chip-filled {
background: #dbeafe;
color: #1d4ed8;
}
/* ---------------- 主体:左面板 + 右纸面 ---------------- */
.body {
display: flex;
gap: 16px;
align-items: flex-start;
flex-wrap: wrap;
}
.panel {
width: 356px;
flex: none;
display: flex;
flex-direction: column;
gap: 14px;
position: sticky;
top: 12px;
max-height: calc(100vh - 24px);
overflow-y: auto;
}
.card {
background: #fff;
border-radius: 14px;
padding: 16px 18px;
box-shadow: 0 2px 10px rgba(15, 23, 42, 0.06);
}
.card h3 {
display: flex;
justify-content: space-between;
align-items: center;
margin: 0 0 8px;
font-size: 15px;
}
.hint {
margin: 0 0 12px;
font-size: 12.5px;
color: #94a3b8;
line-height: 1.6;
}
.tips {
margin: 6px 0 0;
padding-left: 18px;
font-size: 13px;
line-height: 2;
color: #475569;
}
.tips .hl {
color: #2563eb;
font-weight: 700;
}
.cell-template {
margin-bottom: 6px;
}
.cell-actions {
display: flex;
gap: 10px;
margin-top: 12px;
flex-wrap: wrap;
}
/* ---------------- 按钮 ---------------- */
.btn {
display: inline-block;
padding: 8px 16px;
border: none;
border-radius: 9px;
font-size: 13.5px;
font-weight: 600;
cursor: pointer;
transition: all 0.2s ease;
line-height: 1.3;
}
.btn:disabled {
opacity: 0.45;
cursor: not-allowed;
transform: none !important;
}
.btn-primary {
background: #2563eb;
color: #fff;
}
.btn-primary:hover:not(:disabled) {
background: #1d4ed8;
box-shadow: 0 4px 12px rgba(37, 99, 235, 0.35);
}
.btn-success {
background: #16a34a;
color: #fff;
}
.btn-success:hover:not(:disabled) {
background: #15803d;
box-shadow: 0 4px 12px rgba(22, 163, 74, 0.3);
}
.btn-ghost {
background: #f1f5f9;
color: #334155;
}
.btn-ghost:hover:not(:disabled) {
background: #e2e8f0;
}
.btn-danger {
background: #fee2e2;
color: #b91c1c;
}
.btn-danger:hover:not(:disabled) {
background: #fecaca;
}
.btn-sm {
padding: 5px 11px;
font-size: 12.5px;
}
.btn-icon-only {
padding: 2px 8px;
background: #f1f5f9;
color: #64748b;
border-radius: 7px;
font-size: 13px;
}
.btn-icon-only:hover {
background: #e2e8f0;
color: #0f172a;
}
/* ---------------- 标签纸(屏幕预览) ---------------- */
.sheet {
flex: 1;
min-width: 0;
display: flex;
justify-content: center;
padding: 8px;
box-sizing: border-box;
}
.page {
width: 194mm;
display: grid;
grid-template-columns: repeat(4, 48.5mm);
grid-template-rows: repeat(11, 25.4mm);
gap: 0;
background: #fff;
border-radius: 3mm;
box-shadow: 0 8px 26px rgba(15, 23, 42, 0.16);
overflow: hidden;
}
/* ================= 打印 ================= */
@media print {
html,
body {
padding: 0 !important;
margin: 0 !important;
background: #fff !important;
}
body * {
visibility: hidden;
}
.layout,
.body,
.sheet {
display: block;
padding: 0;
margin: 0;
background: transparent;
}
.topbar,
.panel {
display: none !important;
}
.page,
.page * {
visibility: visible;
}
.page {
width: 194mm;
height: auto;
border-radius: 0;
box-shadow: none;
overflow: visible;
}
}
@page {
/* 刻意留 0:边距一旦非 0,浏览器就会在边距里画自己的页眉页脚
(日期时间 / 标题 / URL / 页码)。标签纸在纸上的位置由
applyPrintStyles() 注入的 .page { left / top } 控制,见那个函数的注释。 */
margin: 0;
}
</style>