[TQRCode] QRCode base64 인코딩
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import React, { useEffect, useRef, useState } from "react";
|
||||
|
||||
import { useDispatch, useSelector } from "react-redux";
|
||||
import QRCodeMin from "!!raw-loader!../../utils/qrcode.min.js";
|
||||
import QRCodeMin from "!!raw-loader!../../utils/qrcode.min.js";;
|
||||
|
||||
import { getDeviceAdditionInfo } from "../../actions/deviceActions";
|
||||
import { scaleH, scaleW } from "../../utils/helperMethods";
|
||||
@@ -10,9 +10,15 @@ let script = document.createElement("script");
|
||||
script.innerText = QRCodeMin;
|
||||
document.body.appendChild(script);
|
||||
|
||||
export default function TQRCode({ ariaLabel,text, menu, width = "128", height = "128" }) {
|
||||
export default function TQRCode({
|
||||
ariaLabel,
|
||||
text,
|
||||
width = "128",
|
||||
height = "128",
|
||||
}) {
|
||||
const qrcodeRef = useRef(null);
|
||||
const deviceInfo = useSelector((state) => state.device.deviceInfo);
|
||||
const { entryMenu, nowMenu } = useSelector((state) => state.common.menu);
|
||||
const dispatch = useDispatch();
|
||||
|
||||
useEffect(() => {
|
||||
@@ -20,21 +26,22 @@ export default function TQRCode({ ariaLabel,text, menu, width = "128", height =
|
||||
}, [dispatch]);
|
||||
|
||||
useEffect(() => {
|
||||
if (typeof window === "object" && deviceInfo && menu) {
|
||||
if (typeof window === "object" && deviceInfo && entryMenu && nowMenu) {
|
||||
if (qrcodeRef.current) {
|
||||
while (qrcodeRef.current.firstChild) {
|
||||
qrcodeRef.current.removeChild(qrcodeRef.current.firstChild);
|
||||
}
|
||||
}
|
||||
|
||||
// nowMenu 데이터를 Base64로 인코딩
|
||||
const encodedNowMenu = btoa(nowMenu);
|
||||
|
||||
const qrcode = new window.QRCode(qrcodeRef.current, {
|
||||
text: menu
|
||||
? `${text}&nowMenu=${menu}&idx=${deviceInfo.dvcIndex}`
|
||||
: text,
|
||||
text: `${text}&entryMenu=${entryMenu}&nowMenu=${encodedNowMenu}&idx=${deviceInfo.dvcIndex}`,
|
||||
width: scaleW(width),
|
||||
height: scaleH(height),
|
||||
});
|
||||
}
|
||||
}, [text, menu, deviceInfo]);
|
||||
}, [text, deviceInfo]);
|
||||
return <div aria-label={ariaLabel} ref={qrcodeRef} />;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user