标签打印

master
lion 4 weeks ago
parent dc6af48efa
commit 2db98513a7

@ -570,7 +570,7 @@
// } // }
// Cookies.remove('objs') // Cookies.remove('objs')
// Cookies.set('objs',JSON.stringify(_objs)) // Cookies.set('objs',JSON.stringify(_objs))
window.open('/admin/print.html?ids=' + this.printArr, '_blank') window.open('/admin/#/myprint?ids=' + this.printArr, '_blank')
}, },
async exportExcel(sheetName) { async exportExcel(sheetName) {
const res = await index(Object.assign(this.select, { const res = await index(Object.assign(this.select, {

@ -6,7 +6,8 @@
<div v-if="imgList.length > 0"> <div v-if="imgList.length > 0">
<div class="batch-print-btn"> <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> <el-button type="primary" @click="showLogDrawer = true">打印日志</el-button>
</div> </div>
<div class="print-preview-title">打印预览</div> <div class="print-preview-title">打印预览</div>
@ -59,7 +60,9 @@ export default {
materialList: [], // materialList: [], //
imgList: [], // imgList: [], //
showLogDrawer: false, 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() { async created() {
@ -80,6 +83,16 @@ export default {
await this.changeLabelValue(false) await this.changeLabelValue(false)
}, },
methods: { methods: {
//
async reconnect() {
//
await this.getInfo()
//
await this.getAllMaterialInfo()
//
await this.changeLabelValue(false)
this.needsReconnect = false
},
// //
addLog(type, text) { addLog(type, text) {
const two = n => (n < 10 ? '0' + n : '' + n) const two = n => (n < 10 ? '0' + n : '' + n)
@ -113,9 +126,14 @@ export default {
try { try {
await this.sendPostRequest('web_DSTP2x_SetLibLang', '设置语言', { language: '0' }, true) 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' enumType: '1'
}, true) },
true
)
console.log('devRes', devRes) console.log('devRes', devRes)
const index = devRes.enumList.indexOf(',') const index = devRes.enumList.indexOf(',')
if (index !== -1) { if (index !== -1) {
@ -123,9 +141,14 @@ export default {
devRes.enumList = devList[0] devRes.enumList = devList[0]
} }
// //
this.connectRes = await this.sendPostRequest('web_DSTP2x_ConnEnumeratedDev', '连接打印设备', { this.connectRes = await this.sendPostRequest(
'web_DSTP2x_ConnEnumeratedDev',
'连接打印设备',
{
devName: devRes.enumList devName: devRes.enumList
}, true) },
true
)
// //
const snRes = await this.sendPostRequest('web_DSTP2x_GetPrtSN', '获取打印机序列号', { const snRes = await this.sendPostRequest('web_DSTP2x_GetPrtSN', '获取打印机序列号', {
devHdl: this.connectRes.devHdl 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 devHdl: this.connectRes.devHdl
}, true) },
true
)
if (statusRes.prtStatusDesc) { if (statusRes.prtStatusDesc) {
const statusStr = this.getAllStatus( const statusStr = this.getAllStatus(
statusRes.mainStatusCode, statusRes.mainStatusCode,
@ -178,10 +206,15 @@ export default {
// //
async setTemplatePrint(isprint) { async setTemplatePrint(isprint) {
// //
this.labelContent = await this.sendPostRequest('web_DSTP2x_CreateLabelContext', '创建画布', { this.labelContent = await this.sendPostRequest(
'web_DSTP2x_CreateLabelContext',
'创建画布',
{
width: '80', width: '80',
height: '40' height: '40'
}, true) },
true
)
if (this.labelContent) { if (this.labelContent) {
// //
await this.sendPostRequest('web_DSTP2x_LcDraw_SetTextFontSize', '设置文本字体', { await this.sendPostRequest('web_DSTP2x_LcDraw_SetTextFontSize', '设置文本字体', {
@ -212,7 +245,8 @@ export default {
{ {
lcHdl: this.labelContent.lcHdl, lcHdl: this.labelContent.lcHdl,
prnMode: isprint ? '0' : '3' prnMode: isprint ? '0' : '3'
}, true },
true
) )
} else { } else {
this.$message.error('创建画布失败') this.$message.error('创建画布失败')
@ -357,12 +391,17 @@ export default {
data: hexId data: hexId
}) })
const printRes = await this.sendPostRequest('web_DSTP2x_PrintLc', `${index + 1}次打印`, { const printRes = await this.sendPostRequest(
'web_DSTP2x_PrintLc',
`${index + 1}次打印`,
{
devHdl: this.connectRes.devHdl, devHdl: this.connectRes.devHdl,
lcHdl: this.labelContent.lcHdl, lcHdl: this.labelContent.lcHdl,
outFileType: '1', outFileType: '1',
rfidReadType: '3' rfidReadType: '3'
}, true) },
true
)
if (printRes) { if (printRes) {
if (!isprint) { if (!isprint) {
this.imgList.push(printRes.outFile) this.imgList.push(printRes.outFile)
@ -371,24 +410,43 @@ export default {
} }
} }
// //
await this.sendPostRequest('web_DSTP2x_DeleteLabelContext', `删除${index + 1}画布句柄`, { await this.sendPostRequest(
'web_DSTP2x_DeleteLabelContext',
`删除${index + 1}画布句柄`,
{
lcHdl: this.labelContent.lcHdl lcHdl: this.labelContent.lcHdl
}, true) },
true
)
this.labelContent = '' this.labelContent = ''
} }
if (isprint) { if (isprint) {
await this.sendPostRequest('web_DSTP2x_DisconnDev', '断开设备连接', { await this.sendPostRequest(
'web_DSTP2x_DisconnDev',
'断开设备连接',
{
devHdl: this.connectRes.devHdl devHdl: this.connectRes.devHdl
}, true) },
true
)
//
this.needsReconnect = true
} }
}, },
// //
async batchPrint() { async batchPrint() {
// await this.sendPostRequest('web_DSTP2x_SetLcPrnMode', '', { if (this.isPrinting) return
// lcHdl: this.labelContent.lcHdl, if (this.needsReconnect) {
// prnMode: '0' this.$message.warning('请重新连接设备')
// }) return
}
this.isPrinting = true
try {
await this.changeLabelValue(true) await this.changeLabelValue(true)
} finally {
this.isPrinting = false
}
}, },
// //
async getAllMaterialInfo() { async getAllMaterialInfo() {

Loading…
Cancel
Save