From 18599e1887db8ba7c8ee93d01ce40b32a705fbb7 Mon Sep 17 00:00:00 2001 From: "han\\hanst" Date: Fri, 9 Oct 2026 13:41:32 +0800 Subject: [PATCH] =?UTF-8?q?=E5=85=83=E7=B4=A0=E7=BB=84=E5=90=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/utils/elementCombination.js | 41 +++++ .../modules/labelSetting/LabelDesigner.vue | 3 +- .../components/ElementCombinationDialog.vue | 146 ++++++++++++++---- .../labelSetting/components/PropertyForm.vue | 3 + 4 files changed, 162 insertions(+), 31 deletions(-) create mode 100644 src/utils/elementCombination.js diff --git a/src/utils/elementCombination.js b/src/utils/elementCombination.js new file mode 100644 index 0000000..cf00b3e --- /dev/null +++ b/src/utils/elementCombination.js @@ -0,0 +1,41 @@ +const ELEMENT_TYPES = { + '文本': 'text', + '一维码': 'onecode', + '二维码': 'qrcode', + '图片': 'pic', + '流水号': 'serialNumber' +} + +// 按配对花括号读取引用,保留 #{字段} 和嵌套组合,不用简单的 /{[^}]+}/ 截断内容。 +export function parseElementCombination (data) { + const value = data == null ? '' : String(data) + const references = [] + for (let start = 0; start < value.length; start++) { + if (value[start] !== '{') continue + let depth = 1 + let end = start + 1 + for (; end < value.length && depth > 0; end++) { + if (value[end] === '{') depth++ + if (value[end] === '}') depth-- + } + if (depth > 0) break + + if (start === 0 || value[start - 1] !== '#') { + const reference = value.slice(start + 1, end - 1) + const match = /^(文本|一维码|二维码|图片|流水号)(?:\(([\s\S]*)\))?$/.exec(reference) + if (match) { + references.push({start, end, reference, type: ELEMENT_TYPES[match[1]], data: match[2]}) + } + } + start = end - 1 + } + return references +} + +// 编辑已有组合时替换原组合区间;首次组合才追加,前后固定文字/字段保持不变。 +export function applyElementCombination (data, combinationData) { + const value = data == null ? '' : String(data) + const references = parseElementCombination(value) + if (!references.length) return value + combinationData + return value.slice(0, references[0].start) + combinationData + value.slice(references[references.length - 1].end) +} diff --git a/src/views/modules/labelSetting/LabelDesigner.vue b/src/views/modules/labelSetting/LabelDesigner.vue index 9c7be44..8f72a03 100644 --- a/src/views/modules/labelSetting/LabelDesigner.vue +++ b/src/views/modules/labelSetting/LabelDesigner.vue @@ -166,6 +166,7 @@ import ElementCombinationDialog from './components/ElementCombinationDialog.vue' import PaperSelector from './components/PaperSelector.vue' import { CoordinateTransformer } from '@/utils/coordinateTransform.js' import { ZPLGenerator } from '@/utils/zplGenerator.js' +import { applyElementCombination } from '@/utils/elementCombination' import { getCanvasSize, getRecommendedGridSize } from '@/utils/paperConfig.js' import { saveZplElements, getZplElements } from '@/api/labelSetting/label_setting.js' import {getViewFieldsByLabelType} from '@/api/labelSetting/com_add_update_label.js'; @@ -853,7 +854,7 @@ export default { this.currentCombinationElement.data = combinationConfig.data; break; case 'sequence': - this.currentCombinationElement.data = this.currentCombinationElement.data + combinationConfig.data; + this.currentCombinationElement.data = applyElementCombination(this.currentCombinationElement.data, combinationConfig.data); break; case 'custom': // 对于自定义模式,我们需要在后端处理时执行表达式 diff --git a/src/views/modules/labelSetting/components/ElementCombinationDialog.vue b/src/views/modules/labelSetting/components/ElementCombinationDialog.vue index 88df509..17264a2 100644 --- a/src/views/modules/labelSetting/components/ElementCombinationDialog.vue +++ b/src/views/modules/labelSetting/components/ElementCombinationDialog.vue @@ -12,7 +12,7 @@
-

{{ $t('labelSetting.combination.targetElement', { type: targetElement.type === 'onecode' ? $t('labelSetting.combination.elementBarcode') : $t('labelSetting.combination.elementQrcode') }) }}

+

{{ $t('labelSetting.combination.targetElement', { type: getElementTypeName(targetElement.type) }) }}

{{ $t('labelSetting.combination.currentData', { data: targetElement.data || $t('labelSetting.combination.empty') }) }}

@@ -46,7 +46,7 @@
@@ -74,7 +74,7 @@ @@ -127,6 +127,10 @@