import Footer from '@/components/Footer'; import { IAjaxReturn, post } from '@/services/ajax'; import { LockOutlined, MobileOutlined, UserOutlined } from '@ant-design/icons'; import { LoginForm, ProFormCaptcha, ProFormCheckbox, ProFormText, } from '@ant-design/pro-components'; import { useEmotionCss } from '@ant-design/use-emotion-css'; import { FormattedMessage, Helmet, history, useModel } from '@umijs/max'; import { Alert, App, Tabs } from 'antd'; import { stringify as qsStringify } from 'qs'; import React, { useState } from 'react'; import { flushSync } from 'react-dom'; import Settings from '../../../../config/defaultSettings'; const LoginMessage: React.FC<{ content: string; }> = ({ content }) => { return ( ); }; const Login: React.FC = () => { const [userLoginState, setUserLoginState] = useState({}); const [type, setType] = useState('account'); const { initialState, setInitialState } = useModel('@@initialState'); const containerClassName = useEmotionCss(() => { return { display: 'flex', flexDirection: 'column', height: '100vh', overflow: 'auto', backgroundImage: "url('https://mdn.alipayobjects.com/yuyan_qk0oxh/afts/img/V-_oS6r-i7wAAAAAAAAAAAAAFl94AQBr')", backgroundSize: '100% 100%', }; }); const { notification } = App.useApp(); window.NotificationCF = notification; const handleSubmit = async (values: API.LoginParams) => { const data = { user: values.username, password: values.password, }; post({ url: '/User/Login', data: qsStringify(data) }).then((res: IAjaxReturn) => { if (res && res.err_code == 0) { notification.success({ message: '登录成功', description: '登录成功', }); flushSync(() => { // 登录成功! setInitialState((s) => ({ ...s, currentUser: res.data, currentAuthority: 'admin', })); }); const urlParams = new URL(window.location.href).searchParams; history.push(urlParams.get('redirect') || '/'); } }); }; const { status, type: loginType } = userLoginState; return (
登录页 - {Settings.title} {/* */}
} title="scrm.antd" subTitle={
} initialValues={{ autoLogin: true, }} // actions={[ // , // , // ]} onFinish={async (values) => { await handleSubmit(values as API.LoginParams); }} > {status === 'error' && loginType === 'account' && ( )} {type === 'account' && ( <> , }} placeholder={'用户名'} rules={[ { required: true, message: ( ), }, ]} /> , }} placeholder={'请输入密码'} rules={[ { required: true, message: ( ), }, ]} /> )} {status === 'error' && loginType === 'mobile' && } {type === 'mobile' && ( <> , }} name="mobile" placeholder={'手机号'} rules={[ { required: true, message: ( ), }, { pattern: /^1\d{10}$/, message: ( ), }, ]} /> , }} captchaProps={{ size: 'large', }} placeholder={'请输入验证码'} captchaTextRender={(timing, count) => { if (timing) { return `${count} 获取验证码`; } return '获取验证码'; }} name="captcha" rules={[ { required: true, message: ( ), }, ]} onGetCaptcha={async (phone) => { // const result = await getFakeCaptcha({ // phone, // }); // if (!result) { // return; // } // message.success('获取验证码成功!验证码为:1234'); }} /> )}
); }; export default Login;