标签打印

master
lion 7 months ago
parent d5375d8682
commit dc6af48efa

@ -0,0 +1,22 @@
import request from '@/utils/request'
function generateUniqueId() {
const timestamp = Date.now().toString(36); // 使用36进制避免出现数字开头的问题
const randomNum = Math.random().toString(36).substr(2, 9); // 获取随机数的36进制表示并截取后9位
return timestamp + randomNum;
}
export function sendPostRequestApi(funcId, funcName, data) {
const params = JSON.stringify({
version: "1.0",
seqNo: generateUniqueId(),
funcName: funcId,
inParams: data,
});
console.log(params)
return request({
url: 'http://127.0.0.1:9001/',
method: 'post',
data: params
})
}

@ -40,12 +40,17 @@ export const constantRoutes = [{
path: '/404',
component: () => import('@/views/404'),
hidden: true
},
},
{
path: '/leader',
component: () => import('@/views/jsc/leader'),
hidden: true
},
{
path: '/myprint',
component: () => import('@/views/myprint/index'),
hidden: true
},
{
path: '/stocks',
component: () => import('@/views/stocks/index'),

@ -0,0 +1,422 @@
<template>
<div class="wrap">
<!-- <h1>打印机序号{{ prtSN }}</h1>
<h1>固件版本{{ prtFWVer }}</h1>
<h1>打印状态{{ prtStatusDesc }}</h1> -->
<div v-if="imgList.length > 0">
<div class="batch-print-btn">
<el-button type="primary" @click="batchPrint"></el-button>
<el-button type="primary" @click="showLogDrawer = true">打印日志</el-button>
</div>
<div class="print-preview-title">打印预览</div>
<div class="print-preview-img-box">
<img :src="img" class="print-preview-img" v-for="(img, index) in imgList" :key="index" />
</div>
</div>
<!-- <el-button @click="setTemplatePrint"></el-button> -->
<el-drawer
title="打印日志"
:visible.sync="showLogDrawer"
direction="rtl"
size="50%"
:with-header="true"
>
<div class="log-drawer-content">
<div style="margin-bottom: 10px;">
<div>打印机序号{{ prtSN }}</div>
<div>固件版本{{ prtFWVer }}</div>
<div>打印状态{{ prtStatusDesc }}</div>
</div>
<div class="log-list">
<div
v-for="(log, i) in logs"
:key="i"
:class="['log-item', { 'log-error': log.type === 'error' }]"
>
<span class="log-time">{{ log.time }}</span>
<span class="log-text">{{ log.text }}</span>
</div>
</div>
</div>
</el-drawer>
</div>
</template>
<script>
import { sendPostRequestApi } from '@/api/print'
import { show as getMaterialInfo } from '@/api/inventory'
export default {
data() {
return {
connectRes: '', //
tempRes: '', //
prtSN: '', //
prtFWVer: '', //
prtStatusDesc: '', //
ids: [], // ID
materialList: [], //
imgList: [], //
showLogDrawer: false,
logs: [] // { type: 'success'|'error'|'info', text: string, time: 'HH:mm:ss' }
}
},
async created() {
if (this.$route.query.ids) {
this.ids = this.$route.query.ids.split(',')
} else {
this.$message.error('请先选择物资')
return
}
//
await this.getInfo()
//
await this.setTemplatePrint()
//
await this.getAllMaterialInfo()
//
await this.changeLabelValue(false)
},
methods: {
//
addLog(type, text) {
const two = (n) => (n < 10 ? '0' + n : '' + n)
const d = new Date()
const time = `${two(d.getHours())}:${two(d.getMinutes())}:${two(d.getSeconds())}`
this.logs.push({ type, text, time })
},
//
async sendPostRequest(funcId, funcName, data) {
const res = await sendPostRequestApi(funcId, funcName, data)
if (res.rtnCode === '0') {
this.$message.success(funcName + '成功')
this.addLog('success', funcName + '成功')
return res.outParams ? res.outParams : true
} else {
this.$message.error(funcName + '失败:' + res.rsltMsg)
this.addLog('error', funcName + '失败:' + res.rsltMsg)
return false
}
},
//
async getInfo() {
try {
await this.sendPostRequest('web_DSTP2x_SetLibLang', '设置语言', { language: '0' })
//
const devRes = await this.sendPostRequest('web_DSTP2x_EnumDev', '枚举设备', {
enumType: '1'
})
console.log('devRes', devRes)
const index = devRes.enumList.indexOf(',')
if (index !== -1) {
const devList = devRes.enumList.split(',')
devRes.enumList = devList[0]
}
//
this.connectRes = await this.sendPostRequest('web_DSTP2x_ConnEnumeratedDev', '连接设备', {
devName: devRes.enumList
})
//
const snRes = await this.sendPostRequest('web_DSTP2x_GetPrtSN', '获取打印机序列号', {
devHdl: this.connectRes.devHdl
})
if (snRes.prtSN) {
this.prtSN = snRes.prtSN
}
//
const fwVerRes = await this.sendPostRequest('web_DSTP2x_GetPrtFWVer', '获取固件版本', {
devHdl: this.connectRes.devHdl
})
if (fwVerRes.prtFWVer) {
this.prtFWVer = fwVerRes.prtFWVer
}
//
const statusRes = await this.sendPostRequest('web_DSTP2x_GetPrtStatus', '获取打印状态', {
devHdl: this.connectRes.devHdl
})
if (statusRes.prtStatusDesc) {
const statusStr = this.getAllStatus(
statusRes.mainStatusCode,
statusRes.warnCode,
statusRes.errorCode
)
this.prtStatusDesc = statusRes.prtStatusDesc + '\n' + statusStr
}
//仿
await this.sendPostRequest('web_DSTP2x_SetPrnEmulation', '设置仿真类型', {
devHdl: this.connectRes.devHdl,
emulation: '0'
})
console.log('设置仿真类型成功')
//
await this.sendPostRequest('web_DSTP2x_SetCommTimeout', '设置超时时间', {
devHdl: this.connectRes.devHdl,
commType: '1',
sendTimeout: '20000',
recvTimeout: '20000'
})
console.log('设置超时时间成功')
// sendPostRequest
this.$message.success('获取打印机成功')
} catch (error) {
this.$message.error(error || '请求失败')
}
},
//
async setTemplatePrint() {
//
this.tempRes = await this.sendPostRequest('web_DSTP2x_LoadLabelTmpl', '加载模板', {
tmplFileSrcType: '2',
tmplFileSrc: 'http://192.168.60.99:8004/inventorys1.dlt'
})
if (this.tempRes) {
this.$message.success('加载模板成功')
// id
await this.sendPostRequest('web_DSTP2x_GetTmplAllIDValues', '获取模板的所有 id', {
tmplHdl: this.tempRes.tmplHdl,
cInterval: '64',
nType: '0'
})
//
const printModeRes = await this.sendPostRequest(
'web_DSTP2x_SetTmplPrnMode',
'设置标签模板的打印模式',
{
tmplHdl: this.tempRes.tmplHdl,
prnMode: '3'
}
)
console.log('printModeRes', printModeRes)
if (printModeRes) {
this.$message.success('设置标签模板的打印模式成功')
} else {
this.$message.error('设置标签模板的打印模式失败')
}
} else {
this.$message.error('加载模板失败')
}
},
//
async changeLabelValue(isprint) {
//
if (!isprint) {
this.imgList = []
}
for (let index = 0; index < this.materialList.length; index++) {
const item = this.materialList[index]
const pici = item.rukupici ? '批次:' + item.rukupici : '批次:'
const total_num =
item.wuzileixing === '一物一码'
? '同批数量:' + item.total_num
: '数量:' + item.total_num
const piciNum = pici + ' ' + total_num
const shunxuhao = item.wuzileixing === '一物一码' ? '批内序号:' + item.shunxuhao : ' '
//
let hexId = parseInt(item.id, 10).toString(16).toUpperCase()
if (hexId.length % 2 !== 0) {
hexId = '0' + hexId
}
console.log('item.id:', item.id, 'hexId:', hexId)
await this.sendPostRequest('web_DSTP2x_SetTmplValByKey_Multiple', '设置模板', [
{ tmplHdl: this.tempRes.tmplHdl, elemID: 'date', elemKey: 'Data', elemValue: this.$moment(new Date()).format('YYYY-MM-DD') },
// { tmplHdl: this.tempRes.tmplHdl, elemID: 'date', elemKey: 'xLine', elemValue: '10.0' },
{ tmplHdl: this.tempRes.tmplHdl, elemID: 'chanquan', elemKey: 'Data', elemValue: item.chanquanxinxi_detail ? item.chanquanxinxi_detail.value : '市河道处' },
{ tmplHdl: this.tempRes.tmplHdl, elemID: 'code', elemKey: 'Data', elemValue: item.id },
{ tmplHdl: this.tempRes.tmplHdl, elemID: 'material_info_type', elemKey: 'Data', elemValue: item.material_info_type ? '类别:' + item.material_info_type : '类别:' },
{ tmplHdl: this.tempRes.tmplHdl, elemID: 'zichanmingcheng', elemKey: 'Data', elemValue: item.zichanmingcheng ? '物资名称:' + item.zichanmingcheng : '物资名称:' },
{ tmplHdl: this.tempRes.tmplHdl, elemID: 'guige', elemKey: 'Data', elemValue: item.wuziguige ? '规格:' + item.wuziguige : '规格:' },
{ tmplHdl: this.tempRes.tmplHdl, elemID: 'xinghao', elemKey: 'Data', elemValue: item.guigexinghao ? '型号:' + item.guigexinghao : '型号:' },
{ tmplHdl: this.tempRes.tmplHdl, elemID: 'pici', elemKey: 'Data', elemValue: piciNum },
{ tmplHdl: this.tempRes.tmplHdl, elemID: 'shunxuhao', elemKey: 'Data', elemValue: shunxuhao },
{ tmplHdl: this.tempRes.tmplHdl, elemID: 'EPC', elemKey: 'Data', elemValue: hexId }
// { tmplHdl: this.tempRes.tmplHdl, elemID: 'date', elemKey: 'FontSize', elemValue: '9.0' },
// { tmplHdl: this.tempRes.tmplHdl, elemID: 'chanquan', elemKey: 'FontSize', elemValue: '9.0' },
// { tmplHdl: this.tempRes.tmplHdl, elemID: 'code', elemKey: 'FontSize', elemValue: '9.0' },
// { tmplHdl: this.tempRes.tmplHdl, elemID: 'material_info_type', elemKey: 'FontSize', elemValue: '9.0' },
// { tmplHdl: this.tempRes.tmplHdl, elemID: 'zichanmingcheng', elemKey: 'FontSize', elemValue: '9.0' },
// { tmplHdl: this.tempRes.tmplHdl, elemID: 'guige', elemKey: 'FontSize', elemValue: '9.0' },
// { tmplHdl: this.tempRes.tmplHdl, elemID: 'xinghao', elemKey: 'FontSize', elemValue: '9.0' },
// { tmplHdl: this.tempRes.tmplHdl, elemID: 'pici', elemKey: 'FontSize', elemValue: '9.0' },
// { tmplHdl: this.tempRes.tmplHdl, elemID: 'shunxuhao', elemKey: 'FontSize', elemValue: '9.0' },
// { tmplHdl: this.tempRes.tmplHdl, elemID: 'EPC', elemKey: 'FontSize', elemValue: '9.0' },
])
const printRes = await this.sendPostRequest('web_DSTP2x_PrintTmpl', `${index + 1}次打印`, {
devHdl: this.connectRes.devHdl,
tmplHdl: this.tempRes.tmplHdl,
outFileType: '1'
})
if (printRes) {
if (!isprint) {
this.imgList.push(printRes.outFile)
//
this.addLog('success', `${index + 1}次生成预览图片成功`)
}
}
}
if (isprint) {
//
await this.sendPostRequest('web_DSTP2x_DeleteTmpl', '删除模板句柄', { tmplHdl: this.tempRes.tmplHdl })
await this.sendPostRequest('web_DSTP2x_DisconnDev', '断开连接', { devHdl: this.connectRes.devHdl })
this.$message.success('打印模板成功')
this.$message.success('断开连接成功')
}
},
//
async batchPrint() {
await this.sendPostRequest('web_DSTP2x_SetTmplPrnMode', '设置标签模板的打印模式', {
tmplHdl: this.tempRes.tmplHdl,
prnMode: '0'
})
await this.changeLabelValue(true)
},
//
async getAllMaterialInfo() {
try {
this.materialList = []
for (const id of this.ids) {
const materialInfo = await this.getMaterialInfo(id)
if (materialInfo) {
this.materialList.push(materialInfo)
}
}
console.log('所有物资信息:', this.materialList)
this.$message.success(`已获取 ${this.materialList.length} 条物资信息`)
} catch (error) {
console.error('获取物资信息失败:', error)
this.$message.error('获取物资信息失败')
}
},
//
async getMaterialInfo(id) {
try {
const res = await getMaterialInfo({ id: id })
if (res) {
return res
}
return null
} catch (error) {
console.error(`获取物资 ${id} 详情失败:`, error)
return null
}
},
//
getAllStatus(mainStatus, warnStatus, errStatus) {
const mainStatusGroup = [
'Device idle',
'Device busy',
'Cache is not empty',
'Cache is empty',
'The panel is in the set state',
'Label reading and writing completed',
'The retry and invalidation process is in progress',
'The make-up printing process is in progress',
'RFID automatic verification in progress',
'RFID custom command in progress',
'No RFID module'
]
const warnStatusGroup = ['Paper is about to run out']
const errStatusGroup = [
'Label or black label positioning error',
'Paper jam',
'Paper tearing error',
'Lack of paper',
'Knife error',
'Paper loading error',
'Carbon tape error',
'Lifting the print head',
'Printing head overheating',
'EPC data missing in print data',
'RFID re printing failed',
'RFID calibration failed',
'RFID error',
'Pause or offline'
]
const mainStatusArr = mainStatus.split(',')
const warnStatusArr = warnStatus.split(',')
const errStatusArr = errStatus.split(',')
let rtnStr = '主状态: '
for (let i = 0; i < mainStatusArr.length; i++) {
const idx = mainStatusArr[i] - 1
rtnStr += mainStatusGroup[idx]
rtnStr += '; '
}
if (warnStatus && warnStatusArr.length > 0) {
rtnStr += '警告状态: '
for (let i = 0; i < warnStatusArr.length; i++) {
const idx = warnStatusArr[i] - 1
rtnStr += warnStatusGroup[idx]
rtnStr += '; '
}
}
if (errStatus && errStatusArr.length > 0) {
rtnStr += '错误状态: '
for (let i = 0; i < errStatusArr.length; i++) {
const idx = errStatusArr[i] - 1
rtnStr += errStatusGroup[idx]
rtnStr += '; '
}
}
return rtnStr
}
}
}
</script>
<style scoped>
.wrap{
padding:40px
}
.log-drawer-content{
padding:0 20px 20px 20px;
font-size: 16px;
}
.print-preview-title {
font-size: 20px;
font-weight: bold;
margin-bottom: 10px;
}
.print-preview-img {
width: 320px;
height: 160px;
}
.print-preview-img-box {
display: flex;
flex-wrap: wrap;
gap: 10px;
}
.batch-print-btn {
margin-bottom: 10px;
}
.log-list {
max-height: calc(100vh - 240px);
overflow-y: auto;
}
.log-item {
display: flex;
align-items: center;
line-height: 24px;
}
.log-time {
color: #909399;
font-size: 12px;
}
.log-text {
margin-left: 8px;
}
.log-error .log-text {
color: #f56c6c;
}
</style>

@ -0,0 +1,534 @@
<template>
<div class="wrap">
<!-- <h1>打印机序号{{ prtSN }}</h1>
<h1>固件版本{{ prtFWVer }}</h1>
<h1>打印状态{{ prtStatusDesc }}</h1> -->
<div v-if="imgList.length > 0">
<div class="batch-print-btn">
<el-button type="primary" @click="batchPrint"></el-button>
<el-button type="primary" @click="showLogDrawer = true">打印日志</el-button>
</div>
<div class="print-preview-title">打印预览</div>
<div class="print-preview-img-box">
<img :src="img" class="print-preview-img" v-for="(img, index) in imgList" :key="index" />
</div>
</div>
<!-- <el-button @click="setTemplatePrint"></el-button> -->
<el-drawer
title="打印日志"
:visible.sync="showLogDrawer"
direction="rtl"
size="50%"
:with-header="true"
>
<div class="log-drawer-content">
<div style="margin-bottom: 10px">
<div>打印机序号{{ prtSN }}</div>
<div>固件版本{{ prtFWVer }}</div>
<div>打印状态{{ prtStatusDesc }}</div>
</div>
<div class="log-list">
<div
v-for="(log, i) in logs"
:key="i"
:class="['log-item', { 'log-error': log.type === 'error' }]"
>
<span class="log-time">{{ log.time }}</span>
<span class="log-text">{{ log.text }}</span>
</div>
</div>
</div>
</el-drawer>
</div>
</template>
<script>
import { sendPostRequestApi } from '@/api/print'
import { show as getMaterialInfo } from '@/api/inventory'
export default {
data() {
return {
connectRes: '', //
labelContent: '', //
prtSN: '', //
prtFWVer: '', //
prtStatusDesc: '', //
ids: [], // ID
materialList: [], //
imgList: [], //
showLogDrawer: false,
logs: [] // { type: 'success'|'error'|'info', text: string, time: 'HH:mm:ss' }
}
},
async created() {
if (this.$route.query.ids) {
this.ids = this.$route.query.ids.split(',')
} else {
this.$message.error('请先选择物资')
return
}
//
await this.getInfo()
//
// await this.setTemplatePrint()
//
await this.getAllMaterialInfo()
//
await this.changeLabelValue(false)
},
methods: {
//
addLog(type, text) {
const two = n => (n < 10 ? '0' + n : '' + n)
const d = new Date()
const time = `${two(d.getHours())}:${two(d.getMinutes())}:${two(d.getSeconds())}`
this.logs.push({ type, text, time })
},
//
async sendPostRequest(funcId, funcName, data, showMessage = false) {
const res = await sendPostRequestApi(funcId, funcName, data)
if (res.rtnCode === '0') {
if (showMessage) {
this.$message.success(funcName + '成功')
}
this.addLog('success', funcName + '成功')
return res.outParams ? res.outParams : true
} else {
this.$message.error(funcName + '失败:' + res.rsltMsg)
this.addLog('error', funcName + '失败:' + res.rsltMsg)
return false
}
},
// height
getHeight(text) {
console.log('text', text)
console.log('text.length', text.length)
return text && text.length > 14 ? 8 : 4
},
//
async getInfo() {
try {
await this.sendPostRequest('web_DSTP2x_SetLibLang', '设置语言', { language: '0' }, true)
//
const devRes = await this.sendPostRequest('web_DSTP2x_EnumDev', '获取打印设备', {
enumType: '1'
}, true)
console.log('devRes', devRes)
const index = devRes.enumList.indexOf(',')
if (index !== -1) {
const devList = devRes.enumList.split(',')
devRes.enumList = devList[0]
}
//
this.connectRes = await this.sendPostRequest('web_DSTP2x_ConnEnumeratedDev', '连接打印设备', {
devName: devRes.enumList
}, true)
//
const snRes = await this.sendPostRequest('web_DSTP2x_GetPrtSN', '获取打印机序列号', {
devHdl: this.connectRes.devHdl
})
if (snRes.prtSN) {
this.prtSN = snRes.prtSN
}
//
const fwVerRes = await this.sendPostRequest('web_DSTP2x_GetPrtFWVer', '获取固件版本', {
devHdl: this.connectRes.devHdl
})
if (fwVerRes.prtFWVer) {
this.prtFWVer = fwVerRes.prtFWVer
}
//
const statusRes = await this.sendPostRequest('web_DSTP2x_GetPrtStatus', '获取打印状态', {
devHdl: this.connectRes.devHdl
}, true)
if (statusRes.prtStatusDesc) {
const statusStr = this.getAllStatus(
statusRes.mainStatusCode,
statusRes.warnCode,
statusRes.errorCode
)
this.prtStatusDesc = statusRes.prtStatusDesc + '\n' + statusStr
}
// 仿
await this.sendPostRequest('web_DSTP2x_SetPrnEmulation', '设置仿真类型', {
devHdl: this.connectRes.devHdl,
emulation: '0'
})
console.log('设置仿真类型成功')
//
await this.sendPostRequest('web_DSTP2x_SetCommTimeout', '设置超时时间', {
devHdl: this.connectRes.devHdl,
commType: '1',
sendTimeout: '20000',
recvTimeout: '20000'
})
console.log('设置超时时间成功')
// sendPostRequest
this.$message.success('连接打印机成功')
} catch (error) {
this.$message.error(error || '请求失败')
}
},
//
async setTemplatePrint(isprint) {
//
this.labelContent = await this.sendPostRequest('web_DSTP2x_CreateLabelContext', '创建画布', {
width: '80',
height: '40'
}, true)
if (this.labelContent) {
//
await this.sendPostRequest('web_DSTP2x_LcDraw_SetTextFontSize', '设置文本字体', {
lcHdl: this.labelContent.lcHdl,
fontSize: '10.0',
temporary: '0'
})
//
await this.sendPostRequest('web_DSTP2x_LcDraw_SetTextFontName', '设置文本字体名称', {
lcHdl: this.labelContent.lcHdl,
temporary: '0',
fontName: '宋体'
})
//
await this.sendPostRequest(
'web_DSTP2x_LcDraw_SetTextAutoLineFeed',
'设置文本是否自动换行',
{
lcHdl: this.labelContent.lcHdl,
isAutoLineFeed: '1',
temporary: '0'
}
)
//
await this.sendPostRequest(
'web_DSTP2x_SetLcPrnMode',
'设置标签画布的打印模式',
{
lcHdl: this.labelContent.lcHdl,
prnMode: isprint ? '0' : '3'
}, true
)
} else {
this.$message.error('创建画布失败')
}
},
//
async changeLabelValue(isprint) {
if (!isprint) {
this.imgList = []
}
for (let index = 0; index < this.materialList.length; index++) {
//
await this.setTemplatePrint(isprint)
const item = this.materialList[index]
const date = this.$moment(new Date()).format('YYYY-MM-DD')
const chanquan = item.chanquanxinxi_detail ? item.chanquanxinxi_detail.value : '市河道处'
const code = item.id + ''
const material_info_type = item.material_info_type
? '类别:' + item.material_info_type
: '类别'
const zichanmingcheng = item.zichanmingcheng
? '物资名称:' + item.zichanmingcheng
: '物资名称'
const guige = item.wuziguige ? '规格:' + item.wuziguige : '规格'
const xinghao = item.guigexinghao ? '型号:' + item.guigexinghao : '型号'
const pici = item.rukupici ? '批次:' + item.rukupici : '批次'
const total_num =
item.wuzileixing === '一物一码' ? '同批数量:' + item.total_num : '数量:' + item.total_num
const piciNum = pici + ' ' + total_num
const shunxuhao = item.wuzileixing === '一物一码' ? '批内序号:' + item.shunxuhao : ' '
let hexId = parseInt(item.id, 10).toString(16).toUpperCase()
if (hexId.length % 2 !== 0) {
hexId = '0' + hexId
}
//
//
await this.sendPostRequest('web_DSTP2x_Lbl_DrawText', '设置日期文本内容', {
lcHdl: this.labelContent.lcHdl,
x: '4',
y: '2',
w: '19',
h: '4',
data: date
})
//
await this.sendPostRequest('web_DSTP2x_Lbl_DrawText', '设置渠道文本内容', {
lcHdl: this.labelContent.lcHdl,
x: '36',
y: '2',
w: '30',
h: '4',
data: chanquan
})
// ID
await this.sendPostRequest('web_DSTP2x_Lbl_DrawBarCode', '设置二维码文本内容', {
lcHdl: this.labelContent.lcHdl,
x: '4',
y: '7',
w: '28',
h: '28',
codeType: '58',
data: code
})
// y height
// - y 7
let currentY = 7
const materialInfoTypeHeight = this.getHeight(material_info_type)
await this.sendPostRequest('web_DSTP2x_Lbl_DrawText', '设置物资类别文本内容', {
lcHdl: this.labelContent.lcHdl,
x: '34',
y: currentY.toString(),
w: '47',
h: materialInfoTypeHeight.toString(),
data: material_info_type
})
currentY = currentY + materialInfoTypeHeight
//
const zichanmingchengHeight = this.getHeight(zichanmingcheng)
await this.sendPostRequest('web_DSTP2x_Lbl_DrawText', '设置物资名称文本内容', {
lcHdl: this.labelContent.lcHdl,
x: '34',
y: currentY.toString(),
w: '46',
h: zichanmingchengHeight.toString(),
data: zichanmingcheng
})
currentY = currentY + zichanmingchengHeight
//
const guigeHeight = this.getHeight(guige)
await this.sendPostRequest('web_DSTP2x_Lbl_DrawText', '设置物资规格文本内容', {
lcHdl: this.labelContent.lcHdl,
x: '34',
y: currentY.toString(),
w: '46',
h: guigeHeight.toString(),
data: guige
})
currentY = currentY + guigeHeight
//
const xinghaoHeight = this.getHeight(xinghao)
await this.sendPostRequest('web_DSTP2x_Lbl_DrawText', '设置物资型号文本内容', {
lcHdl: this.labelContent.lcHdl,
x: '34',
y: currentY.toString(),
w: '46',
h: xinghaoHeight.toString(),
data: xinghao
})
currentY = currentY + xinghaoHeight
//
const piciNumHeight = 4
await this.sendPostRequest('web_DSTP2x_Lbl_DrawText', '设置批次文本内容', {
lcHdl: this.labelContent.lcHdl,
x: '34',
y: currentY.toString(),
w: '46',
h: piciNumHeight.toString(),
data: piciNum
})
currentY = currentY + piciNumHeight
//
const shunxuhaoHeight = 4
await this.sendPostRequest('web_DSTP2x_Lbl_DrawText', '设置批内序号文本内容', {
lcHdl: this.labelContent.lcHdl,
x: '34',
y: currentY.toString(),
w: '46',
h: shunxuhaoHeight.toString(),
data: shunxuhao
})
// EPC
await this.sendPostRequest('web_DSTP2x_LcRfid_SetData', '设置EPC文本内容', {
lcHdl: this.labelContent.lcHdl,
rfidRgnType: '1',
rfidDataFmt: '2',
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)
if (printRes) {
if (!isprint) {
this.imgList.push(printRes.outFile)
//
this.addLog('success', `${index + 1}次生成预览图片成功`)
}
}
//
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)
}
},
//
async batchPrint() {
// await this.sendPostRequest('web_DSTP2x_SetLcPrnMode', '', {
// lcHdl: this.labelContent.lcHdl,
// prnMode: '0'
// })
await this.changeLabelValue(true)
},
//
async getAllMaterialInfo() {
try {
this.materialList = []
for (const id of this.ids) {
const materialInfo = await this.getMaterialInfo(id)
if (materialInfo) {
this.materialList.push(materialInfo)
}
}
console.log('所有物资信息:', this.materialList)
this.$message.success(`已获取 ${this.materialList.length} 条物资信息`)
} catch (error) {
console.error('获取物资信息失败:', error)
this.$message.error('获取物资信息失败')
}
},
//
async getMaterialInfo(id) {
try {
const res = await getMaterialInfo({ id: id })
if (res) {
return res
}
return null
} catch (error) {
console.error(`获取物资 ${id} 详情失败:`, error)
return null
}
},
//
getAllStatus(mainStatus, warnStatus, errStatus) {
const mainStatusGroup = [
'Device idle',
'Device busy',
'Cache is not empty',
'Cache is empty',
'The panel is in the set state',
'Label reading and writing completed',
'The retry and invalidation process is in progress',
'The make-up printing process is in progress',
'RFID automatic verification in progress',
'RFID custom command in progress',
'No RFID module'
]
const warnStatusGroup = ['Paper is about to run out']
const errStatusGroup = [
'Label or black label positioning error',
'Paper jam',
'Paper tearing error',
'Lack of paper',
'Knife error',
'Paper loading error',
'Carbon tape error',
'Lifting the print head',
'Printing head overheating',
'EPC data missing in print data',
'RFID re printing failed',
'RFID calibration failed',
'RFID error',
'Pause or offline'
]
const mainStatusArr = mainStatus.split(',')
const warnStatusArr = warnStatus.split(',')
const errStatusArr = errStatus.split(',')
let rtnStr = '主状态: '
for (let i = 0; i < mainStatusArr.length; i++) {
const idx = mainStatusArr[i] - 1
rtnStr += mainStatusGroup[idx]
rtnStr += '; '
}
if (warnStatus && warnStatusArr.length > 0) {
rtnStr += '警告状态: '
for (let i = 0; i < warnStatusArr.length; i++) {
const idx = warnStatusArr[i] - 1
rtnStr += warnStatusGroup[idx]
rtnStr += '; '
}
}
if (errStatus && errStatusArr.length > 0) {
rtnStr += '错误状态: '
for (let i = 0; i < errStatusArr.length; i++) {
const idx = errStatusArr[i] - 1
rtnStr += errStatusGroup[idx]
rtnStr += '; '
}
}
return rtnStr
}
}
}
</script>
<style scoped>
.wrap {
padding: 40px;
}
.log-drawer-content {
padding: 0 20px 20px 20px;
font-size: 16px;
}
.print-preview-title {
font-size: 20px;
font-weight: bold;
margin-bottom: 10px;
}
.print-preview-img {
width: 320px;
height: 160px;
}
.print-preview-img-box {
display: flex;
flex-wrap: wrap;
gap: 10px;
}
.batch-print-btn {
margin-bottom: 10px;
}
.log-list {
max-height: calc(100vh - 240px);
overflow-y: auto;
}
.log-item {
display: flex;
align-items: center;
line-height: 24px;
}
.log-time {
color: #909399;
font-size: 12px;
}
.log-text {
margin-left: 8px;
}
.log-error .log-text {
color: #f56c6c;
}
</style>

@ -37,10 +37,9 @@
<div v-else>
<template v-for="(item,index) in fileList">
<div :key="index" style="display:inline-flex;align-items:center;margin:6px 10px 6px 0;">
<div>
<a :href="item.url" target="_blank" style="color:#409EFF;text-decoration:none;">
{{ item.original_name}}
{{ item.name}}
</a>
</div>
</div>

@ -101,8 +101,8 @@
} from '@/api/system/baseForm.js'
import addRuku from './component/addRuku.vue'
import showRuku from './component/showRuku.vue'
import {
delStock
import {
delStock
} from '@/api/stocks.js'
import {
getOatoken
@ -261,15 +261,15 @@
]
}
},
mounted() {
if(this.$route.query.oaType==='wuzi'){
this.editorRuku('','add',this.$route.query.rukuType)
mounted() {
if(this.$route.query.oaType==='wuzi'){
this.editorRuku('','add',this.$route.query.rukuType)
}
this.getUserName()
this.getindex()
getOatoken().then(res => {
this.wuziguanli_oatoken = res.oatoken
})
})
},
methods: {
@ -341,25 +341,25 @@
if (k == type) {
typeid = parseInt(typeObj[k])
}
}
}
let default_json = {
stocks_id:res.id,
xiangguanliucheng:res.xiangguanliucheng,
let default_json = {
stocks_id:res.id,
xiangguanliucheng:res.xiangguanliucheng,
// xiangguanliucheng:res.link_id,
rukuriqi:res.rukushijian,
jingbanren:res.jingbanren,
jiluren:res.jilurenyuan,
baoguanren:res.baoguanrenyuan,
remark:res.beizhu,
rukuriqi:res.rukushijian,
jingbanren:res.jingbanren,
jiluren:res.jilurenyuan,
baoguanren:res.baoguanrenyuan,
remark:res.beizhu,
huowudan:res.zuozhengwenjian.join(",")
}
const url =
`${process.env.VUE_APP_OA_URL}/admin/flow/create/${typeid}?wuziguanli_oatoken=${this.wuziguanli_oatoken}&stocks_id=${res.id}&default_json=${JSON.stringify(default_json)}`
const seeBuy = window.open(url, '_blank')
if(this.$route.query.oaType==='wuzi'){
window.history.back()
const seeBuy = window.open(url, '_blank')
if(this.$route.query.oaType==='wuzi'){
window.history.back()
}
},
deleteRuku(row) {
@ -388,4 +388,4 @@
margin-right: 10px;
}
}
</style>
</style>

@ -58,6 +58,13 @@ module.exports = {
pathRewrite: {
['^' + process.env.VUE_APP_BASE_API]: process.env.VUE_APP_BASE_API
}
},
'/print': {
target: 'http://127.0.0.1:9001', // 目标接口地址
changeOrigin: true, // 开启代理,模拟同源请求
pathRewrite: {
'^/print': '' // 去掉请求路径中的 /print 前缀(如果接口本身没有 /print
}
}
}
},

Loading…
Cancel
Save