二维码样式更改

This commit is contained in:
Ledo 2025-07-07 23:04:40 +08:00
parent 4194f5e9ee
commit 4577472af4
6 changed files with 196 additions and 224 deletions

View File

@ -51,7 +51,11 @@ const bomCodes = ref('')
const open = async ( vals) => { const open = async ( vals) => {
cnenList.value = vals; const sortedVals = [...vals].sort((a, b) => {
return a.id - b.id;
});
cnenList.value = sortedVals;
specarr.value = [] specarr.value = []
console.log(vals) console.log(vals)
datavals.value = [] datavals.value = []
@ -74,7 +78,9 @@ const open = async ( vals) => {
await Promise.all( await Promise.all(
printCodeName.value.map(async (item) => { printCodeName.value.map(async (item) => {
const qrCodeData = await QRCode.toDataURL(item.name) const qrCodeData = await QRCode.toDataURL(item.name,{
errorCorrectionLevel: 'H'
})
const qrCodeElement = document.getElementById('qrCodeContainer') const qrCodeElement = document.getElementById('qrCodeContainer')
if (qrCodeElement) { if (qrCodeElement) {
(qrCodeElement.innerHTML += (qrCodeElement.innerHTML +=

View File

@ -184,7 +184,9 @@ const open = async ( vals) => {
await Promise.all( await Promise.all(
printCodeName.value.map(async (item) => { printCodeName.value.map(async (item) => {
const qrCodeData = await QRCode.toDataURL(item.name) const qrCodeData = await QRCode.toDataURL(item.name,{
errorCorrectionLevel: 'H'
})
const qrCodeElement = document.getElementById('qrCodeContainer1') const qrCodeElement = document.getElementById('qrCodeContainer1')
if (qrCodeElement) { if (qrCodeElement) {
(qrCodeElement.innerHTML += (qrCodeElement.innerHTML +=

View File

@ -51,14 +51,36 @@ const bomCodes = ref('')
const open = async (bomCode, vals) => { const open = async (bomCode, vals) => {
cnenList.value = vals; const sortedVals = [...vals].sort((a, b) => {
const aParts = a.blueprintNo.split('-').map(part => parseInt(part) || part);
const bParts = b.blueprintNo.split('-').map(part => parseInt(part) || part);
//
for (let i = 0; i < Math.max(aParts.length, bParts.length); i++) {
const aPart = aParts[i] || 0; // 0
const bPart = bParts[i] || 0;
//
if (typeof aPart === 'number' && typeof bPart === 'number') {
if (aPart !== bPart) return aPart - bPart;
}
//
else {
if (aPart !== bPart) return String(aPart).localeCompare(String(bPart));
}
}
//
return a.blueprintNo.localeCompare(b.blueprintNo);
})
cnenList.value = sortedVals;
bomCodes.value = bomCode; bomCodes.value = bomCode;
specarr.value = [] specarr.value = []
console.log(vals)
datavals.value = [] datavals.value = []
printCodeName.value = [] printCodeName.value = []
vals.forEach((item) => { sortedVals.forEach((item) => {
const row = { const row = {
blueprintNo: item.blueprintNo, blueprintNo: item.blueprintNo,
} }
@ -78,7 +100,9 @@ const open = async (bomCode, vals) => {
var i = 0; var i = 0;
await Promise.all( await Promise.all(
printCodeName.value.map(async (item) => { printCodeName.value.map(async (item) => {
const qrCodeData = await QRCode.toDataURL(item.name) const qrCodeData = await QRCode.toDataURL(item.name,{
errorCorrectionLevel: 'H'
})
const qrCodeElement = document.getElementById('qrCodeContainer') const qrCodeElement = document.getElementById('qrCodeContainer')
if (qrCodeElement) { if (qrCodeElement) {
(qrCodeElement.innerHTML += (qrCodeElement.innerHTML +=

View File

@ -188,7 +188,9 @@ const open = async (bomCode, vals) => {
await Promise.all( await Promise.all(
printCodeName.value.map(async (item) => { printCodeName.value.map(async (item) => {
const qrCodeData = await QRCode.toDataURL(item.name) const qrCodeData = await QRCode.toDataURL(item.name,{
errorCorrectionLevel: 'H'
})
const qrCodeElement = document.getElementById('qrCodeContainer1') const qrCodeElement = document.getElementById('qrCodeContainer1')
if (qrCodeElement) { if (qrCodeElement) {
(qrCodeElement.innerHTML += (qrCodeElement.innerHTML +=

View File

@ -10,8 +10,8 @@
<el-button @click="onPrint" type="primary" style="float: right;margin-right: 1%;">打印</el-button> <el-button @click="onPrint" type="primary" style="float: right;margin-right: 1%;">打印</el-button>
<!-- 打印预览 --> <!-- 打印预览 -->
<div class="print-wrap1 page" ref="print"> <div class="print-wrap page" ref="print">
<div id="qrCodeContainer1"></div> <div id="qrCodeContainer"></div>
</div> </div>
<template #footer> <template #footer>
<el-button @click="onPrint" type="primary">打印</el-button> <el-button @click="onPrint" type="primary">打印</el-button>
@ -22,8 +22,7 @@
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { onMounted, nextTick } from 'vue' import QRCode from 'qrcode'
import JsBarcode from 'jsbarcode'
import printFinalDialog from './printFinalDialog.vue'; import printFinalDialog from './printFinalDialog.vue';
const dialogVisible = ref(false) const dialogVisible = ref(false)
let clauseId = null; let clauseId = null;
@ -34,91 +33,6 @@ const onPrint = () => {
printref.value.open(cnenList.value) printref.value.open(cnenList.value)
} }
// const onPrint = () => {
// const printNode = document.querySelector('.print-wrap1')
// if (!printNode) return
// const newIframe: any = document.createElement('iframe')
// newIframe.setAttribute(
// 'style',
// 'width:0px;height:0px;position:absolute;left:-9999px;top:-9999px;'
// )
// document.body.appendChild(newIframe)
// const doc = newIframe.contentWindow.document
// //
// doc.write(`
// <!DOCTYPE html>
// <html>
// <head>
// <style>
// @page {
// size: 45mm 30mm;
// margin: 0;
// }
// body {
// margin: 0;
// padding: 0;
// background-color: black !important;
// color: white !important;
// -webkit-print-color-adjust: exact;
// print-color-adjust: exact;
// }
// .qr-page {
// width: 45mm;
// height: 30mm;
// padding: 2mm;
// box-sizing: border-box;
// font-family: monospace;
// position: relative;
// background-color: black !important;
// color: white !important;
// }
// .code-line {
// width: 100%;
// margin-bottom: 2mm;
// position: relative;
// }
// .code-line span {
// display: inline-block;
// width: 100%;
// border-bottom: 1px solid white;
// padding-bottom: 0.2mm;
// margin-bottom: 0.5mm;
// }
// .barcode-container {
// display: flex;
// justify-content: center;
// margin: 1mm 0;
// }
// .barcode {
// width: 20mm;
// height: 7mm;
// }
// .spec-line, .name-line, .location-line {
// margin-bottom: 1mm;
// font-size: 11px;
// }
// .location-line {
// display: flex;
// justify-content: space-between;
// }
// </style>
// </head>
// <body>
// ${printNode.innerHTML}
// </body>
// </html>
// `)
// doc.close()
// dialogVisible.value = false
// setTimeout(() => {
// newIframe.contentWindow.focus()
// newIframe.contentWindow.print()
// document.body.removeChild(newIframe)
// dialogVisible.value = false
// }, 100)
// }
function beforeDialogClose(doClose: (shouldClose: boolean) => void): void { function beforeDialogClose(doClose: (shouldClose: boolean) => void): void {
outopen() outopen()
@ -130,21 +44,26 @@ const outopen = () => {
const printCodeName = ref([]) const printCodeName = ref([])
const datavals = ref([]) const datavals = ref([])
const specarr = ref([])
const cnenList = ref([]) const cnenList = ref([])
const bomCodes = ref('')
const open = async (vals) => { const open = async (vals) => {
cnenList.value = vals; const sortedVals = [...vals].sort((a, b) => {
specarr.value = [] return b.id - a.id;
console.log(vals) });
cnenList.value = sortedVals;
datavals.value = [] datavals.value = []
printCodeName.value = [] printCodeName.value = []
vals.forEach((item) => { sortedVals.forEach((item) => {
console.log(item.id)
const row1 = { const row1 = {
code: item.matCode, code: item.matCode,
name: item.matName == null ? '' : item.matName, name: item.matName == null ? '' : item.matName,
spec: item.spec == null ? '' : item.spec, spec: item.matSpec == null ? '' : item.matSpec,
rg: item.rgName == null ? '' : item.rgName, rg: item.rgName == null ? '' : item.rgName,
pg: item.pnName == null ? '' : item.pnName, pg: item.pnName == null ? '' : item.pnName,
//amount: item.amount == null ? '' : item.amount //amount: item.amount == null ? '' : item.amount
@ -154,52 +73,45 @@ const open = async (vals) => {
dialogVisible.value = true dialogVisible.value = true
// 使nextTickDOM
await nextTick()
const qrCodeElement = document.getElementById('qrCodeContainer1')
if (!qrCodeElement) return
//
qrCodeElement.innerHTML = ''
var i = 0; var i = 0;
// await Promise.all(
printCodeName.value.forEach((item) => { printCodeName.value.map(async (item) => {
// canvas
const canvas = document.createElement('canvas') const formattedDate = `物料编码:${item.code},规格:${item.spec},简称:${item.name},库区:${item.rg},库位:${item.pg}`;
JsBarcode(canvas, item.code, { const qrCodeData = await QRCode.toDataURL(formattedDate ,{
format: "CODE128", errorCorrectionLevel: 'H'
width: 2,
height: 40,
displayValue: false,
fontSize: 10
}) })
const qrCodeElement = document.getElementById('qrCodeContainer')
const barcodeSrc = canvas.toDataURL('image/png') if (qrCodeElement) {
(qrCodeElement.innerHTML +=
qrCodeElement.innerHTML += `<div style="width: 90mm; height: 60mm; padding: 2mm; box-sizing: border-box; font-family: monospace; position: relative; background-color: black; color: white;">
`<div class="page qr-page"> <div style="font-size: 11px; margin-bottom: 1mm;">
<div class="code-line"> <span style="display: inline-block; width: 100%; border-bottom: 1px solid white; padding-bottom: 0.2mm;">物料编码${item.code}</span>
<span>物料编码${item.code}</span>
</div> </div>
<div class="barcode-container"> <div style="display: flex; align-items: center;">
<img class="barcode" src="${barcodeSrc}" alt="Barcode"> <span style="white-space: nowrap; margin-right: 1mm;">简称:</span>
<span style="flex-grow: 1; border-bottom: 1px solid white; height: 2em; margin-left: 1mm;">${item.name}</span>
</div> </div>
<div class="spec-line">规格: ${item.spec}</div> <div style="display: flex; position: absolute; bottom: 2mm; left: 2mm; right: 2mm; height: 34mm;">
<div class="name-line">简称${item.name}</div> <div style="display: flex; flex-direction: column; justify-content: center; align-items: flex-start; width: 13mm; margin-right: 1mm;">
<div class="location-line"> <span style="font-size: 11px; margin-bottom: 0.5mm; margin-top:2mm; white-space: nowrap;">规格: ${item.spec}</span>
<span>库区${item.rg}</span> <span style="font-size: 11px; margin-bottom: 0.5mm; margin-top:2mm; white-space: nowrap;">库区${item.rg}</span>
<span>库位${item.pg}</span> <span style="font-size: 11px; margin-bottom: 0.5mm; margin-top:2mm; white-space: nowrap;">库位${item.pg}</span>
</div> </div>
</div>` <div style="width: 34mm; height: 34mm; margin-left: auto; display: flex; align-items: flex-end; justify-content: flex-end;">
if(vals.length > 1 && i<=vals.length - 1){ <img style="width: 100%; height: 100%;" src="${qrCodeData}" alt="QR Code">
</div>
</div>
</div>`)
if(printCodeName.value.length > 1 && i < printCodeName.value.length - 1){
qrCodeElement.innerHTML += qrCodeElement.innerHTML +=
`<div style="height:3mm; background-color: white; color: white;width:103mm;margin-left:-3mm"> `<div style="height:3mm; background-color: white; color: white;width:103mm;margin-left:-3mm">
</div>` </div>`
} }
i++; }
}) })
)
} }
defineExpose({ open }) defineExpose({ open })
@ -208,8 +120,8 @@ defineExpose({ open })
<style scoped lang="scss"> <style scoped lang="scss">
/* 预览样式 - 仅用于屏幕显示 */ /* 预览样式 - 仅用于屏幕显示 */
.page { .page {
width: 60mm; width: 100mm;
min-height: 30mm; min-height: 60mm;
margin: auto; margin: auto;
box-shadow: 0 0 5px rgba(0, 0, 0, 0.1); box-shadow: 0 0 5px rgba(0, 0, 0, 0.1);
background-color: black; background-color: black;
@ -218,8 +130,8 @@ defineExpose({ open })
box-sizing: border-box; box-sizing: border-box;
/* 临时隐藏下划线,打印时会显示 */ /* 临时隐藏下划线,打印时会显示 */
.code-line span { .code-line span, .name-underline {
border-bottom: 1px solid transparent; display: none;
} }
} }
@ -229,8 +141,8 @@ defineExpose({ open })
background-color: black !important; background-color: black !important;
color: white !important; color: white !important;
.code-line span { .code-line span, .name-underline {
border-bottom: 1px solid white; display: inline-block;
} }
} }
} }

View File

@ -10,8 +10,8 @@
<el-button @click="onPrint" type="primary" style="float: right;margin-right: 1%;">打印</el-button> <el-button @click="onPrint" type="primary" style="float: right;margin-right: 1%;">打印</el-button>
<!-- 打印预览 --> <!-- 打印预览 -->
<div class="print-wrap2 page" ref="print"> <div class="print-wrap1 page" ref="print">
<div id="qrCodeContainer2"></div> <div id="qrCodeContainer1"></div>
</div> </div>
<template #footer> <template #footer>
<el-button @click="onPrint" type="primary">打印</el-button> <el-button @click="onPrint" type="primary">打印</el-button>
@ -21,8 +21,7 @@
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { onMounted, nextTick } from 'vue' import QRCode from 'qrcode'
import JsBarcode from 'jsbarcode'
const dialogVisible = ref(false) const dialogVisible = ref(false)
let clauseId = null; let clauseId = null;
@ -30,7 +29,7 @@ const startPageNum = ref(0);
const endPageNum = ref(0); const endPageNum = ref(0);
const onPrint = () => { const onPrint = () => {
const printNode = document.querySelector('.print-wrap2') const printNode = document.querySelector('.print-wrap1')
if (!printNode) return if (!printNode) return
const newIframe: any = document.createElement('iframe') const newIframe: any = document.createElement('iframe')
@ -69,34 +68,69 @@ const onPrint = () => {
background-color: black !important; background-color: black !important;
color: white !important; color: white !important;
} }
.code-line { .code-line, .name-line {
width: 100%; font-size: 11px;
margin-bottom: 2mm; margin-bottom: 1mm;
position: relative;
} }
.code-line span { .code-line span {
display: inline-block; display: inline-block;
width: 100%; width: 100%;
border-bottom: 1px solid white; border-bottom: 1px solid white;
padding-bottom: 0.2mm; padding-bottom: 0.2mm;
margin-bottom: 0.5mm;
} }
.barcode-container { .name-line {
display: flex; display: flex;
align-items: center;
}
.name-label {
white-space: nowrap;
margin-right: 1mm;
}
.name-underline {
flex-grow: 1;
border-bottom: 1px solid white;
height: 1em;
margin-left: 1mm;
}
.bottom-section {
display: flex;
position: absolute;
bottom: 2mm;
left: 2mm;
right: 2mm;
height: 17mm;
}
.qr-container {
width: 14mm;
height: 14mm;
margin-left: auto;
display: flex;
align-items: flex-end;
justify-content: flex-end;
}
.qr-code {
width: 100%;
height: 100%;
}
.quantity-container {
display: flex;
flex-direction: column;
justify-content: center; justify-content: center;
margin: 1mm 0; align-items: flex-start;
width: 13mm;
margin-right: 1mm;
} }
.barcode { .quantity {
width: 20mm;
height: 7mm;
}
.spec-line, .name-line, .location-line {
margin-bottom: 1mm;
font-size: 11px; font-size: 11px;
margin-bottom: 0.5mm;
margin-top:2mm;
white-space: nowrap;
} }
.location-line { .timestamp {
display: flex; font-size: 5px;
justify-content: space-between; line-height: 1;
margin-top: auto;
white-space: nowrap;
} }
</style> </style>
</head> </head>
@ -130,64 +164,56 @@ const cnenList = ref([])
const open = async (vals) => { const open = async (vals) => {
cnenList.value = vals; cnenList.value = vals;
specarr.value = []
console.log(vals)
datavals.value = [] datavals.value = []
printCodeName.value = [] printCodeName.value = []
vals.forEach((item) => { vals.forEach((item) => {
console.log(item)
const row1 = { const row1 = {
code: item.matCode, code: item.matCode,
name: item.matName == null ? '' : item.matName, name: item.matName == null ? '' : item.matName,
spec: item.spec == null ? '' : item.spec, spec: item.matSpec == null ? '' : item.matSpec,
rg: item.rgName == null ? '' : item.rgName, rg: item.rgName == null ? '' : item.rgName,
pg: item.pnName == null ? '' : item.pnName, pg: item.pnName == null ? '' : item.pnName,
//amount: item.amount == null ? '' : item.amount //amount: item.amount == null ? '' : item.amount
} }
printCodeName.value.push(row1) printCodeName.value.push(row1)
}) })
dialogVisible.value = true dialogVisible.value = true
// 使nextTickDOM await Promise.all(
await nextTick() printCodeName.value.map(async (item) => {
const formattedDate = `物料编码:${item.code},规格:${item.spec},简称:${item.name},库区:${item.rg},库位:${item.pg}`;
const qrCodeElement = document.getElementById('qrCodeContainer2') const qrCodeData = await QRCode.toDataURL(formattedDate ,{
if (!qrCodeElement) return errorCorrectionLevel: 'H'
//
qrCodeElement.innerHTML = ''
//
printCodeName.value.forEach((item) => {
// canvas
const canvas = document.createElement('canvas')
JsBarcode(canvas, item.code, {
format: "CODE128",
width: 2,
height: 40,
displayValue: false,
fontSize: 10
}) })
const qrCodeElement = document.getElementById('qrCodeContainer1')
const barcodeSrc = canvas.toDataURL('image/png') if (qrCodeElement) {
(qrCodeElement.innerHTML +=
qrCodeElement.innerHTML +=
`<div class="page qr-page"> `<div class="page qr-page">
<div class="code-line"> <div class="code-line">
<span>物料编码${item.code}</span> <span>物料编码${item.code}</span>
</div> </div>
<div class="barcode-container"> <div class="name-line">
<img class="barcode" src="${barcodeSrc}" alt="Barcode"> <span class="name-label">简称:</span>
<span class="name-underline">${item.name}</span>
</div> </div>
<div class="spec-line">规格: ${item.spec}</div> <div class="bottom-section">
<div class="name-line">简称${item.name}</div> <div class="quantity-container">
<div class="location-line"> <span class="quantity">规格: ${item.spec}</span>
<span>库区${item.rg}</span> <span class="quantity">库区: ${item.rg}</span>
<span>库位${item.pg}</span> <span class="quantity">库位: ${item.pg}</span>
</div> </div>
</div>` <div class="qr-container">
<img class="qr-code" src="${qrCodeData}" alt="QR Code">
</div>
</div>
</div>`)
}
}) })
).then(res => {
onPrint() onPrint()
})
} }
defineExpose({ open }) defineExpose({ open })
@ -196,7 +222,7 @@ defineExpose({ open })
<style scoped lang="scss"> <style scoped lang="scss">
/* 预览样式 - 仅用于屏幕显示 */ /* 预览样式 - 仅用于屏幕显示 */
.page { .page {
width: 60mm; width: 45mm;
min-height: 30mm; min-height: 30mm;
margin: auto; margin: auto;
box-shadow: 0 0 5px rgba(0, 0, 0, 0.1); box-shadow: 0 0 5px rgba(0, 0, 0, 0.1);
@ -206,8 +232,8 @@ defineExpose({ open })
box-sizing: border-box; box-sizing: border-box;
/* 临时隐藏下划线,打印时会显示 */ /* 临时隐藏下划线,打印时会显示 */
.code-line span { .code-line span, .name-underline {
border-bottom: 1px solid transparent; display: none;
} }
} }
@ -217,8 +243,8 @@ defineExpose({ open })
background-color: black !important; background-color: black !important;
color: white !important; color: white !important;
.code-line span { .code-line span, .name-underline {
border-bottom: 1px solid white; display: inline-block;
} }
} }
} }