182 lines
5.4 KiB
TypeScript
182 lines
5.4 KiB
TypeScript
import React from 'react';
|
||
import { useNavigate } from 'react-router-dom';
|
||
import {
|
||
Form,
|
||
Input,
|
||
Button,
|
||
Typography,
|
||
Card,
|
||
message,
|
||
Checkbox,
|
||
App,
|
||
} from 'antd';
|
||
import {
|
||
UserOutlined,
|
||
LockOutlined,
|
||
} from '@ant-design/icons';
|
||
import { motion } from 'motion/react';
|
||
import bgcImg from '../assets/bgc2.png';
|
||
import logincard from '../assets/logincard.png';
|
||
import { userLogin } from '../store/userSlice';
|
||
import { useAppDispatch } from '../store';
|
||
import Cookies from 'js-cookie';
|
||
|
||
const { Text, Title } = Typography;
|
||
|
||
export default function Login() {
|
||
const navigate = useNavigate();
|
||
const dispatch = useAppDispatch();
|
||
const { message, } = App.useApp();
|
||
|
||
// 账号密码登录
|
||
const onFinish = async (values: any) => {
|
||
try {
|
||
// 👇 调用 dispatch,并用 unwrap() 拿到 return 的数据
|
||
const loginResult = await dispatch(userLogin(values)).unwrap();
|
||
|
||
// loginResult 就是你 userLogin 里 return 的 res
|
||
console.log("登录成功返回的数据:", loginResult);
|
||
|
||
if (loginResult.code == 200) {
|
||
//dispatch(setUserInfo(loginResult))
|
||
const searchParams = new URLSearchParams(window.location.search);
|
||
const goRemote = searchParams.get('goRemote');
|
||
if (Number(goRemote) == 1) {
|
||
const rawUserId = Cookies.get("userId"); // 比如 "32434"
|
||
|
||
const encodedUserId = btoa(unescape(encodeURIComponent(rawUserId)));
|
||
window.location.href = `https://ai.satabot.com/?userId=${encodedUserId}`;
|
||
return;
|
||
}
|
||
|
||
|
||
message.success(`登录成功`);
|
||
navigate('/', { replace: true });
|
||
} else {
|
||
|
||
message.error("登录失败:" + loginResult.msg);
|
||
|
||
|
||
}
|
||
|
||
// 登录成功后跳转
|
||
|
||
} catch (err) {
|
||
message.error("登录失败:" + err.toString());
|
||
|
||
}
|
||
|
||
};
|
||
|
||
return (
|
||
<div className="min-h-screen bg-[#F5F8FC] flex items-center justify-center p-4 relative overflow-hidden"
|
||
style={{
|
||
backgroundImage: `url(${bgcImg})`,
|
||
backgroundSize: 'cover',
|
||
backgroundPosition: 'center'
|
||
}}
|
||
>
|
||
<motion.div
|
||
initial={{ opacity: 0, scale: 0.95 }}
|
||
animate={{ opacity: 1, scale: 1 }}
|
||
transition={{ duration: 0.4 }}
|
||
className="w-full max-w-5xl"
|
||
>
|
||
<Card
|
||
variant={false}
|
||
className="shadow-xl overflow-hidden rounded-2xl"
|
||
styles={{ body: { padding: 0 } }}
|
||
>
|
||
<div className="flex flex-col md:flex-row relative">
|
||
{/* 左侧:表单区域 */}
|
||
<div className="md:w-1/2 bg-white p-10 md:p-16 flex flex-col justify-center relative z-10">
|
||
<motion.div initial={{ opacity: 0, x: -20 }} animate={{ opacity: 1, x: 0 }} transition={{ delay: 0.2 }}>
|
||
<Title level={2} style={{ marginBottom: 40, color: '#111', fontWeight: 700 }}>
|
||
光伏电站智能监控与运维系统
|
||
</Title>
|
||
|
||
<Form name="login" layout="vertical" onFinish={onFinish} autoComplete="off" size="large">
|
||
<Form.Item name="username" rules={[{ required: true, message: '请输入账号' }]}>
|
||
<Input
|
||
prefix={<UserOutlined style={{ color: '#999' }} />}
|
||
placeholder="请输入账号"
|
||
style={{ borderRadius: 8, height: 52, fontSize: 15, borderColor: '#e5e7eb' }}
|
||
/>
|
||
</Form.Item>
|
||
|
||
<Form.Item name="password" rules={[{ required: true, message: '请输入密码' }]}>
|
||
<Input.Password
|
||
prefix={<LockOutlined style={{ color: '#999' }} />}
|
||
placeholder="请输入密码"
|
||
style={{ borderRadius: 8, height: 52, fontSize: 15, borderColor: '#e5e7eb' }}
|
||
/>
|
||
</Form.Item>
|
||
|
||
{/* 记住密码 */}
|
||
{/*<Form.Item name="remember" valuePropName="checked" noStyle>
|
||
<Checkbox>
|
||
<Text style={{ fontSize: 14, color: '#666' }}>记住密码</Text>
|
||
</Checkbox>
|
||
</Form.Item>*/}
|
||
|
||
|
||
|
||
<Form.Item style={{ marginTop: 20 }}>
|
||
<Button
|
||
type="primary"
|
||
htmlType="submit"
|
||
block
|
||
style={{
|
||
borderRadius: 8,
|
||
height: 52,
|
||
fontWeight: 600,
|
||
fontSize: 16,
|
||
backgroundColor: '#1677ff',
|
||
borderColor: '#1677ff',
|
||
boxShadow: '0 4px 12px rgba(22, 119, 255, 0.25)'
|
||
}}
|
||
>
|
||
登录
|
||
</Button>
|
||
</Form.Item>
|
||
{/* 用户协议 */}
|
||
<Form.Item
|
||
name="agreement"
|
||
valuePropName="checked"
|
||
rules={[{ validator: (_, value) => value ? Promise.resolve() : Promise.reject(new Error('请阅读并同意用户协议')) }]}
|
||
>
|
||
<Checkbox>
|
||
<Text style={{ fontSize: 14, color: '#666' }}>
|
||
我已阅读并同意 <Text type="link" style={{ padding: 0, color: "#1677ff" }}>用户协议</Text> 和 <Text type="link" style={{ padding: 0, color: "#1677ff" }}>隐私政策</Text>
|
||
</Text>
|
||
</Checkbox>
|
||
</Form.Item>
|
||
</Form>
|
||
</motion.div>
|
||
</div>
|
||
|
||
{/* 右侧:梯形斜切 + 图片铺满 */}
|
||
<div
|
||
className="md:w-1/2 relative min-h-[600px] overflow-hidden"
|
||
style={{
|
||
// 梯形斜切效果
|
||
clipPath: 'polygon(12% 0, 100% 0, 100% 100%, 0 100%)',
|
||
}}
|
||
>
|
||
<div
|
||
className="absolute inset-0 w-full h-full"
|
||
style={{
|
||
backgroundImage: `url(${logincard})`,
|
||
backgroundSize: 'cover',
|
||
backgroundPosition: 'center',
|
||
backgroundRepeat: 'no-repeat',
|
||
}}
|
||
/>
|
||
</div>
|
||
</div>
|
||
</Card>
|
||
</motion.div>
|
||
</div>
|
||
);
|
||
}
|