From 4edfd951c59e69797e7bbcee98b726bbe8b5383e Mon Sep 17 00:00:00 2001 From: liufumingren Date: Tue, 15 Sep 2026 16:19:04 +0800 Subject: [PATCH] =?UTF-8?q?fix(print):=20=E8=A7=86=E9=A2=91=E5=8F=B7?= =?UTF-8?q?=E9=9D=A2=E5=8D=95=E8=87=AA=E5=AE=9A=E4=B9=89=E5=8C=BA=E6=9C=80?= =?UTF-8?q?=E5=A4=9A=E4=BF=9D=E7=95=99=208=20=E8=A1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 新增 SPH_CUSTOM_INFO_MAX_LINES / SPH_CUSTOM_INFO_LINE_BREAK 常量与 truncateSphCustomInfoLines helper:视频号面单自定义区仅可容纳 8 行文本, 第 9 行起整体舍弃(含首行头部与子单号行,空行同样计入行数) - applySphExpressFieldMapping 在合并子单号行、头部行、商品明细行与额外自定义行 后统一截断,避免客户端溢出错版 --- app/lib/printer_data_builder.js | 52 +++++++++++++++++++++++++++++---- 1 file changed, 46 insertions(+), 6 deletions(-) diff --git a/app/lib/printer_data_builder.js b/app/lib/printer_data_builder.js index c9055fe..b9e357c 100644 --- a/app/lib/printer_data_builder.js +++ b/app/lib/printer_data_builder.js @@ -106,6 +106,19 @@ const WAYBILL_CUSTOM_DISPLAY_TYPES = Object.freeze({ PICK_LOCATION_NAME_BARCODE_QTY: '5', }); +/** + * 视频号(SPH)自定义区最大行数:超出部分全部舍弃。 + * 视频号面单自定义区仅可容纳 8 行文本,超过后客户端会出现溢出/错版。 + * @type {number} + */ +const SPH_CUSTOM_INFO_MAX_LINES = 8; + +/** + * 视频号(SPH)自定义区文本行分隔标记。 + * @type {string} + */ +const SPH_CUSTOM_INFO_LINE_BREAK = '
'; + const ARRAY_STYLE_KEYS = new Set([ 'documents', 'taskList', @@ -637,6 +650,29 @@ function mergeWaybillCustomLines(lines = [], options = {}) { return text; } +/** + * 截断视频号(SPH)自定义区文本行。 + * + * 视频号面单自定义区最多打印 8 行,第 9 行起全部舍弃。 + * 统计口径为最终文本的全部分行(含首行头部与子单号行),空白行同样计入行数,不做过滤。 + * + * @param {string} text 自定义区文本(以 `
` 分隔行)。 + * @return {string} 截断后的文本。 + */ +function truncateSphCustomInfoLines(text) { + const safeText = String(text === undefined || text === null ? '' : text); + if (!safeText) { + return safeText; + } + + const lines = safeText.split(SPH_CUSTOM_INFO_LINE_BREAK); + if (lines.length <= SPH_CUSTOM_INFO_MAX_LINES) { + return safeText; + } + + return lines.slice(0, SPH_CUSTOM_INFO_MAX_LINES).join(SPH_CUSTOM_INFO_LINE_BREAK); +} + /** * 构建数组字段的精简骨架。 * @@ -2092,6 +2128,7 @@ function applyXhsExpressFieldMapping( * - taskList[0].printInfo 使用 order_express.printinfo(非空时) * - taskList[0].printNum.sumNum 使用 wave_total_orders,curNum 保持模板值,缺失时默认 1 * - taskList[0].customInfo.data.description 使用现有商品汇总文本并按
拼接 + * - taskList[0].customInfo.data.description 最多保留 8 行(含首行头部与子单号行),第 9 行起全部舍弃 * - taskList[0].extendData.sender 使用 policy_config 发件人信息 * - taskList[0].taskID 优先沿用 buildPlatformRequestSkeleton 现有 taskId * @@ -2166,12 +2203,15 @@ function applySphExpressFieldMapping( boxNo: Number(safeOrderDelivery.box_no || 0), } ); - const customProductInfo = appendExtraCustomLines( - mergeWaybillCustomLines(customProductInfoLines, { - lineBreak: LINE_BREAK_MAP.LF, - }).replace(/\n/g, '
'), - extraCustomLines, - '
' + // 视频号面单自定义区最多 8 行:子单号行 + 头部行 + 商品明细行合计截断,第 9 行起舍弃 + const customProductInfo = truncateSphCustomInfoLines( + appendExtraCustomLines( + mergeWaybillCustomLines(customProductInfoLines, { + lineBreak: LINE_BREAK_MAP.LF, + }).replace(/\n/g, SPH_CUSTOM_INFO_LINE_BREAK), + extraCustomLines, + SPH_CUSTOM_INFO_LINE_BREAK + ) ); task.customInfo = isPlainObject(task.customInfo) ? task.customInfo : {};