From 239e5fe99fb92198443b438ec1167f40fbfcd029 Mon Sep 17 00:00:00 2001 From: "han\\hanst" Date: Wed, 4 Nov 2026 13:34:17 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BB=84=E5=90=88=E6=8C=89=E2=80=9C=E5=85=83?= =?UTF-8?q?=E7=B4=A0=E7=B1=BB=E5=9E=8B=EF=BC=8B=E5=86=85=E5=AE=B9=E2=80=9D?= =?UTF-8?q?=E5=8C=B9=E9=85=8D=EF=BC=8C=E5=90=8C=E5=90=8D=E5=85=83=E7=B4=A0?= =?UTF-8?q?=E4=BA=92=E7=9B=B8=E8=A6=86=E7=9B=96=EF=BC=8C=E6=9C=80=E7=BB=88?= =?UTF-8?q?=E4=BD=BF=E7=94=A8=E6=9C=80=E5=90=8E=E4=B8=80=E4=B8=AA=E5=85=83?= =?UTF-8?q?=E7=B4=A0=E7=9A=84=E5=85=AC=E5=BC=8F=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/utils/elementCombination.js | 23 ++++++++++++-- src/utils/zplGenerator.js | 2 +- .../components/ElementCombinationDialog.vue | 30 ++++++++++++++----- 3 files changed, 44 insertions(+), 11 deletions(-) diff --git a/src/utils/elementCombination.js b/src/utils/elementCombination.js index cf00b3e..cd9e3d4 100644 --- a/src/utils/elementCombination.js +++ b/src/utils/elementCombination.js @@ -6,6 +6,21 @@ const ELEMENT_TYPES = { '流水号': 'serialNumber' } +// labelNo 已持久化;新建元素在首次保存前使用画布 ID,由后端统一映射。 +export function getElementReferenceKey (element) { + const key = element.labelNo || element.id + return key == null ? null : String(key) +} + +export function getElementReference (element) { + if (element.combinationReference) return element.combinationReference + const typeName = Object.keys(ELEMENT_TYPES).find(name => ELEMENT_TYPES[name] === element.type) || element.type + const key = getElementReferenceKey(element) + const identity = key == null ? '' : `@${encodeURIComponent(key)}` + const content = element.data ? `(${element.data})` : '' + return `${typeName}${identity}${content}` +} + // 按配对花括号读取引用,保留 #{字段} 和嵌套组合,不用简单的 /{[^}]+}/ 截断内容。 export function parseElementCombination (data) { const value = data == null ? '' : String(data) @@ -22,9 +37,13 @@ export function parseElementCombination (data) { if (start === 0 || value[start - 1] !== '#') { const reference = value.slice(start + 1, end - 1) - const match = /^(文本|一维码|二维码|图片|流水号)(?:\(([\s\S]*)\))?$/.exec(reference) + const match = /^(文本|一维码|二维码|图片|流水号)(?:@([^(){}]+))?(?:\(([\s\S]*)\))?$/.exec(reference) if (match) { - references.push({start, end, reference, type: ELEMENT_TYPES[match[1]], data: match[2]}) + let elementKey = match[2] + if (elementKey !== undefined) { + try { elementKey = decodeURIComponent(elementKey) } catch (error) { /* 保留损坏标识,不能按同名元素兜底。 */ } + } + references.push({start, end, reference, type: ELEMENT_TYPES[match[1]], data: match[3], elementKey}) } } start = end - 1 diff --git a/src/utils/zplGenerator.js b/src/utils/zplGenerator.js index fff68b2..e24e34a 100644 --- a/src/utils/zplGenerator.js +++ b/src/utils/zplGenerator.js @@ -237,7 +237,7 @@ export class ZPLGenerator { } const weekNo = Math.floor((diffDays - daysToNextWeekStart) / 7) + 2 const normalizedWeekNo = Math.max(1, weekNo) - return `${String(normalizedWeekNo).padStart(2, '0')}${String(date.getFullYear() % 100).padStart(2, '0')}` + return `${String(date.getFullYear() % 100).padStart(2, '0')}${String(normalizedWeekNo).padStart(2, '0')}` } calculateWeekday(date, firstDayOfWeekStr) { diff --git a/src/views/modules/labelSetting/components/ElementCombinationDialog.vue b/src/views/modules/labelSetting/components/ElementCombinationDialog.vue index 17264a2..308d01b 100644 --- a/src/views/modules/labelSetting/components/ElementCombinationDialog.vue +++ b/src/views/modules/labelSetting/components/ElementCombinationDialog.vue @@ -127,7 +127,7 @@