From 218ee1577e128b88f5a281a88ae28a6dfd230a02 Mon Sep 17 00:00:00 2001 From: yml2213 Date: Thu, 20 Aug 2026 16:13:07 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E7=9F=AD=E4=BF=A1=E7=99=BB?= =?UTF-8?q?=E5=BD=95=E6=89=8B=E6=9C=BA=E5=8F=B7=E6=A0=A1=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/pages/worker/WorkerLoginPage.tsx | 39 ++++++++++++------- 1 file changed, 26 insertions(+), 13 deletions(-) diff --git a/apps/frontend/src/pages/worker/WorkerLoginPage.tsx b/apps/frontend/src/pages/worker/WorkerLoginPage.tsx index 39b94f5d..2441ffa0 100644 --- a/apps/frontend/src/pages/worker/WorkerLoginPage.tsx +++ b/apps/frontend/src/pages/worker/WorkerLoginPage.tsx @@ -19,8 +19,9 @@ import { Table, Tabs, Typography, + type InputRef, } from 'antd' -import { useEffect, useState } from 'react' +import { useEffect, useRef, useState } from 'react' import { Navigate, useNavigate } from 'react-router' import { @@ -64,11 +65,13 @@ export default function WorkerLoginPage() { const [loading, setLoading] = useState(false) const [registerForm] = Form.useForm() const [loginSmsForm] = Form.useForm<{ phone: string; code: string }>() + const loginSmsPhoneInputRef = useRef(null) const [resetForm] = Form.useForm<{ phone: string; code: string; password: string }>() const [deviceForm] = Form.useForm<{ username: string; password: string }>() const [countdown, setCountdown] = useState(0) const [loginSmsCountdown, setLoginSmsCountdown] = useState(0) const [loginMode, setLoginMode] = useState<'password' | 'sms'>('password') + const [loginSmsPhone, setLoginSmsPhone] = useState('') const [resetCountdown, setResetCountdown] = useState(0) const [forgotPasswordOpen, setForgotPasswordOpen] = useState(false) const [deviceManagerOpen, setDeviceManagerOpen] = useState(false) @@ -129,7 +132,7 @@ export default function WorkerLoginPage() { } async function requestLoginSmsCode() { - const phone = String(loginSmsForm.getFieldValue('phone') || '').trim() + const phone = getLoginSmsPhone() if (!/^1[3-9]\d{9}$/.test(phone)) { message.error('请先填写正确的手机号') return @@ -153,7 +156,7 @@ export default function WorkerLoginPage() { async function submitSmsLogin(values: { phone: string; code: string }) { setLoading(true) try { - const response = await loginWorkerBySmsCode(values) + const response = await loginWorkerBySmsCode({ ...values, phone: getLoginSmsPhone() }) setWorkerSession(response.data.token, response.data.expiresAt, response.data.worker) message.success('登录成功') void navigate('/hall', { replace: true }) @@ -164,6 +167,10 @@ export default function WorkerLoginPage() { } } + function getLoginSmsPhone() { + return String(loginSmsPhoneInputRef.current?.input?.value || loginSmsPhone).trim() + } + async function loadManagedDevices(values?: { username: string; password: string }) { const credentials = values || deviceForm.getFieldsValue() if (!credentials.username || !credentials.password) { @@ -406,23 +413,29 @@ export default function WorkerLoginPage() { ]} > } maxLength={11} placeholder="注册时使用的手机号" + value={loginSmsPhone} + onChange={(event) => setLoginSmsPhone(event.target.value)} /> - + - } - maxLength={6} - placeholder="6 位数字验证码" - /> + + } + maxLength={6} + placeholder="6 位数字验证码" + /> +