标签打印

master
lion 11 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