2024-10-16 18:15:19 +08:00
|
|
|
import { hiprint } from 'vue-plugin-hiprint'
|
|
|
|
|
export const customProvider = function (options) {
|
2024-10-22 11:10:13 +08:00
|
|
|
const addElementTypes = function (context) {
|
2024-10-16 18:15:19 +08:00
|
|
|
context.removePrintElementTypes('customProvider')
|
|
|
|
|
context.addPrintElementTypes('customProvider', [
|
|
|
|
|
new hiprint.PrintElementTypeGroup('', [
|
|
|
|
|
{
|
2024-10-20 21:51:59 +08:00
|
|
|
tid: 'providerModule1.html',
|
|
|
|
|
title: 'temu条码',
|
|
|
|
|
data: 'XS888888888',
|
|
|
|
|
type: 'html',
|
2024-10-22 15:11:28 +08:00
|
|
|
formatter: function (data, options, templateData) {
|
2024-10-22 11:10:13 +08:00
|
|
|
console.log(data, options, templateData)
|
|
|
|
|
const elId = options.elId || 'barCode-' + new Date().getTime()
|
2024-10-22 15:11:28 +08:00
|
|
|
const codeWidth = parseInt((options.width - 22) * 0.85)
|
2024-10-22 22:41:23 +08:00
|
|
|
options.elId = `${elId}`
|
|
|
|
|
|
2024-10-21 21:56:34 +08:00
|
|
|
// eslint-disable-next-line no-undef
|
2024-10-22 22:41:23 +08:00
|
|
|
$('body').append(`<div id="codewrapper-${elId}" style="width: ${codeWidth}pt">
|
|
|
|
|
<svg id="${elId}" width="100%" display="block" height="100%" class="hibarcode_imgcode" preserveAspectRatio="none slice"></svg>
|
|
|
|
|
</div>`)
|
2024-10-21 21:56:34 +08:00
|
|
|
// eslint-disable-next-line no-undef
|
2024-10-21 18:10:59 +08:00
|
|
|
JsBarcode('#'+ elId, '96778555251', {
|
2024-10-21 21:56:34 +08:00
|
|
|
format: "CODE128B",
|
2024-10-21 18:01:56 +08:00
|
|
|
width: 2,
|
2024-10-22 15:11:28 +08:00
|
|
|
height: parseInt(hinnn.pt.toPx(options.height - 22).toString()) * 0.6,
|
2024-10-21 18:01:56 +08:00
|
|
|
margin: 0,
|
|
|
|
|
displayValue: false
|
2024-10-20 21:51:59 +08:00
|
|
|
})
|
2024-10-21 18:01:56 +08:00
|
|
|
|
2024-10-21 21:56:34 +08:00
|
|
|
// eslint-disable-next-line no-undef
|
2024-10-22 15:11:28 +08:00
|
|
|
const codeHtml = $(`#codewrapper-${elId}`).html()
|
2024-10-21 21:56:34 +08:00
|
|
|
// eslint-disable-next-line no-undef
|
2024-10-22 15:11:28 +08:00
|
|
|
$(`body>#codewrapper-${elId}`).remove()
|
2024-10-21 21:56:34 +08:00
|
|
|
// eslint-disable-next-line no-undef
|
2024-10-22 11:10:13 +08:00
|
|
|
const resizeObserver = new ResizeObserver(() => {
|
|
|
|
|
JsBarcode('#'+ elId, '96778555251', {
|
|
|
|
|
format: "CODE128B",
|
|
|
|
|
width: 2,
|
2024-10-22 15:11:28 +08:00
|
|
|
height: parseInt(hinnn.pt.toPx(options.height - 22).toString()) * 0.6,
|
2024-10-22 11:10:13 +08:00
|
|
|
margin: 0,
|
|
|
|
|
displayValue: false
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
const node = document.getElementById(`temuBarCode-${elId}`)
|
|
|
|
|
if (node) {
|
|
|
|
|
resizeObserver.observe(node)
|
|
|
|
|
}
|
2024-10-22 15:11:28 +08:00
|
|
|
}, 0)
|
2024-10-21 18:01:56 +08:00
|
|
|
var html = `
|
2024-10-22 11:10:13 +08:00
|
|
|
<div class="temuBarCode" id="temuBarCode-${elId}">
|
2024-10-20 21:51:59 +08:00
|
|
|
<div class="temuBarCode-top">
|
|
|
|
|
<div class="hiprint-printElement-text-content hiprint-printElement-content">(AA+AAA)*20PCS</div>
|
|
|
|
|
<div class="hiprint-printElement-text-content hiprint-printElement-content">AA 20PCS+AAA 20PCS</div>
|
|
|
|
|
</div>
|
|
|
|
|
<div class="temuBarCode-middle">
|
2024-10-22 15:11:28 +08:00
|
|
|
<div class="hiprint-printElement-text-content hiprint-printElement-content temuBarCode-code" style="width: 100%">
|
|
|
|
|
${codeHtml}
|
2024-10-20 21:51:59 +08:00
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
<div class="temuBarCode-bottom">
|
|
|
|
|
<div class="hiprint-printElement-text-content hiprint-printElement-content">1034130097</div>
|
|
|
|
|
<div class="hiprint-printElement-text-content hiprint-printElement-content">Made in China</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
`
|
2024-10-21 18:01:56 +08:00
|
|
|
return html
|
2024-10-20 21:51:59 +08:00
|
|
|
},
|
2024-10-16 18:15:19 +08:00
|
|
|
options: {
|
2024-10-20 21:51:59 +08:00
|
|
|
width: 316,
|
2024-10-22 11:10:13 +08:00
|
|
|
height: 120,
|
2024-10-23 22:13:07 +08:00
|
|
|
elId: ''
|
2024-10-22 22:41:23 +08:00
|
|
|
},
|
|
|
|
|
printElementType: {
|
2024-10-16 18:15:19 +08:00
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
tid: 'providerModule1.barcode',
|
|
|
|
|
title: '条形码',
|
|
|
|
|
data: 'XS888888888',
|
|
|
|
|
type: 'text',
|
|
|
|
|
options: {
|
|
|
|
|
field: 'barcode',
|
|
|
|
|
testData: 'XS888888888',
|
|
|
|
|
height: 32,
|
|
|
|
|
fontSize: 12,
|
|
|
|
|
lineHeight: 18,
|
|
|
|
|
textAlign: 'left',
|
|
|
|
|
textType: 'barcode',
|
|
|
|
|
hideTitle: false
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
tid: 'providerModule1.qrcode',
|
|
|
|
|
title: '二维码',
|
|
|
|
|
data: 'XS888888888',
|
|
|
|
|
type: 'text',
|
|
|
|
|
options: {
|
|
|
|
|
field: '',
|
|
|
|
|
testData: '',
|
|
|
|
|
height: 32,
|
|
|
|
|
fontSize: 12,
|
|
|
|
|
lineHeight: 18,
|
|
|
|
|
textType: 'qrcode',
|
|
|
|
|
hideTitle: false
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
tid: 'providerModule1.image',
|
2024-10-23 22:13:07 +08:00
|
|
|
title: '图片',
|
2024-10-16 18:15:19 +08:00
|
|
|
data: 'https://foruda.gitee.com/avatar/1677050350324030848/5400665_ccsimple_1591166830.png!avatar200',
|
|
|
|
|
type: 'image'
|
|
|
|
|
}
|
|
|
|
|
])
|
|
|
|
|
])
|
|
|
|
|
}
|
|
|
|
|
return {
|
2024-10-22 11:10:13 +08:00
|
|
|
addElementTypes
|
2024-10-16 18:15:19 +08:00
|
|
|
}
|
|
|
|
|
}
|