feat: add guest login button for customer demos

- One-click "访客体验入口" button on login page
- Visitor account (visitor/visitor123) with read-only role
- No username/password needed for customers to browse

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Du Wenbo
2026-04-02 21:14:42 +08:00
parent ef9b5d055f
commit 0a26c8b07a
2 changed files with 36 additions and 6 deletions

View File

@@ -9,14 +9,20 @@ const { Title, Text } = Typography;
export default function LoginPage() {
const [loading, setLoading] = useState(false);
const [guestLoading, setGuestLoading] = useState(false);
const navigate = useNavigate();
const doLogin = async (username: string, password: string) => {
const res: any = await login(username, password);
setToken(res.access_token);
setUser(res.user);
return res;
};
const onFinish = async (values: { username: string; password: string }) => {
setLoading(true);
try {
const res: any = await login(values.username, values.password);
setToken(res.access_token);
setUser(res.user);
await doLogin(values.username, values.password);
message.success('登录成功');
navigate('/');
} catch {
@@ -26,6 +32,19 @@ export default function LoginPage() {
}
};
const onGuestLogin = async () => {
setGuestLoading(true);
try {
await doLogin('visitor', 'visitor123');
message.success('访客登录成功');
navigate('/');
} catch {
message.error('访客登录失败,请联系管理员');
} finally {
setGuestLoading(false);
}
};
return (
<div style={{
minHeight: '100vh', display: 'flex', justifyContent: 'center', alignItems: 'center',
@@ -51,9 +70,17 @@ export default function LoginPage() {
</Button>
</Form.Item>
{import.meta.env.DEV && <Text type="secondary" style={{ fontSize: 12 }}>
默认账号: admin / admin123
</Text>}
<Form.Item style={{ marginBottom: 8 }}>
<Button block loading={guestLoading} onClick={onGuestLogin}
style={{ borderColor: '#1890ff', color: '#1890ff' }}>
访
</Button>
</Form.Item>
<div style={{ textAlign: 'center' }}>
<Text type="secondary" style={{ fontSize: 12 }}>
访
</Text>
</div>
</Form>
</Card>
</div>

View File

@@ -108,6 +108,9 @@ async def seed():
User(username="operator1", hashed_password=hash_password("tianpu123"),
full_name="李运维", role="operator", email="op1@tianpu.com",
phone="13800000003"),
User(username="visitor", hashed_password=hash_password("visitor123"),
full_name="访客", role="visitor", email=None,
phone=None),
]
session.add_all(users)