优化
This commit is contained in:
25
src/utils/qrCodeGenerator.js
Normal file
25
src/utils/qrCodeGenerator.js
Normal file
@@ -0,0 +1,25 @@
|
||||
import QRCode from 'qrcode'
|
||||
|
||||
/**
|
||||
* 生成二维码Base64图片
|
||||
* @param {string} data - 要编码的二维码数据
|
||||
* @param {Object} options - 二维码选项
|
||||
* @returns {Promise<string>} Base64编码的二维码图片
|
||||
*/
|
||||
export async function generateQRCode(data, options = {}) {
|
||||
try {
|
||||
const defaultOptions = {
|
||||
width: 120,
|
||||
margin: 1,
|
||||
color: {
|
||||
dark: '#000000',
|
||||
light: '#FFFFFF',
|
||||
},
|
||||
}
|
||||
const finalOptions = { ...defaultOptions, ...options }
|
||||
return await QRCode.toDataURL(data, finalOptions)
|
||||
} catch (error) {
|
||||
console.error('生成二维码失败:', error)
|
||||
return ''
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user