From 6edecaa45149de51f007ee5b1bbd3bc833c0c581 Mon Sep 17 00:00:00 2001 From: "han\\hanst" Date: Mon, 18 Aug 2025 16:33:14 +0800 Subject: [PATCH] =?UTF-8?q?=E7=95=8C=E9=9D=A2=E8=AE=BE=E5=AE=9A=E7=9A=84?= =?UTF-8?q?=E5=86=85=E5=AE=B9=E9=9C=80=E8=A6=81=E6=8C=89=E7=89=B9=E5=AE=9A?= =?UTF-8?q?=E6=A0=BC=E5=BC=8F=E7=BB=84=E5=90=88=E5=88=B0=E6=9D=A1=E7=A0=81?= =?UTF-8?q?=E3=80=81=E4=BA=8C=E7=BB=B4=E7=A0=81=E4=B8=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/utils/zplGenerator.js | 7 +- .../modules/labelSetting/LabelDesigner.vue | 62 ++ .../components/ElementCombinationDialog.vue | 721 ++++++++++++++++++ .../labelSetting/components/PropertyForm.vue | 12 +- .../labelSetting/components/PropertyPanel.vue | 3 +- 5 files changed, 796 insertions(+), 9 deletions(-) create mode 100644 src/views/modules/labelSetting/components/ElementCombinationDialog.vue diff --git a/src/utils/zplGenerator.js b/src/utils/zplGenerator.js index 4a2a8d9..a9edda2 100644 --- a/src/utils/zplGenerator.js +++ b/src/utils/zplGenerator.js @@ -159,11 +159,8 @@ export class ZPLGenerator { const showContent = element.showContent !== false // 默认显示内容 // 将毫米转换为ZPL单位 - // 宽度:ZPL的^BY宽度参数控制窄条宽度倍数 (范围1-10) - // 根据ZPL规范,这个参数不是直接的物理尺寸,而是相对倍数 - // 使用经验公式:倍数 ≈ 宽度(mm) * 1.5,确保在1-10范围内 - const widthMM = parseFloat(element.width) || 2 - const width = Math.max(1, Math.min(10, Math.round(widthMM * 1.5))) + // 宽度:毫米转换为ZPL宽度倍数 (范围1-10) + const width = Math.min(10, Math.round((element.width || 0.33) * this.dpi / 25.4)) // 0.33mm≈13mil 常用 // 高度:毫米转换为点数,使用精确的DPI转换公式 const height = Math.max(1, Math.round((element.height || 15) * this.dpi / 25.4)) diff --git a/src/views/modules/labelSetting/LabelDesigner.vue b/src/views/modules/labelSetting/LabelDesigner.vue index e2a1f57..6e2bb8d 100644 --- a/src/views/modules/labelSetting/LabelDesigner.vue +++ b/src/views/modules/labelSetting/LabelDesigner.vue @@ -125,6 +125,7 @@ @save="handleSave" @preview="handlePreview" @data-source="handleDataSource" + @element-combination="handleElementCombination" /> @@ -137,6 +138,16 @@ @update:visible="dataSourceVisible = $event" @confirm="handleDataSourceConfirm" /> + + + @@ -145,6 +156,7 @@ import HorizontalToolbar from './components/HorizontalToolbar.vue' import DesignCanvas from './components/DesignCanvas.vue' import PropertyPanel from './components/PropertyPanel.vue' import DataSourceDialog from './components/DataSourceDialog.vue' +import ElementCombinationDialog from './components/ElementCombinationDialog.vue' import PaperSelector from './components/PaperSelector.vue' import { CoordinateTransformer } from '@/utils/coordinateTransform.js' import { ZPLGenerator } from '@/utils/zplGenerator.js' @@ -162,6 +174,7 @@ export default { DesignCanvas, PropertyPanel, DataSourceDialog, + ElementCombinationDialog, PaperSelector }, props: { @@ -187,6 +200,8 @@ export default { dataSourceVisible: false, dataKeys: [], currentElementText: '', // 当前元素的文本内容 + elementCombinationVisible: false, + currentCombinationElement: null, // 当前要组合的元素 labelSettings: {}, partialVisibilityWarned: false, // 部分可见性警告状态 debouncedBoundaryMessage: null, // 防抖边界消息函数 @@ -729,6 +744,53 @@ export default { } }, + async handleElementCombination(element) { + // 获取数据源字段信息(如果还没有的话) + if (!this.dataKeys.length) { + try { + const response = await getViewFieldsByLabelType({ + labelType: this.labelSettings.labelType, + site: this.$store.state.user.site + }); + + if (response.data && response.data.code === 200) { + this.dataKeys = response.data.data.map(field => ({ + ...field, + fieldDescription: field.fieldDescription || '' + })); + } + } catch (error) { + console.error('获取数据源字段失败:', error); + } + } + + this.currentCombinationElement = element; + this.elementCombinationVisible = true; + }, + + handleElementCombinationConfirm(combinationConfig) { + if (this.currentCombinationElement) { + // 根据组合模式设置元素数据 + switch (combinationConfig.mode) { + case 'template': + this.currentCombinationElement.data = combinationConfig.data; + break; + case 'sequence': + this.currentCombinationElement.data = this.currentCombinationElement.data + combinationConfig.data; + break; + case 'custom': + // 对于自定义模式,我们需要在后端处理时执行表达式 + this.currentCombinationElement.data = `CUSTOM:${combinationConfig.data}`; + break; + } + + // 保存组合配置到元素的扩展属性中 + this.$set(this.currentCombinationElement, 'combinationConfig', combinationConfig); + + this.$message.success('元素组合设置已保存'); + } + }, + handlePaperChange(paperId) { this.selectedPaper = paperId diff --git a/src/views/modules/labelSetting/components/ElementCombinationDialog.vue b/src/views/modules/labelSetting/components/ElementCombinationDialog.vue new file mode 100644 index 0000000..0b033d7 --- /dev/null +++ b/src/views/modules/labelSetting/components/ElementCombinationDialog.vue @@ -0,0 +1,721 @@ + + + + + diff --git a/src/views/modules/labelSetting/components/PropertyForm.vue b/src/views/modules/labelSetting/components/PropertyForm.vue index 2cb3ae5..94562ee 100644 --- a/src/views/modules/labelSetting/components/PropertyForm.vue +++ b/src/views/modules/labelSetting/components/PropertyForm.vue @@ -239,6 +239,9 @@ 数据源 + + 元素组合 + @@ -301,6 +304,9 @@ 数据源 + + 元素组合 + @@ -391,7 +397,7 @@
-
+
@@ -77,7 +78,7 @@ export default { default: () => ({ width: 472, height: 315 }) } }, - emits: ['delete-element', 'save', 'preview', 'data-source'], + emits: ['delete-element', 'save', 'preview', 'data-source', 'element-combination'], methods: { handleImageUpload(imageData) { if (this.selectedElement && this.selectedElement.type === 'pic') {