feat(分拣标签): 弹窗增加「旋转」开关(0/90/180/270)
CI / server typecheck + tests (push) Canceled after 0s
CI / web typecheck + tests + miniprogram syntax (push) Canceled after 0s
CI / eslint (观察项,C7 骨架) (push) Canceled after 0s
CI / npm audit (critical 硬拦) (push) Canceled after 0s

现象:预览页是 80×30 横版、内容位置也对,实物却转了 90° ⇒ 旋转
发生在打印机驱动/纸型层,网页直接控制不了。给一个旋转开关反向抵消:

- 0°(默认):与改动前逐字一致(自然平铺);
- 90°/270°:@page 尺寸转置 + 标签块整体 rotate(±90deg)、一页一签;
- 180°:尺寸不变、标签块翻转;
- 非法值回落 0°;角度与纸张宽/高一起存 localStorage。

尺寸仍可配(预设 + 自定义),覆盖「各人标签高宽不同」。
This commit is contained in:
雨天
2026-10-14 10:53:56 +08:00
parent c05aacb898
commit def05c6679
8 changed files with 168 additions and 32 deletions
@@ -31,6 +31,25 @@ GP-3120 列表中的 `80×30`);选中即把宽/高写入内部值(仍可
| 手填框 | 仅在「自定义」时显示;宽/高仍是真正的存储值 |
| 打印代码 | **零改动**(`pickingLabelPrint` 未动;本改动只是让「宽/高」更容易填对) |
## 2.1 「旋转」开关(2026-10-14 追加,开发者:预览是横的、实物却竖着)
**现象**:预览页面是 80×30 横版且内容位置正确,**实物却转了 90°**。⇒ 旋转发生在**打印机驱动/纸型层**,
网页无法直接控制驱动的方向。
**处置**:在弹窗加一个**「旋转」下拉:0°(默认)/ 90° / 180° / 270°**,用于**反向抵消**驱动自身的旋转。
| 旋转 | `@page` | 标签块 | 结构 |
|---|---|---|---|
| 0°(默认) | `W H` | `W × (H-0.5)` 相对定位 | 多张**自然平铺**(与改动前逐字一致) |
| 90° / 270° | **`H W`(转置)** | `W × (H-0.5)` 绝对定位 + `rotate(±90deg)` | 一页一签(`.pick-page` 页面框 + `break-after`) |
| 180° | `W H` | 同上 + `rotate(180deg)` | 一页一签 |
口径:非法值回落 0°(保持现状);旋转角度与纸张宽/高一起存 `localStorage`。因为旋转 90/270 时
页面尺寸会转置,每签必须独占一页(否则流程盒与页宽对不上)。
> 根因在驱动:最彻底的做法是在**打印对话框选驱动自带的纸型**(如 `80mm * 30mm`)而非 Custom。
> 本开关是**页面侧能做的唯一补偿**,同时适配“各人纸型不同”的场景。
**新增文案**(2 条,三语同步):`picking.modal.paperPreset`(纸张尺寸)、`picking.modal.paperCustom`(自定义)。
## 3. 验收标准(可执行)
@@ -39,15 +58,18 @@ GP-3120 列表中的 `80×30`);选中即把宽/高写入内部值(仍可
2. 下拉选「自定义」⇒ 展开「纸张宽/高」手填框,可填任意 mm。
3. 存储值不在预设内(老数据)⇒ 下拉显示「自定义」、宽/高框展开。
4. 打印 HTML 的 `@page` 与 `.pick-label` 宽高跟所填值一致(既有单测已覆盖)。
5. 真机:选 `80 × 30`(与实物签一致)⇒ 一签一页、不夹空白。
6. 回归:`pickingLabelPrint` 既有单测全绿;`typecheck` 过;i18n 三语齐全。
5. **旋转 0°**:不包页面框、无 `transform`(与改动前逐字一致);**旋转 90°/270°**:`@page` 转置且标签块 `rotate(±90deg)`、一页一签;**180°**:尺寸不变、`rotate(180deg)`;非法值回落 0°。
6. 真机:选与驱动一致的尺寸 + 能对上的旋转角 ⇒ 一签一页、方向正、不夹空白。
7. 回归:`pickingLabelPrint` 单测全绿;`typecheck` 过;i18n 三语齐全。
## 4. 变更清单
| 文件 | 类型 | 意图 |
|---|---|---|
| `src/pages/picking/PickingManagement.tsx` | 改 | 弹窗加「纸张尺寸」预设下拉(含常量表与联动) |
| `src/i18n/locales/{zh-CN,en,id}/picking.ts` | 改 | 新增 `modal.paperPreset` / `modal.paperCustom` |
| `src/pages/picking/PickingManagement.tsx` | 改 | 弹窗加「纸张尺寸」预设下拉 + 「旋转」下拉(含常量表、显隐与联动) |
| `src/utils/pickingLabelPrint.ts` | 改 | `buildPickingLabelHtml` 支持 `rotation`(转置 `@page` + 块旋转 + 旋转模式下一页一签) |
| `src/i18n/locales/{zh-CN,en,id}/picking.ts` | 改 | 新增 `modal.paperPreset` / `modal.paperCustom` / `modal.rotation` |
| `src/utils/pickingLabelPrint.test.ts` | 改 | 补旋转 0/90/180/270 与非法值用例 |
| `docs/design/20261014-分拣标签纸张尺寸预设选择.md` | 新增 | 本文 |
## 5. 回滚
+1 -1
View File
@@ -74,7 +74,7 @@ AI 提示词清理已停用条目(7 条归档不删、清单过滤 archived、
分拣**列表多选批量打印标签**(表头全选 + 行内多选;选中后弹**居中弹窗**:选**按区域/按商品/按订单/按分类**排队并**逐条勾选**要打的行,确认后才弹系统打印;**一签一页**,标签不得设百分比高——否则每张耗两页;复用既有文案不新增 key;仅给商品行 SELECT 补一列 `category_name`,无迁移)见 [20261013-分拣列表批量打印标签.md](./20261013-分拣列表批量打印标签.md)。
「独立进货」从「不落 customers 的哨兵」改为**系统默认客户行**(方案甲,2026-10-14 开发者裁决):迁移 `20261044` 在每个租户 `customers` 幂等建 1 行(编码 `__INDEPENDENT_INBOUND__` / 名字「独立进货」/ `status=10`)+ `clone_tenant_schema()` 末尾为新租户补插 ⇒ 客户列表/订单筛选/客户结算下拉/录单下拉自动可见且只一条;**客户结算金额恒为 0**(既有 skipped 短路不动);哨兵豁免与销售口径排除**全部保留** 见 [20261014-独立进货建客户档案(方案甲).md](./20261014-独立进货建客户档案(方案甲).md)。
新建分类**同名同父复用已有**(订单录入/订单详情/分类管理/供应商品类/批量导入共用的前端唯一出口 `insertCatalogCategory` 补查重;口径 = 同分公司 + 同父级 + `TRIM(name)` 精确相等,与后端 service 一致;此前裸插入 ⇒ 同名不同 code 可重复创建);DB 唯一约束(方案 3)待生产重复清点后再定 见 [20261014-分类新建去重(同名复用已有).md](./20261014-分类新建去重(同名复用已有).md)。
分拣标签打印弹窗增加**「纸张尺寸」预设选择**(对齐打印机驱动纸型列表的常见标签值,含 `80×30`;选中即写入宽/高手填框、仍可自定义;打印代码零改动)—— 页高必须等于实物单张标签高,手填 mm 极易填错(现场实测填成 80×60 而实物是 80×30 ⇒ 一页占 2 张签、每签后夹一张空白)见 [20261014-分拣标签纸张尺寸预设选择.md](./20261014-分拣标签纸张尺寸预设选择.md)。
分拣标签打印弹窗增加**「纸张尺寸」预设选择**(对齐打印机驱动纸型列表的常见标签值,含 `80×30`;选预设时收起宽/高手填框、选「自定义」才展开;打印代码零改动)—— 页高必须等于实物单张标签高,手填 mm 极易填错(现场实测填成 80×60 而实物是 80×30 ⇒ 一页占 2 张签、每签后夹一张空白);另加**「旋转」开关(0/90/180/270)**:预览是横的、实物却竖着(旋转发生在驱动层),靠它反向抵消 见 [20261014-分拣标签纸张尺寸预设选择.md](./20261014-分拣标签纸张尺寸预设选择.md)。
## 全量对齐与改造方案(2026-09-28)
+1
View File
@@ -183,6 +183,7 @@ export const picking: MessageDict = {
'modal.paperHeight': 'Paper height (mm)',
'modal.paperPreset': 'Paper size',
'modal.paperCustom': 'Custom',
'modal.rotation': 'Rotation',
'modal.reprintTitle': 'Force another copy after printed or failed; rows still pending print are skipped',
'modal.reprint': 'Reprint',
'modal.printHint':
+1
View File
@@ -183,6 +183,7 @@ export const picking: MessageDict = {
'modal.paperHeight': 'Tinggi kertas (mm)',
'modal.paperPreset': 'Ukuran kertas',
'modal.paperCustom': 'Kustom',
'modal.rotation': 'Rotasi',
'modal.reprintTitle': 'Paksa cetak lagi setelah sudah dicetak/gagal; baris masih menunggu cetak tetap dilewati',
'modal.reprint': 'Cetak ulang',
'modal.printHint':
+1
View File
@@ -177,6 +177,7 @@ export const picking: MessageDict = {
'modal.paperHeight': '纸张高(mm)',
'modal.paperPreset': '纸张尺寸',
'modal.paperCustom': '自定义',
'modal.rotation': '旋转',
'modal.reprintTitle': '已打印或失败后可强制再下一份;待打印中的行仍会跳过',
'modal.reprint': '补打',
'modal.printHint': '免过秤可勾选打印(只记该行实拣,不自动分拣完成)。已完成单请到「历史拣货单」补打。',
+32 -7
View File
@@ -140,19 +140,23 @@ const LABEL_PAPER_PRESETS: Array<{ w: number; h: number }> = [
const labelPaperKey = (w: unknown, h: unknown) => `${Number(w) || 0}x${Number(h) || 0}`;
function loadLabelPaper(): { width: string; height: string } {
function loadLabelPaper(): { width: string; height: string; rotation: string } {
try {
const raw = localStorage.getItem(LABEL_PAPER_STORAGE_KEY);
if (raw) {
const parsed = JSON.parse(raw) as { widthMm?: number; heightMm?: number };
const parsed = JSON.parse(raw) as { widthMm?: number; heightMm?: number; rotationDeg?: number };
if (parsed?.widthMm && parsed?.heightMm) {
return { width: String(parsed.widthMm), height: String(parsed.heightMm) };
return {
width: String(parsed.widthMm),
height: String(parsed.heightMm),
rotation: String(parsed.rotationDeg || 0),
};
}
}
} catch {
/* ignore */
}
return { width: '50', height: '30' };
return { width: '50', height: '30', rotation: '0' };
}
/**
@@ -1779,13 +1783,17 @@ function assigneeLabel(user: PickingAssignee, roleLabel: (code: string) => strin
setLabelPrintChecked(Object.fromEntries(labelPrintOrdered.map((item) => [item.id, checked])));
};
const patchLabelPaper = (patch: Partial<{ width: string; height: string }>) => {
const patchLabelPaper = (patch: Partial<{ width: string; height: string; rotation: string }>) => {
setLabelPaper((prev) => {
const next = { ...prev, ...patch };
try {
localStorage.setItem(
LABEL_PAPER_STORAGE_KEY,
JSON.stringify({ widthMm: Number(next.width) || 0, heightMm: Number(next.height) || 0 })
JSON.stringify({
widthMm: Number(next.width) || 0,
heightMm: Number(next.height) || 0,
rotationDeg: Number(next.rotation) || 0,
})
);
} catch {
/* ignore */
@@ -1822,7 +1830,10 @@ function assigneeLabel(user: PickingAssignee, roleLabel: (code: string) => strin
barcode: item.label_barcode || item.barcode || item.sku_code || '',
};
}),
{ paper: { widthMm: Number(labelPaper.width), heightMm: Number(labelPaper.height) } }
{
paper: { widthMm: Number(labelPaper.width), heightMm: Number(labelPaper.height) },
rotation: Number(labelPaper.rotation) || 0,
}
);
setLabelPrintModalOpen(false);
} catch (error: unknown) {
@@ -2794,6 +2805,20 @@ function assigneeLabel(user: PickingAssignee, roleLabel: (code: string) => strin
<option value="custom">{t('picking.modal.paperCustom')}</option>
</select>
</label>
<label className="flex items-center gap-1 text-sm text-gray-600">
{t('picking.modal.rotation')}
<select
value={labelPaper.rotation}
onChange={(e) => patchLabelPaper({ rotation: e.target.value })}
className="app-input app-focus-ring px-2 py-1.5 border rounded-md text-sm"
>
{['0', '90', '180', '270'].map((deg) => (
<option key={deg} value={deg}>
{deg}°
</option>
))}
</select>
</label>
{showLabelPaperInputs ? (
<>
<label className="flex items-center gap-1 text-sm text-gray-600">
+42
View File
@@ -100,6 +100,48 @@ describe('buildPickingLabelHtml(分拣标签 · 浏览器打印)', () => {
expect((html.match(/class="pick-label"/g) || []).length).toBe(2);
});
it('旋转 0°(默认):不包页面框、无 transform(保持自然平铺)', () => {
const html = buildPickingLabelHtml([{ itemName: 'a', qty: 1, unit: '斤' }]);
expect(html).not.toContain('class="pick-page"');
expect(html).not.toContain('rotate(');
});
it('旋转 90°/270°:页面尺寸转置 + 标签块旋转(一页一签)', () => {
const html90 = buildPickingLabelHtml([{ itemName: 'a', qty: 1, unit: '斤' }], {
paper: { widthMm: 80, heightMm: 30 },
rotation: 90,
});
// 页面转置为 30×80,标签块仍是 80×29.5 但整体转 90°
expect(html90).toContain('@page { size: 30mm 80mm; margin: 0; }');
expect(html90).toMatch(/\.pick-label \{[^}]*width: 80mm/);
expect(html90).toContain('rotate(90deg)');
expect(html90).toContain('class="pick-page"');
expect(html90).toContain('break-after: page');
const html270 = buildPickingLabelHtml([{ itemName: 'a', qty: 1, unit: '斤' }], {
paper: { widthMm: 80, heightMm: 30 },
rotation: 270,
});
expect(html270).toContain('@page { size: 30mm 80mm; margin: 0; }');
expect(html270).toContain('rotate(-90deg)');
});
it('旋转 180°:页面尺寸不变、标签块翻转', () => {
const html = buildPickingLabelHtml([{ itemName: 'a', qty: 1, unit: '斤' }], {
paper: { widthMm: 80, heightMm: 30 },
rotation: 180,
});
expect(html).toContain('@page { size: 80mm 30mm; margin: 0; }');
expect(html).toContain('rotate(180deg)');
});
it('非法旋转值回落 0°', () => {
const html = buildPickingLabelHtml([{ itemName: 'a', qty: 1, unit: '斤' }], {
rotation: 45 as unknown as number,
});
expect(html).not.toContain('rotate(');
});
it('有 barcode 时内联二维码 SVG;无则不输出', () => {
const withQr = buildPickingLabelHtml([{ itemName: '大葱', qty: 1, unit: '斤', barcode: 'SKU-1' }]);
expect(withQr).toContain('class="t-qr"');
+64 -20
View File
@@ -169,19 +169,36 @@ function qrSvg(text: unknown): string {
}
}
/** 生成标签页(纸张尺寸可配);多张标签自然平铺(一页能放几张放几张)。 */
/** 打印旋转(补偿打印机驱动把页面转 90°/180° 的情况;默认不旋转) */
export type PickingLabelRotation = 0 | 90 | 180 | 270;
function normalizeRotation(value: unknown): PickingLabelRotation {
const n = Number(value);
return n === 90 || n === 180 || n === 270 ? n : 0;
}
/** 生成标签页(纸张尺寸 + 旋转可配);旋转 0° 时多张标签自然平铺(一页能放几张放几张)。 */
export function buildPickingLabelHtml(
labels: PickingLabel[],
options?: { paper?: Partial<PickingLabelPaper> | null }
options?: {
paper?: Partial<PickingLabelPaper> | null;
/** 旋转角度:0(默认)| 90 | 180 | 270 —— 用于抵消打印机驱动自身的旋转 */
rotation?: PickingLabelRotation | number | null;
}
): string {
const paper = normalizePaper(options?.paper);
const rotation = normalizeRotation(options?.rotation);
const transposed = rotation === 90 || rotation === 270;
// 旋转 90/270 时页面尺寸转置(标签块转过来才装得下)
const pageW = transposed ? paper.heightMm : paper.widthMm;
const pageH = transposed ? paper.widthMm : paper.heightMm;
const labelH = paper.heightMm - 0.5; // 略小于纸高,防四舍五入把满高挤出页外
const contentTop = (baselineDots: number, fontDots: number) =>
mm(baselineDots - fontDots * 0.78);
const pages = (labels || [])
.map((label) => {
const qr = qrSvg(label.barcode);
const codeText = String(label.barcode || '').trim();
return `<section class="pick-label">
const sections = (labels || []).map((label) => {
const qr = qrSvg(label.barcode);
const codeText = String(label.barcode || '').trim();
return `<section class="pick-label">
<div class="t-title">分拣标签</div>
<div class="t-cust">${esc(`客户:${String(label.companyName || '').trim() || '客户'}`)}</div>
<div class="t-name">${esc(`品名:${String(label.itemName || '').trim() || '商品'}`)}</div>
@@ -190,17 +207,10 @@ export function buildPickingLabelHtml(
${qr ? `<div class="t-qr">${qr}</div>` : ''}
${codeText ? `<div class="t-code">${esc(codeText)}</div>` : ''}
</section>`;
})
.join('');
return `<!doctype html><html><head><meta charset="utf-8"><title>分拣标签</title><style>
@page { size: ${paper.widthMm}mm ${paper.heightMm}mm; margin: 0; }
html, body { margin: 0; padding: 0; }
/* 一签一页靠**自然平铺**,不强制分页:
浏览器实际页高可能是标签高的整数倍(如驱动纸张设成 2 张),此时 page-break-after:always
会把每页剩下的一整张留成空白(实测:打 N 张耗 2N 张)。让标签自然平铺,一页能放几张就放几张。
高度取略小于纸高,防四舍五入把满高挤出页外。 */
.pick-label { position: relative; width: ${paper.widthMm}mm; height: ${paper.heightMm - 0.5}mm; box-sizing: border-box; overflow: hidden; color: #000; font-family: -apple-system, "PingFang SC", "Microsoft YaHei", Arial, sans-serif; page-break-inside: avoid; break-inside: avoid; }
.pick-label > div { position: absolute; left: ${mm(PADDING)}; right: ${mm(PADDING + QR_DOTS + 8)}; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
});
/** 标签内部的文字/二维码规则(两种模式共用) */
const innerRules = `.pick-label > div { position: absolute; left: ${mm(PADDING)}; right: ${mm(PADDING + QR_DOTS + 8)}; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pick-label .t-title { top: ${contentTop(PADDING + 24, 24)}; font-size: ${mm(24)}; font-weight: 700; }
.pick-label .t-cust { top: ${contentTop(PADDING + 24 + LINE_DOTS, 20)}; font-size: ${mm(20)}; }
.pick-label .t-name { top: ${contentTop(PADDING + 24 + LINE_DOTS * 2, 20)}; font-size: ${mm(20)}; }
@@ -208,13 +218,47 @@ html, body { margin: 0; padding: 0; }
.pick-label .t-date { top: ${contentTop(PADDING + 24 + LINE_DOTS * 4 + 2, 18)}; font-size: ${mm(18)}; }
.pick-label .t-qr { left: auto; right: ${mm(PADDING)}; top: ${mm(PADDING + 8)}; width: ${mm(QR_DOTS)}; height: ${mm(QR_DOTS)}; }
.pick-label .t-qr svg { width: 100%; height: 100%; }
.pick-label .t-code { left: auto; right: ${mm(PADDING)}; top: ${mm(PADDING + 8 + QR_DOTS + 6)}; width: ${mm(QR_DOTS)}; text-align: center; font-size: ${mm(14)}; }
.pick-label .t-code { left: auto; right: ${mm(PADDING)}; top: ${mm(PADDING + 8 + QR_DOTS + 6)}; width: ${mm(QR_DOTS)}; text-align: center; font-size: ${mm(14)}; }`;
/** 块级样式:不旋转 = 相对定位、自然平铺;旋转 = 绝对定位在页面框内 + transform */
const blockBase = `box-sizing: border-box; overflow: hidden; color: #000; font-family: -apple-system, "PingFang SC", "Microsoft YaHei", Arial, sans-serif;`;
if (rotation === 0) {
return `<!doctype html><html><head><meta charset="utf-8"><title>分拣标签</title><style>
@page { size: ${pageW}mm ${pageH}mm; margin: 0; }
html, body { margin: 0; padding: 0; }
/* 一签一页靠**自然平铺**,不强制分页:
浏览器实际页高可能是标签高的整数倍(如驱动纸张设成 2 张),此时 page-break-after:always
会把每页剩下的一整张留成空白(实测:打 N 张耗 2N 张)。让标签自然平铺,一页能放几张就放几张。 */
.pick-label { position: relative; width: ${paper.widthMm}mm; height: ${labelH}mm; ${blockBase} page-break-inside: avoid; break-inside: avoid; }
${innerRules}
</style></head><body>${sections.join('')}</body></html>`;
}
// 旋转模式:一页一签(页面框 = 纸型),标签块绝对定位 + 旋转
const transform =
rotation === 90
? ' transform-origin: top left; transform: rotate(90deg) translateY(-100%);'
: rotation === 180
? ' transform-origin: center center; transform: rotate(180deg);'
: ' transform-origin: top left; transform: rotate(-90deg) translateX(-100%);';
const pages = sections.map((section) => `<div class="pick-page">${section}</div>`).join('');
return `<!doctype html><html><head><meta charset="utf-8"><title>分拣标签</title><style>
@page { size: ${pageW}mm ${pageH}mm; margin: 0; }
html, body { margin: 0; padding: 0; }
/* 旋转模式(抵消驱动自身旋转):页面 = 纸型,标签块 ${paper.widthMm}×${paper.heightMm}mm 整体转 ${rotation}° */
.pick-page { position: relative; width: ${pageW}mm; height: ${pageH}mm; overflow: hidden; page-break-after: always; break-after: page; }
.pick-page:last-child { page-break-after: auto; break-after: auto; }
.pick-label { position: absolute; top: 0; left: 0; width: ${paper.widthMm}mm; height: ${labelH}mm; ${blockBase}${transform} }
${innerRules}
</style></head><body>${pages}</body></html>`;
}
export async function printPickingLabels(
labels: PickingLabel[],
options?: { paper?: Partial<PickingLabelPaper> | null }
options?: {
paper?: Partial<PickingLabelPaper> | null;
rotation?: PickingLabelRotation | number | null;
}
): Promise<void> {
const list = (labels || []).filter(Boolean);
if (!list.length) return;