|
|
@ -7,17 +7,33 @@ |
|
|
<span class="dpi-label">预览DPI:</span> |
|
|
<span class="dpi-label">预览DPI:</span> |
|
|
<span class="dpi-value">{{ currentDpiLabel }}</span> |
|
|
<span class="dpi-value">{{ currentDpiLabel }}</span> |
|
|
</div> |
|
|
</div> |
|
|
|
|
|
</div> |
|
|
|
|
|
|
|
|
|
|
|
<div class="control-row button-row"> |
|
|
<el-button |
|
|
<el-button |
|
|
type="primary" |
|
|
type="primary" |
|
|
size="small" |
|
|
|
|
|
|
|
|
size="mini" |
|
|
icon="el-icon-view" |
|
|
icon="el-icon-view" |
|
|
:loading="previewLoading" |
|
|
:loading="previewLoading" |
|
|
@click="generatePreview" |
|
|
@click="generatePreview" |
|
|
|
|
|
class="compact-btn" |
|
|
|
|
|
style="flex: 1; height: 24px; min-height: 24px; max-height: 24px; padding: 4px 2px; font-size: 10px; margin: 0; border-radius: 3px;" |
|
|
> |
|
|
> |
|
|
预览 |
|
|
预览 |
|
|
</el-button> |
|
|
</el-button> |
|
|
|
|
|
|
|
|
|
|
|
<el-button |
|
|
|
|
|
type="warning" |
|
|
|
|
|
size="mini" |
|
|
|
|
|
icon="el-icon-data-analysis" |
|
|
|
|
|
:loading="realDataPreviewLoading" |
|
|
|
|
|
@click="generateRealDataPreview" |
|
|
|
|
|
class="compact-btn" |
|
|
|
|
|
style="flex: 1; height: 24px; min-height: 24px; max-height: 24px; padding: 4px 2px; font-size: 10px; margin: 0; border-radius: 3px;" |
|
|
|
|
|
> |
|
|
|
|
|
真实数据预览 |
|
|
|
|
|
</el-button> |
|
|
|
|
|
|
|
|
<PrintButton |
|
|
<PrintButton |
|
|
:zpl-code="zplCode" |
|
|
:zpl-code="zplCode" |
|
|
:report-id="$route.params.labelSetting && $route.params.labelSetting.labelNo" |
|
|
:report-id="$route.params.labelSetting && $route.params.labelSetting.labelNo" |
|
|
@ -83,6 +99,7 @@ import { ZPLGenerator } from '@/utils/zplGenerator.js' |
|
|
import dynamicPaperConfig from '@/utils/paperConfigDynamic.js' |
|
|
import dynamicPaperConfig from '@/utils/paperConfigDynamic.js' |
|
|
import { debounce } from 'lodash' |
|
|
import { debounce } from 'lodash' |
|
|
import { PrintButton } from '@/components/print' |
|
|
import { PrintButton } from '@/components/print' |
|
|
|
|
|
import { previewLabelWithRealData } from '@/api/labelSetting/label_setting.js' |
|
|
|
|
|
|
|
|
export default { |
|
|
export default { |
|
|
name: 'ZPLPreview', |
|
|
name: 'ZPLPreview', |
|
|
@ -111,10 +128,12 @@ export default { |
|
|
default: 203 |
|
|
default: 203 |
|
|
} |
|
|
} |
|
|
}, |
|
|
}, |
|
|
|
|
|
emits: ['auto-save'], |
|
|
data() { |
|
|
data() { |
|
|
return { |
|
|
return { |
|
|
previewImage: null, |
|
|
previewImage: null, |
|
|
previewLoading: false, |
|
|
previewLoading: false, |
|
|
|
|
|
realDataPreviewLoading: false, |
|
|
autoPreview: true // 默认开启实时预览 |
|
|
autoPreview: true // 默认开启实时预览 |
|
|
} |
|
|
} |
|
|
}, |
|
|
}, |
|
|
@ -301,6 +320,91 @@ export default { |
|
|
console.log('预览已清除') |
|
|
console.log('预览已清除') |
|
|
}, |
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
async generateRealDataPreview() { |
|
|
|
|
|
const reportId = this.$route.params.labelSetting && this.$route.params.labelSetting.labelNo |
|
|
|
|
|
if (!reportId) { |
|
|
|
|
|
this.$message.warning('请先设置标签编号') |
|
|
|
|
|
return |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 检查是否有未保存的更改 |
|
|
|
|
|
if (this.elements.length === 0) { |
|
|
|
|
|
this.$message.warning('请先添加标签元素') |
|
|
|
|
|
return |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
this.realDataPreviewLoading = true |
|
|
|
|
|
|
|
|
|
|
|
try { |
|
|
|
|
|
// 1. 先自动保存当前标签设置 |
|
|
|
|
|
|
|
|
|
|
|
await this.autoSave() |
|
|
|
|
|
|
|
|
|
|
|
// 2. 等待一下确保保存完成 |
|
|
|
|
|
await new Promise(resolve => setTimeout(resolve, 500)) |
|
|
|
|
|
|
|
|
|
|
|
// 3. 调用真实数据预览API |
|
|
|
|
|
const response = await previewLabelWithRealData({ |
|
|
|
|
|
reportId: reportId |
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
if (response && response.data && response.data.code === 200) { |
|
|
|
|
|
const realZplCode = response.data.data |
|
|
|
|
|
|
|
|
|
|
|
// 使用真实数据的ZPL代码生成预览图 |
|
|
|
|
|
await this.generatePreviewWithZpl(realZplCode) |
|
|
|
|
|
|
|
|
|
|
|
this.$message.success('真实数据预览生成成功') |
|
|
|
|
|
} else { |
|
|
|
|
|
this.$message.error((response.data && response.data.msg) || '真实数据预览失败') |
|
|
|
|
|
} |
|
|
|
|
|
} catch (error) { |
|
|
|
|
|
console.error('真实数据预览失败:', error) |
|
|
|
|
|
this.$message.error('真实数据预览失败: ' + (error.message || '网络错误')) |
|
|
|
|
|
} finally { |
|
|
|
|
|
this.realDataPreviewLoading = false |
|
|
|
|
|
} |
|
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
async autoSave() { |
|
|
|
|
|
// 通过事件通知父组件执行保存 |
|
|
|
|
|
return new Promise((resolve, reject) => { |
|
|
|
|
|
// 发送保存事件到父组件 |
|
|
|
|
|
this.$emit('auto-save', { |
|
|
|
|
|
success: resolve, |
|
|
|
|
|
error: reject |
|
|
|
|
|
}) |
|
|
|
|
|
}) |
|
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
async generatePreviewWithZpl(zplCode) { |
|
|
|
|
|
if (!zplCode) { |
|
|
|
|
|
this.previewImage = null |
|
|
|
|
|
return |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
try { |
|
|
|
|
|
const labelSize = this.getLabelarySize() |
|
|
|
|
|
const apiUrl = `https://api.labelary.com/v1/printers/${this.labelaryDpmm}dpmm/labels/${labelSize}/0/` |
|
|
|
|
|
const response = await axios.post(apiUrl, zplCode, { |
|
|
|
|
|
responseType: 'blob', |
|
|
|
|
|
timeout: 15000, |
|
|
|
|
|
headers: { |
|
|
|
|
|
'Content-Type': 'application/x-www-form-urlencoded' |
|
|
|
|
|
} |
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
// 清理旧的预览图片URL |
|
|
|
|
|
if (this.previewImage) { |
|
|
|
|
|
URL.revokeObjectURL(this.previewImage) |
|
|
|
|
|
} |
|
|
|
|
|
this.previewImage = URL.createObjectURL(response.data) |
|
|
|
|
|
} catch (error) { |
|
|
|
|
|
console.error('预览图生成失败:', error) |
|
|
|
|
|
this.$message.error('预览图生成失败') |
|
|
|
|
|
} |
|
|
|
|
|
}, |
|
|
|
|
|
|
|
|
handlePrintSuccess(result) { |
|
|
handlePrintSuccess(result) { |
|
|
console.log('打印成功:', result) |
|
|
console.log('打印成功:', result) |
|
|
// 可以在这里添加打印成功后的逻辑,比如更新状态等 |
|
|
// 可以在这里添加打印成功后的逻辑,比如更新状态等 |
|
|
@ -341,6 +445,74 @@ export default { |
|
|
flex: 1; |
|
|
flex: 1; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
.button-row { |
|
|
|
|
|
display: flex; |
|
|
|
|
|
gap: 10px; |
|
|
|
|
|
align-items: stretch; |
|
|
|
|
|
justify-content: space-between; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
.button-row > * { |
|
|
|
|
|
flex: 1 1 0; |
|
|
|
|
|
height: 24px !important; |
|
|
|
|
|
min-height: 24px !important; |
|
|
|
|
|
max-height: 24px !important; |
|
|
|
|
|
font-size: 10px !important; |
|
|
|
|
|
line-height: 1.2 !important; |
|
|
|
|
|
border-radius: 3px !important; |
|
|
|
|
|
margin: 0 !important; |
|
|
|
|
|
box-sizing: border-box !important; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
.button-row .el-button, |
|
|
|
|
|
.button-row .compact-btn { |
|
|
|
|
|
flex: 1 1 0 !important; |
|
|
|
|
|
height: 24px !important; |
|
|
|
|
|
min-height: 24px !important; |
|
|
|
|
|
max-height: 24px !important; |
|
|
|
|
|
font-size: 10px !important; |
|
|
|
|
|
line-height: 1.2 !important; |
|
|
|
|
|
border-radius: 3px !important; |
|
|
|
|
|
margin: 0 !important; |
|
|
|
|
|
box-sizing: border-box !important; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
.button-row .el-button .el-icon, |
|
|
|
|
|
.button-row .compact-btn .el-icon { |
|
|
|
|
|
font-size: 10px !important; |
|
|
|
|
|
margin-right: 2px !important; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/* 强制覆盖PrintButton组件的样式 */ |
|
|
|
|
|
.button-row >>> .el-button { |
|
|
|
|
|
flex: 1 1 0 !important; |
|
|
|
|
|
height: 24px !important; |
|
|
|
|
|
min-height: 24px !important; |
|
|
|
|
|
max-height: 24px !important; |
|
|
|
|
|
font-size: 10px !important; |
|
|
|
|
|
line-height: 1.2 !important; |
|
|
|
|
|
border-radius: 3px !important; |
|
|
|
|
|
margin: 0 !important; |
|
|
|
|
|
box-sizing: border-box !important; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
.dpi-info { |
|
|
|
|
|
display: flex; |
|
|
|
|
|
align-items: center; |
|
|
|
|
|
gap: 8px; |
|
|
|
|
|
font-size: 13px; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
.dpi-label { |
|
|
|
|
|
color: #606266; |
|
|
|
|
|
font-weight: 500; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
.dpi-value { |
|
|
|
|
|
color: #303133; |
|
|
|
|
|
font-weight: 600; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
.preview-image { |
|
|
.preview-image { |
|
|
margin-bottom: 16px; |
|
|
margin-bottom: 16px; |
|
|
text-align: center; |
|
|
text-align: center; |
|
|
|