初始化2
This commit is contained in:
33
app/composables/useQRCode.ts
Normal file
33
app/composables/useQRCode.ts
Normal file
@@ -0,0 +1,33 @@
|
||||
import QRCode from 'qrcode'
|
||||
|
||||
/**
|
||||
* 将 URL 转换为二维码图片的 data URL
|
||||
*/
|
||||
export async function generateQrCodeDataUrl(url: string, options?: QRCode.QRCodeToDataURLOptions): Promise<string> {
|
||||
const defaultOptions: QRCode.QRCodeToDataURLOptions = {
|
||||
width: 280,
|
||||
margin: 2,
|
||||
color: {
|
||||
dark: '#000000',
|
||||
light: '#ffffff'
|
||||
}
|
||||
}
|
||||
|
||||
return QRCode.toDataURL(url, { ...defaultOptions, ...options })
|
||||
}
|
||||
|
||||
/**
|
||||
* 将 URL 转换为二维码图片的 Canvas 元素
|
||||
*/
|
||||
export async function generateQrCodeCanvas(url: string, canvas: HTMLCanvasElement, options?: QRCode.QRCodeToCanvasOptions): Promise<void> {
|
||||
const defaultOptions: QRCode.QRCodeToCanvasOptions = {
|
||||
width: 280,
|
||||
margin: 2,
|
||||
color: {
|
||||
dark: '#000000',
|
||||
light: '#ffffff'
|
||||
}
|
||||
}
|
||||
|
||||
return QRCode.toCanvas(canvas, url, { ...defaultOptions, ...options })
|
||||
}
|
||||
Reference in New Issue
Block a user