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:
@@ -9,14 +9,20 @@ const { Title, Text } = Typography;
|
|||||||
|
|
||||||
export default function LoginPage() {
|
export default function LoginPage() {
|
||||||
const [loading, setLoading] = useState(false);
|
const [loading, setLoading] = useState(false);
|
||||||
|
const [guestLoading, setGuestLoading] = useState(false);
|
||||||
const navigate = useNavigate();
|
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 }) => {
|
const onFinish = async (values: { username: string; password: string }) => {
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
try {
|
try {
|
||||||
const res: any = await login(values.username, values.password);
|
await doLogin(values.username, values.password);
|
||||||
setToken(res.access_token);
|
|
||||||
setUser(res.user);
|
|
||||||
message.success('登录成功');
|
message.success('登录成功');
|
||||||
navigate('/');
|
navigate('/');
|
||||||
} catch {
|
} 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 (
|
return (
|
||||||
<div style={{
|
<div style={{
|
||||||
minHeight: '100vh', display: 'flex', justifyContent: 'center', alignItems: 'center',
|
minHeight: '100vh', display: 'flex', justifyContent: 'center', alignItems: 'center',
|
||||||
@@ -51,9 +70,17 @@ export default function LoginPage() {
|
|||||||
登 录
|
登 录
|
||||||
</Button>
|
</Button>
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
{import.meta.env.DEV && <Text type="secondary" style={{ fontSize: 12 }}>
|
<Form.Item style={{ marginBottom: 8 }}>
|
||||||
默认账号: admin / admin123
|
<Button block loading={guestLoading} onClick={onGuestLogin}
|
||||||
</Text>}
|
style={{ borderColor: '#1890ff', color: '#1890ff' }}>
|
||||||
|
访客体验入口
|
||||||
|
</Button>
|
||||||
|
</Form.Item>
|
||||||
|
<div style={{ textAlign: 'center' }}>
|
||||||
|
<Text type="secondary" style={{ fontSize: 12 }}>
|
||||||
|
访客仅可浏览数据,无管理权限
|
||||||
|
</Text>
|
||||||
|
</div>
|
||||||
</Form>
|
</Form>
|
||||||
</Card>
|
</Card>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -108,6 +108,9 @@ async def seed():
|
|||||||
User(username="operator1", hashed_password=hash_password("tianpu123"),
|
User(username="operator1", hashed_password=hash_password("tianpu123"),
|
||||||
full_name="李运维", role="operator", email="op1@tianpu.com",
|
full_name="李运维", role="operator", email="op1@tianpu.com",
|
||||||
phone="13800000003"),
|
phone="13800000003"),
|
||||||
|
User(username="visitor", hashed_password=hash_password("visitor123"),
|
||||||
|
full_name="访客", role="visitor", email=None,
|
||||||
|
phone=None),
|
||||||
]
|
]
|
||||||
session.add_all(users)
|
session.add_all(users)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user