|
|
|
|
@ -6,7 +6,8 @@
|
|
|
|
|
|
|
|
|
|
<div v-if="imgList.length > 0">
|
|
|
|
|
<div class="batch-print-btn">
|
|
|
|
|
<el-button type="primary" @click="batchPrint">批量打印</el-button>
|
|
|
|
|
<el-button type="primary" @click="reconnect">重新连接</el-button>
|
|
|
|
|
<el-button type="primary" :loading="isPrinting" :disabled="isPrinting" @click="batchPrint">批量打印</el-button>
|
|
|
|
|
<el-button type="primary" @click="showLogDrawer = true">打印日志</el-button>
|
|
|
|
|
</div>
|
|
|
|
|
<div class="print-preview-title">打印预览</div>
|
|
|
|
|
@ -59,7 +60,9 @@ export default {
|
|
|
|
|
materialList: [], // 存储所有物资信息
|
|
|
|
|
imgList: [], // 存储所有图片路径
|
|
|
|
|
showLogDrawer: false,
|
|
|
|
|
logs: [] // { type: 'success'|'error'|'info', text: string, time: 'HH:mm:ss' }
|
|
|
|
|
logs: [], // { type: 'success'|'error'|'info', text: string, time: 'HH:mm:ss' }
|
|
|
|
|
isPrinting: false,
|
|
|
|
|
needsReconnect: false
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
async created() {
|
|
|
|
|
@ -80,6 +83,16 @@ export default {
|
|
|
|
|
await this.changeLabelValue(false)
|
|
|
|
|
},
|
|
|
|
|
methods: {
|
|
|
|
|
// 重新连接
|
|
|
|
|
async reconnect() {
|
|
|
|
|
// 获取打印机信息
|
|
|
|
|
await this.getInfo()
|
|
|
|
|
// 设置模版打印
|
|
|
|
|
await this.getAllMaterialInfo()
|
|
|
|
|
// 更改每一个标签中的值 并生成预览图片
|
|
|
|
|
await this.changeLabelValue(false)
|
|
|
|
|
this.needsReconnect = false
|
|
|
|
|
},
|
|
|
|
|
// 统一添加日志
|
|
|
|
|
addLog(type, text) {
|
|
|
|
|
const two = n => (n < 10 ? '0' + n : '' + n)
|
|
|
|
|
@ -92,7 +105,7 @@ export default {
|
|
|
|
|
const res = await sendPostRequestApi(funcId, funcName, data)
|
|
|
|
|
if (res.rtnCode === '0') {
|
|
|
|
|
if (showMessage) {
|
|
|
|
|
this.$message.success(funcName + '成功')
|
|
|
|
|
this.$message.success(funcName + '成功')
|
|
|
|
|
}
|
|
|
|
|
this.addLog('success', funcName + '成功')
|
|
|
|
|
return res.outParams ? res.outParams : true
|
|
|
|
|
@ -113,9 +126,14 @@ export default {
|
|
|
|
|
try {
|
|
|
|
|
await this.sendPostRequest('web_DSTP2x_SetLibLang', '设置语言', { language: '0' }, true)
|
|
|
|
|
//枚举设备
|
|
|
|
|
const devRes = await this.sendPostRequest('web_DSTP2x_EnumDev', '获取打印设备', {
|
|
|
|
|
const devRes = await this.sendPostRequest(
|
|
|
|
|
'web_DSTP2x_EnumDev',
|
|
|
|
|
'获取打印设备',
|
|
|
|
|
{
|
|
|
|
|
enumType: '1'
|
|
|
|
|
}, true)
|
|
|
|
|
},
|
|
|
|
|
true
|
|
|
|
|
)
|
|
|
|
|
console.log('devRes', devRes)
|
|
|
|
|
const index = devRes.enumList.indexOf(',')
|
|
|
|
|
if (index !== -1) {
|
|
|
|
|
@ -123,9 +141,14 @@ export default {
|
|
|
|
|
devRes.enumList = devList[0]
|
|
|
|
|
}
|
|
|
|
|
// 连接打印设备
|
|
|
|
|
this.connectRes = await this.sendPostRequest('web_DSTP2x_ConnEnumeratedDev', '连接打印设备', {
|
|
|
|
|
this.connectRes = await this.sendPostRequest(
|
|
|
|
|
'web_DSTP2x_ConnEnumeratedDev',
|
|
|
|
|
'连接打印设备',
|
|
|
|
|
{
|
|
|
|
|
devName: devRes.enumList
|
|
|
|
|
}, true)
|
|
|
|
|
},
|
|
|
|
|
true
|
|
|
|
|
)
|
|
|
|
|
// 获取打印机序列号
|
|
|
|
|
const snRes = await this.sendPostRequest('web_DSTP2x_GetPrtSN', '获取打印机序列号', {
|
|
|
|
|
devHdl: this.connectRes.devHdl
|
|
|
|
|
@ -143,9 +166,14 @@ export default {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 获取打印状态
|
|
|
|
|
const statusRes = await this.sendPostRequest('web_DSTP2x_GetPrtStatus', '获取打印状态', {
|
|
|
|
|
const statusRes = await this.sendPostRequest(
|
|
|
|
|
'web_DSTP2x_GetPrtStatus',
|
|
|
|
|
'获取打印状态',
|
|
|
|
|
{
|
|
|
|
|
devHdl: this.connectRes.devHdl
|
|
|
|
|
}, true)
|
|
|
|
|
},
|
|
|
|
|
true
|
|
|
|
|
)
|
|
|
|
|
if (statusRes.prtStatusDesc) {
|
|
|
|
|
const statusStr = this.getAllStatus(
|
|
|
|
|
statusRes.mainStatusCode,
|
|
|
|
|
@ -178,10 +206,15 @@ export default {
|
|
|
|
|
// 设置模版打印
|
|
|
|
|
async setTemplatePrint(isprint) {
|
|
|
|
|
// 创建画布
|
|
|
|
|
this.labelContent = await this.sendPostRequest('web_DSTP2x_CreateLabelContext', '创建画布', {
|
|
|
|
|
width: '80',
|
|
|
|
|
height: '40'
|
|
|
|
|
}, true)
|
|
|
|
|
this.labelContent = await this.sendPostRequest(
|
|
|
|
|
'web_DSTP2x_CreateLabelContext',
|
|
|
|
|
'创建画布',
|
|
|
|
|
{
|
|
|
|
|
width: '80',
|
|
|
|
|
height: '40'
|
|
|
|
|
},
|
|
|
|
|
true
|
|
|
|
|
)
|
|
|
|
|
if (this.labelContent) {
|
|
|
|
|
// 设置文本字体
|
|
|
|
|
await this.sendPostRequest('web_DSTP2x_LcDraw_SetTextFontSize', '设置文本字体', {
|
|
|
|
|
@ -212,9 +245,10 @@ export default {
|
|
|
|
|
{
|
|
|
|
|
lcHdl: this.labelContent.lcHdl,
|
|
|
|
|
prnMode: isprint ? '0' : '3'
|
|
|
|
|
}, true
|
|
|
|
|
},
|
|
|
|
|
true
|
|
|
|
|
)
|
|
|
|
|
} else {
|
|
|
|
|
} else {
|
|
|
|
|
this.$message.error('创建画布失败')
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
@ -357,12 +391,17 @@ export default {
|
|
|
|
|
data: hexId
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
const printRes = await this.sendPostRequest('web_DSTP2x_PrintLc', `第${index + 1}次打印`, {
|
|
|
|
|
devHdl: this.connectRes.devHdl,
|
|
|
|
|
lcHdl: this.labelContent.lcHdl,
|
|
|
|
|
outFileType: '1',
|
|
|
|
|
rfidReadType: '3'
|
|
|
|
|
}, true)
|
|
|
|
|
const printRes = await this.sendPostRequest(
|
|
|
|
|
'web_DSTP2x_PrintLc',
|
|
|
|
|
`第${index + 1}次打印`,
|
|
|
|
|
{
|
|
|
|
|
devHdl: this.connectRes.devHdl,
|
|
|
|
|
lcHdl: this.labelContent.lcHdl,
|
|
|
|
|
outFileType: '1',
|
|
|
|
|
rfidReadType: '3'
|
|
|
|
|
},
|
|
|
|
|
true
|
|
|
|
|
)
|
|
|
|
|
if (printRes) {
|
|
|
|
|
if (!isprint) {
|
|
|
|
|
this.imgList.push(printRes.outFile)
|
|
|
|
|
@ -371,24 +410,43 @@ export default {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// 完成后清理
|
|
|
|
|
await this.sendPostRequest('web_DSTP2x_DeleteLabelContext', `删除${index + 1}画布句柄`, {
|
|
|
|
|
lcHdl: this.labelContent.lcHdl
|
|
|
|
|
}, true)
|
|
|
|
|
await this.sendPostRequest(
|
|
|
|
|
'web_DSTP2x_DeleteLabelContext',
|
|
|
|
|
`删除${index + 1}画布句柄`,
|
|
|
|
|
{
|
|
|
|
|
lcHdl: this.labelContent.lcHdl
|
|
|
|
|
},
|
|
|
|
|
true
|
|
|
|
|
)
|
|
|
|
|
this.labelContent = ''
|
|
|
|
|
}
|
|
|
|
|
if (isprint) {
|
|
|
|
|
await this.sendPostRequest('web_DSTP2x_DisconnDev', '断开设备连接', {
|
|
|
|
|
devHdl: this.connectRes.devHdl
|
|
|
|
|
}, true)
|
|
|
|
|
await this.sendPostRequest(
|
|
|
|
|
'web_DSTP2x_DisconnDev',
|
|
|
|
|
'断开设备连接',
|
|
|
|
|
{
|
|
|
|
|
devHdl: this.connectRes.devHdl
|
|
|
|
|
},
|
|
|
|
|
true
|
|
|
|
|
)
|
|
|
|
|
// 打印流程完成,需要重新连接
|
|
|
|
|
this.needsReconnect = true
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
// 批量打印
|
|
|
|
|
async batchPrint() {
|
|
|
|
|
// await this.sendPostRequest('web_DSTP2x_SetLcPrnMode', '设置标签画布的打印模式', {
|
|
|
|
|
// lcHdl: this.labelContent.lcHdl,
|
|
|
|
|
// prnMode: '0'
|
|
|
|
|
// })
|
|
|
|
|
await this.changeLabelValue(true)
|
|
|
|
|
if (this.isPrinting) return
|
|
|
|
|
if (this.needsReconnect) {
|
|
|
|
|
this.$message.warning('请重新连接设备')
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
this.isPrinting = true
|
|
|
|
|
try {
|
|
|
|
|
await this.changeLabelValue(true)
|
|
|
|
|
} finally {
|
|
|
|
|
this.isPrinting = false
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
// 获取所有物资信息
|
|
|
|
|
async getAllMaterialInfo() {
|
|
|
|
|
@ -410,7 +468,7 @@ export default {
|
|
|
|
|
// 获取物资详情
|
|
|
|
|
async getMaterialInfo(id) {
|
|
|
|
|
try {
|
|
|
|
|
const res = await getMaterialInfo({ id: id })
|
|
|
|
|
const res = await getMaterialInfo({ id: id })
|
|
|
|
|
if (res) {
|
|
|
|
|
return res
|
|
|
|
|
}
|
|
|
|
|
|