MCPcopy Create free account
hub / github.com/027xiguapi/code-box / QRCodeModal

Function QRCodeModal

component/ui/QRCodeModal.tsx:105–176  ·  view source on GitHub ↗
({ onClose, onConfirm }: QRCodeModalProps)

Source from the content-addressed store, hash-verified

103}
104
105export default function QRCodeModal({ onClose, onConfirm }: QRCodeModalProps) {
106 const [inputCode, setInputCode] = useState<string>("")
107 const [isValid, setIsValid] = useState<boolean | null>(null)
108
109 const handleVerify = () => {
110 const formattedInput = inputCode.replace(/\s/g, "")
111 const secretKey = process.env.PLASMO_PUBLIC_CODEBOX_SECRET4
112
113 if (
114 formattedInput.length == 6 &&
115 TOTP.verifyTOTP(secretKey, formattedInput)
116 ) {
117 setIsValid(true)
118 onConfirm()
119 } else if (process.env.PLASMO_PUBLIC_CODEBOX_SECRET3 == formattedInput) {
120 setIsValid(true)
121 onConfirm()
122 } else {
123 setIsValid(false)
124 }
125 }
126
127 // 在原有return中添加:
128 return (
129 <div style={styles.overlay}>
130 <div style={styles.content}>
131 <button style={styles.closeButton} onClick={onClose} aria-label="Close">
132 ×
133 </button>
134
135 {imageSrc && (
136 <div style={styles.qrcodeBox}>
137 <img
138 src={imageSrc}
139 alt="WeChat QR Code"
140 style={styles.qrcodeImage}
141 />
142 <div style={styles.scanTip}>扫描二维码获取验证码</div>
143 </div>
144 )}
145
146 {/* 新增验证码区域 */}
147 <div style={styles.captchaSection}>
148 <div style={styles.inputGroup}>
149 <input
150 type="text"
151 value={inputCode}
152 onChange={(e) => {
153 // 只允许数字和空格
154 const val = e.target.value.replace(/[^\d\s]/g, "")
155 setInputCode(val)
156 setIsValid(null) // 清除验证状态
157 }}
158 placeholder="请输入验证码"
159 style={{
160 ...styles.input,
161 borderColor: isValid === false ? "#ff4444" : "#ddd"
162 }}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected