forked from tangly1024/NotionNext
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQrCode.js
38 lines (35 loc) · 916 Bytes
/
QrCode.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import { siteConfig } from '@/lib/config'
import { loadExternalResource } from '@/lib/utils'
import { useEffect } from 'react'
/**
* 二维码生成
*/
export default function QrCode({ value }) {
const qrCodeCDN = siteConfig('QR_CODE_CDN')
useEffect(() => {
let qrcode
if (!value) {
return
}
loadExternalResource(qrCodeCDN, 'js').then(url => {
const QRCode = window?.QRCode
if (typeof QRCode !== 'undefined') {
qrcode = new QRCode(document.getElementById('qrcode'), {
text: value,
width: 256,
height: 256,
colorDark: '#000000',
colorLight: '#ffffff',
correctLevel: QRCode.CorrectLevel.H
})
// console.log('二维码', qrcode, value)
}
})
return () => {
if (qrcode) {
qrcode.clear() // clear the code.
}
}
}, [])
return <div id="qrcode"></div>
}