fix(qa): randează codul QR în cardul de link public
Două probleme, ambele găsite la QA în browser: - `qrcode` e CommonJS; sub Vite metodele stau pe `.default`, deci `QRCode.toCanvas` era undefined → throw prins de un catch gol (blank canvas). - `renderQr()` era apelat în load() înainte ca ref-ul canvas să fie montat, și nu se relua. Adăugat un watch care randează când canvas + is_public sunt gata. Verificat live: canvas 512x512, QR desenat, buton „Descarcă QR" activ. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -653,17 +653,29 @@ const renderQr = async () => {
|
|||||||
await nextTick()
|
await nextTick()
|
||||||
if (!qrCanvas.value) return
|
if (!qrCanvas.value) return
|
||||||
try {
|
try {
|
||||||
const QRCode = await import('qrcode')
|
const mod = await import('qrcode')
|
||||||
|
// `qrcode` is CommonJS; under Vite its methods land on `.default`.
|
||||||
|
const QRCode = (mod as any).default ?? mod
|
||||||
await QRCode.toCanvas(qrCanvas.value, publicBookingIdUrl.value, {
|
await QRCode.toCanvas(qrCanvas.value, publicBookingIdUrl.value, {
|
||||||
width: 512,
|
width: 512,
|
||||||
margin: 4
|
margin: 4
|
||||||
})
|
})
|
||||||
qrReady.value = true
|
qrReady.value = true
|
||||||
} catch {
|
} catch (err) {
|
||||||
|
console.error('QR render failed', err)
|
||||||
qrReady.value = false
|
qrReady.value = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Render the QR whenever the canvas is mounted and the property is public.
|
||||||
|
// (renderQr called during load() can run before the canvas ref binds.)
|
||||||
|
watch(
|
||||||
|
[qrCanvas, () => property.value?.is_public, publicBookingIdUrl],
|
||||||
|
([canvas, isPublic]) => {
|
||||||
|
if (canvas && isPublic) renderQr()
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
const downloadQr = () => {
|
const downloadQr = () => {
|
||||||
if (!qrCanvas.value || !qrReady.value) return
|
if (!qrCanvas.value || !qrReady.value) return
|
||||||
const link = document.createElement('a')
|
const link = document.createElement('a')
|
||||||
|
|||||||
Reference in New Issue
Block a user