refactor: 打印组件二维码渲染改用 qrcode 库
This commit is contained in:
parent
01d26f6649
commit
9743cdd36f
@ -56,11 +56,7 @@
|
|||||||
<barcode-img :text="getPreviewValue(item) || '0123456789'" />
|
<barcode-img :text="getPreviewValue(item) || '0123456789'" />
|
||||||
</template>
|
</template>
|
||||||
<template v-else-if="item.type === 'qrcode'">
|
<template v-else-if="item.type === 'qrcode'">
|
||||||
<img
|
<qrcode-img :text="getPreviewValue(item) || ''" />
|
||||||
:src="'https://ye4s.wms.gztbyc.com/qrcode/build?text=' + encodeURIComponent(getPreviewValue(item) || '')"
|
|
||||||
alt=""
|
|
||||||
style="width: 100%; height: 100%; object-fit: contain;"
|
|
||||||
/>
|
|
||||||
</template>
|
</template>
|
||||||
<template v-else-if="item.type === 'image'">
|
<template v-else-if="item.type === 'image'">
|
||||||
<img :src="item.content" alt="" style="width: 100%; height: 100%; object-fit: fill;" />
|
<img :src="item.content" alt="" style="width: 100%; height: 100%; object-fit: fill;" />
|
||||||
@ -126,6 +122,7 @@
|
|||||||
import { computed, h, reactive, ref, watch } from 'vue'
|
import { computed, h, reactive, ref, watch } from 'vue'
|
||||||
import { ElMessage } from 'element-plus'
|
import { ElMessage } from 'element-plus'
|
||||||
import JsBarcode from 'jsbarcode'
|
import JsBarcode from 'jsbarcode'
|
||||||
|
import QRCode from 'qrcode'
|
||||||
import * as receivingApi from '@/api/storage_receiving/receiving'
|
import * as receivingApi from '@/api/storage_receiving/receiving'
|
||||||
import * as templateApi from '@/api/setting.printtemplate/printTemplate'
|
import * as templateApi from '@/api/setting.printtemplate/printTemplate'
|
||||||
import * as stationApi from '@/api/print/print'
|
import * as stationApi from '@/api/print/print'
|
||||||
@ -204,6 +201,29 @@ const barcodeImg = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const qrcodeImg = {
|
||||||
|
props: ['text'],
|
||||||
|
setup(innerProps: any) {
|
||||||
|
const src = ref('')
|
||||||
|
const renderQrcode = (val: string) => {
|
||||||
|
if (!val) {
|
||||||
|
src.value = ''
|
||||||
|
return
|
||||||
|
}
|
||||||
|
const canvas = document.createElement('canvas')
|
||||||
|
QRCode.toCanvas(canvas, val, { width: 200, margin: 1 }, (err: Error | null | undefined) => {
|
||||||
|
if (err) {
|
||||||
|
src.value = ''
|
||||||
|
return
|
||||||
|
}
|
||||||
|
src.value = canvas.toDataURL()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
watch(() => innerProps.text, (val: string) => renderQrcode(val), { immediate: true })
|
||||||
|
return () => h('img', { src: src.value, style: { display: 'block', width: '100%', height: '100%', objectFit: 'contain' } })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const previewInfo = computed(() => {
|
const previewInfo = computed(() => {
|
||||||
const t = templateOptions.value.find((item: any) => item.id === printSettings.template)
|
const t = templateOptions.value.find((item: any) => item.id === printSettings.template)
|
||||||
if (!t) return { width: 0, height: 0 }
|
if (!t) return { width: 0, height: 0 }
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user