fix(intake): wrap long Gujia barcode suffixes
This commit is contained in:
parent
a423bddc63
commit
78f5e8c570
@ -0,0 +1,53 @@
|
||||
import type { BarcodePrintRow } from "./barcodePrintRows";
|
||||
import { printBarcodeRow } from "./barcodePrintLodop";
|
||||
|
||||
describe("Gujia barcode template", () => {
|
||||
it("prints long numeric suffixes on the existing second line", async () => {
|
||||
const lodop = {
|
||||
PRINT_INIT: jest.fn(),
|
||||
SET_PRINT_PAGESIZE: jest.fn(),
|
||||
SET_PRINT_MODE: jest.fn(),
|
||||
NEWPAGE: jest.fn(),
|
||||
ADD_PRINT_BARCODE: jest.fn(),
|
||||
ADD_PRINT_TEXT: jest.fn(),
|
||||
ADD_PRINT_RECT: jest.fn(),
|
||||
SET_PRINT_STYLEA: jest.fn(),
|
||||
PREVIEW: jest.fn(),
|
||||
};
|
||||
const originalGetCLodop = window.getCLodop;
|
||||
window.getCLodop = () => lodop as never;
|
||||
|
||||
const row = {
|
||||
barcode: "MKHDNZ0409260600037",
|
||||
factoryModel: "",
|
||||
productCategory: "",
|
||||
color: "",
|
||||
size: "",
|
||||
tagMaterial: "",
|
||||
material: "",
|
||||
executeStandard: "",
|
||||
supplierName: "Gujia",
|
||||
} as BarcodePrintRow;
|
||||
|
||||
try {
|
||||
await printBarcodeRow(row, { templateTitle: "顾家" });
|
||||
} finally {
|
||||
window.getCLodop = originalGetCLodop;
|
||||
}
|
||||
|
||||
expect(lodop.ADD_PRINT_TEXT).toHaveBeenCalledWith(
|
||||
"32mm",
|
||||
"0mm",
|
||||
"100%",
|
||||
"1mm",
|
||||
"04092606",
|
||||
);
|
||||
expect(lodop.ADD_PRINT_TEXT).toHaveBeenCalledWith(
|
||||
"44mm",
|
||||
"0mm",
|
||||
"100%",
|
||||
"1mm",
|
||||
"00037",
|
||||
);
|
||||
});
|
||||
});
|
||||
@ -0,0 +1,21 @@
|
||||
type GujiaBarcodeParts = {
|
||||
bar2: string;
|
||||
bar3: string;
|
||||
};
|
||||
|
||||
const FIRST_NUMBER_LINE_LENGTH = 8;
|
||||
|
||||
export function splitGujiaBarcodeParts(parts: GujiaBarcodeParts): GujiaBarcodeParts {
|
||||
if (
|
||||
parts.bar3 ||
|
||||
!/^\d+$/.test(parts.bar2) ||
|
||||
parts.bar2.length <= FIRST_NUMBER_LINE_LENGTH
|
||||
) {
|
||||
return parts;
|
||||
}
|
||||
|
||||
return {
|
||||
bar2: parts.bar2.slice(0, FIRST_NUMBER_LINE_LENGTH),
|
||||
bar3: parts.bar2.slice(FIRST_NUMBER_LINE_LENGTH),
|
||||
};
|
||||
}
|
||||
@ -2,6 +2,7 @@
|
||||
|
||||
import { pinyin } from "pinyin-pro";
|
||||
import type { BarcodePrintRow } from "./barcodePrintRows";
|
||||
import { splitGujiaBarcodeParts } from "./barcodePrintGujia";
|
||||
|
||||
type LodopValue = string | number;
|
||||
|
||||
@ -441,6 +442,8 @@ const BARCODE_PRINT_TEMPLATES: BarcodePrintTemplate[] = [
|
||||
{
|
||||
title: "顾家",
|
||||
printFunc(record, lodop, options) {
|
||||
const barcodeParts = splitGujiaBarcodeParts(record);
|
||||
|
||||
lodop.PRINT_INIT("条码打印");
|
||||
lodop.SET_PRINT_PAGESIZE?.(2, "60mm", "40mm", "");
|
||||
lodop.ADD_PRINT_BARCODE("4mm", "10mm", "25mm", "25mm", "QRCode", record.barcode);
|
||||
@ -448,10 +451,10 @@ const BARCODE_PRINT_TEMPLATES: BarcodePrintTemplate[] = [
|
||||
lodop.ADD_PRINT_TEXT("27mm", "0mm", "100%", "1mm", record.catcode);
|
||||
lodop.SET_PRINT_STYLEA(0, "Alignment", 2);
|
||||
setFont(lodop, 10, true);
|
||||
lodop.ADD_PRINT_TEXT("32mm", "0mm", "100%", "1mm", record.bar2);
|
||||
lodop.ADD_PRINT_TEXT("32mm", "0mm", "100%", "1mm", barcodeParts.bar2);
|
||||
lodop.SET_PRINT_STYLEA(0, "Alignment", 2);
|
||||
setFont(lodop, 20, true);
|
||||
lodop.ADD_PRINT_TEXT("44mm", "0mm", "100%", "1mm", record.bar3);
|
||||
lodop.ADD_PRINT_TEXT("44mm", "0mm", "100%", "1mm", barcodeParts.bar3);
|
||||
lodop.SET_PRINT_STYLEA(0, "Alignment", 2);
|
||||
setFont(lodop, 10, true);
|
||||
if (options?.batchNumber?.trim()) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user