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 @@