import { useRef, useState, type RefObject } from 'react'; import { Link, useNavigate } from 'react-router-dom'; import AppImage from '@dukang/shared-ui/AppImage'; import { useStoreSession } from '../contexts/StoreSessionContext'; import { getLastPhone, request, saveRememberedSession, type ShopSessionPayload, } from '../lib/api'; import { routeAfterShopLogin } from './SelectStorePage'; function ShopAgreementCheckbox({ agreed, onChange, labelRef, }: { agreed: boolean; onChange: (next: boolean) => void; labelRef?: RefObject; }) { return ( ); } export default function LoginPage() { const navigate = useNavigate(); const { applySession } = useStoreSession(); const [phone, setPhone] = useState(getLastPhone()); const [code, setCode] = useState(''); const [agreed, setAgreed] = useState(false); const [loading, setLoading] = useState(false); const [msg, setMsg] = useState(''); const [codeCooldown, setCodeCooldown] = useState(0); const agreementRef = useRef(null); function ensureAgreed() { if (!agreed) { setMsg('请先阅读并同意用户协议'); agreementRef.current?.scrollIntoView({ behavior: 'smooth', block: 'center' }); return false; } return true; } async function sendCode() { if (!ensureAgreed()) return; setMsg(''); try { await request('SHOP_H5', '/shop/auth/sms/send', { method: 'POST', body: JSON.stringify({ phone, scene: 'STORE_LOGIN' }), }); setMsg('验证码已发送'); setCodeCooldown(60); const timer = setInterval(() => { setCodeCooldown((c) => { if (c <= 1) { clearInterval(timer); return 0; } return c - 1; }); }, 1000); } catch (e) { setMsg(e instanceof Error ? e.message : '发送失败'); } } async function login() { if (!ensureAgreed()) return; setLoading(true); setMsg(''); try { const data = await request('SHOP_H5', '/shop/auth/login/sms', { method: 'POST', body: JSON.stringify({ phone, code }), }); saveRememberedSession(data); applySession(data); routeAfterShopLogin(data, navigate); } catch (e) { setMsg(e instanceof Error ? e.message : '登录失败'); } finally { setLoading(false); } } return (

杜康好客

门店管理系统

phone_iphone setPhone(e.target.value)} />
shield setCode(e.target.value)} />
{msg &&

{msg}

}

手机号验证成功后,7 天内无需再次输入验证码

); }