feat(traycode): 优化托盘码生成逻辑并调整打印样式

- 移除旧的条码生成逻辑,使用新的序列规则生成托盘码
- 引入条码格式服务以支持更灵活的编码规则
- 更新前端打印模板,使用CODE39条形码替代二维码
- 调整打印页面尺寸为80mm x 50mm以适配标签打印机
- 修改CSS样式以提高打印质量,避免缩放导致的模糊问题
- 更新依赖包,添加vue-barcode库支持条形码渲染
This commit is contained in:
liuhanqing
2025-12-11 17:14:08 +08:00
parent 4e9dbfba27
commit 8fdc98f0c3
5 changed files with 89 additions and 38 deletions

View File

@@ -1,9 +1,12 @@
package com.ruoyi.bas.traycode.service.impl;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.convert.Convert;
import com.ruoyi.bas.traycode.domain.BasTraycode;
import com.ruoyi.bas.traycode.mapper.BasTraycodeMapper;
import com.ruoyi.bas.traycode.service.IBasTraycodeService;
import com.ruoyi.bas.traycodeformat.domain.BasTraycodeFormat;
import com.ruoyi.bas.traycodeformat.service.IBasTraycodeFormatService;
import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@@ -21,6 +24,8 @@ public class BasTraycodeServiceImpl implements IBasTraycodeService
{
@Autowired
private BasTraycodeMapper basTraycodeMapper;
@Autowired
private IBasTraycodeFormatService basTraycodeFormatService;
/**
* 查询条码信息
@@ -56,24 +61,28 @@ public class BasTraycodeServiceImpl implements IBasTraycodeService
public int insertBasTraycode(BasTraycode basTraycode)
{
try {
Integer i = basTraycodeMapper.selectBasTrayCodeMax();
if (i == null) {
i = 0;
}
BasTraycodeFormat basTraycodeFormat = basTraycodeFormatService.selectBasTraycodeFormatById(basTraycode.getFormatId());
int i1 = Integer.parseInt(basTraycode.getSpare1());
//如果i<4位数,前面补0
String code = "";
for (int j = 0; j < i1; j++) {
code = String.format("%04d", i + 1 + j);
if("9999".equals( code)){
code = String.format("%07d",Convert.toInt( basTraycodeFormat.getSerialRule()) + 1 + j);
if(basTraycodeFormat.getMaxNum() < Convert.toLong( code)){
throw new RuntimeException("已生成最大值");
}
basTraycode.setTrayCode(code);
String finalCode = basTraycodeFormat.getBarcodeFormat()+code;
basTraycode.setTrayCode(finalCode);
basTraycode.setSpare1(null);
basTraycode.setCreateTime(DateUtils.getNowDate());
basTraycode.setSpare2("Y");
basTraycodeMapper.insertBasTraycode(basTraycode);
}
basTraycodeFormat.setSerialRule(Convert.toLong( code).toString());
basTraycodeFormatService.updateBasTraycodeFormat(basTraycodeFormat);
} catch (Exception e) {
throw new RuntimeException(e);
}

View File

@@ -79,20 +79,7 @@ public class BasTraycodeFormatServiceImpl implements IBasTraycodeFormatService
public int updateBasTraycodeFormat(BasTraycodeFormat basTraycodeFormat)
{
BasTraycodeFormat old = selectBasTraycodeFormatById(basTraycodeFormat.getId());
int oldSerialRule = Convert.toInt(old.getSerialRule());
int newSerialRule = Convert.toInt(basTraycodeFormat.getSerialRule());
List<BasTraycode> traycodeList = new ArrayList<>();
for (int i = oldSerialRule; i < newSerialRule; i++) {
BasTraycode basTraycode = new BasTraycode();
basTraycode.setFormatId(basTraycodeFormat.getId());
String traycode = old.getBarcodeFormat()+ StrUtil.padPre(Convert.toStr(i),5,'0');
basTraycode.setTrayCode(traycode);
traycodeList.add(basTraycode);
}
basTraycodeFormat.setUpdateTime(DateUtils.getNowDate());
//插入条码信息
basTraycodeService.insertBasTraycodeList(traycodeList);
return basTraycodeFormatMapper.updateBasTraycodeFormat(basTraycodeFormat);
}

View File

@@ -44,6 +44,7 @@
"sortablejs": "1.10.2",
"splitpanes": "2.4.1",
"vue": "2.6.12",
"vue-barcode": "^1.3.0",
"vue-count-to": "1.0.13",
"vue-cropper": "0.5.5",
"vue-easy-print": "^0.0.8",

View File

@@ -103,7 +103,7 @@
<div class="qrcode-container">
<vue-qr
:text="qrCodeValue"
:size="180"
:size="80"
:margin="0"
:correctLevel="2"
error-correction-level="M"
@@ -116,8 +116,8 @@
<!-- 打印专用区域(隐藏) -->
<vue-easy-print style="display: none;" ref="easyPrint2">
<div class="vue-easy-print" style="page-break-after:always">
<div class="label-content">
<div class="vue-easy-print">
<div class="print-label">
<div class="preview-box">
<div class="preview-content">
<div class="preview-row">
@@ -158,10 +158,10 @@
</div>
</div>
<!-- 二维码区域 -->
<div class="qrcode-container">
<div class="qrcode-container" style="top:2mm;right:2mm;">
<vue-qr
:text="qrCodeValue"
:size="180"
:size="120"
:margin="0"
:correctLevel="2"
error-correction-level="M"
@@ -969,7 +969,7 @@ export default {
}
.preview-display {
padding: 0 20px 20px;
padding: 0 10px 10px;
}
.label-content {
@@ -978,6 +978,19 @@ export default {
overflow: hidden;
}
/* 打印单页标签尺寸(按实际贴纸尺寸调整) */
.print-label {
width: 90mm; /* 贴纸宽度 */
height: 30mm; /* 贴纸高度 */
padding: 6mm; /* 安全边距 */
box-sizing: border-box;
display: flex;
align-items: stretch;
background: #fff;
border: 1px solid #e4e7ed;
border-radius: 6px;
}
.preview-box {
padding: 20px;
font-family: 'Arial', sans-serif;
@@ -1103,26 +1116,63 @@ export default {
@media print {
@page {
margin: 0;
size: auto;
size: 90mm 30mm;
}
body {
margin: 0;
}
.vue-easy-print {
width: 90mm;
height: 30mm;
}
.preview-box {
border: none;
box-shadow: none;
position: relative;
width: 100%;
height: 100%;
padding: 0;
display: flex;
flex-direction: row;
}
.preview-content {
margin-right: 38mm;
padding-right: 0;
}
.preview-row {
margin-bottom: 4px;
min-height: auto;
}
.preview-label {
font-size: 14px;
min-width: 10mm;
margin-right: 3px;
}
.preview-value {
font-size: 14px;
}
.qrcode-container {
border: none;
position: absolute !important;
top: 20px !important;
right: 20px !important;
top: 2mm !important;
right: 2mm !important;
padding: 0;
background-color: transparent;
text-align: center;
}
/* 提高打印品质,避免缩放导致模糊 */
* {
-webkit-print-color-adjust: exact;
print-color-adjust: exact;
}
}
</style>

View File

@@ -150,7 +150,7 @@
<!-- 添加或修改条码信息对话框 -->
<el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
<el-form ref="form" :model="form" :rules="rules" label-width="100px">
<!-- <el-form-item label="格式ID" prop="formatId">
<el-form-item label="格式ID" prop="formatId">
<el-select v-model="form.formatId" placeholder="请选择格式ID">
<el-option
v-for="item in traycodeFormatList"
@@ -159,7 +159,7 @@
:value="item.id"
/>
</el-select>
</el-form-item>-->
</el-form-item>
<el-form-item label="数量" prop="spare1" v-if="form.id == null">
<el-input v-model="form.spare1" placeholder="请输入数量" />
@@ -189,10 +189,13 @@
<!-- 打印模板 -->
<vue-easy-print v-show="true" ref="easyPrint2">
<div v-for="item in printData" :key="item.id" style="page-break-after:always" class="vue-easy-print">
<vue-qr :text='item.trayCode' :size="150" :margin="10" :align-item="center" :correctLevel="2"></vue-qr>
<div>
<span class="num">{{ item.trayCode }}</span>
</div>
<vue-barcode
:value=item.trayCode
format="CODE39"
width="2"
height="100"
display-value
/>
</div>
</vue-easy-print>
</div>
@@ -203,14 +206,15 @@ import { listTraycode, getTraycode, delTraycode, addTraycode, updateTraycode } f
import { listTraycodeFormat } from "@/api/bas/traycodeFormat"
import vueEasyPrint from 'vue-easy-print'
import VueQr from 'vue-qr'
import VueBarcode from 'vue-barcode'
export default {
name: "Traycode",
dicts:['sys_yes_no'],
components: {
vueEasyPrint,
VueQr
VueQr,
VueBarcode
},
data() {
return {
@@ -455,7 +459,7 @@ export default {
@media print {
@page {
size: A4;
size: 80mm 50mm;
margin: 0;
}