| | |
| | | ProFormCaptcha, |
| | | ProFormCheckbox, |
| | | ProFormText, |
| | | ProFormSelect |
| | | } from '@ant-design/pro-components'; |
| | | import { Button, Divider, Alert, Tabs, message, theme } from 'antd'; |
| | | import { Button, Divider, Alert, Tabs, message, theme, Form } from 'antd'; |
| | | import { useState, useEffect } from 'react'; |
| | | import { FormattedMessage, history, SelectLang, useIntl, useModel, Helmet } from '@umijs/max'; |
| | | import { flushSync } from 'react-dom'; |
| | | import { request } from '@umijs/max'; |
| | | import { setToken } from '@/utils/token-util' |
| | | import { PROJECT_NAME } from '@/config/setting' |
| | | import Http from '@/utils/http'; |
| | | |
| | | import logo from './logo.png' |
| | | import logo from '/public/img/logo.png' |
| | | import logoBg from '/public/login-bg.mp4' |
| | | |
| | | const LoginMessage = ({ content }) => { |
| | | return ( |
| | |
| | | const { initialState, setInitialState } = useModel('@@initialState'); |
| | | const { token } = theme.useToken(); |
| | | |
| | | const [form] = Form.useForm(); |
| | | const [loginType, setLoginType] = useState('account'); |
| | | const [status, setStatus] = useState(200); |
| | | const [rememberMe, setRememberMe] = useState(true); |
| | | |
| | | console.log(initialState.memo); |
| | | const [rememberMe, setRememberMe] = useState(() => { |
| | | const storedValue = localStorage.getItem('rememberMe'); |
| | | return storedValue !== null ? JSON.parse(storedValue) : true; |
| | | }); |
| | | const [rememberData, setRememberData] = useState(() => { |
| | | const storedValue = localStorage.getItem('rememberData'); |
| | | return storedValue !== null ? JSON.parse(storedValue) : true; |
| | | }); |
| | | const [hostList, setHostList] = useState([]); |
| | | |
| | | useEffect(() => { |
| | | console.log(rememberMe); |
| | | form.setFieldsValue({ |
| | | autoLogin: rememberMe |
| | | }); |
| | | localStorage.setItem('rememberMe', JSON.stringify(rememberMe)); |
| | | }, [rememberMe]) |
| | | |
| | | useEffect(() => { |
| | | form.setFieldsValue({ |
| | | username: rememberData.username, |
| | | password: rememberData.password |
| | | }); |
| | | localStorage.setItem('rememberData', JSON.stringify(rememberData)); |
| | | }, [rememberData]) |
| | | |
| | | useEffect(() => { |
| | | const fetchHostList = async () => { |
| | | const resp = await Http.doGet('api/auth/host'); |
| | | const list = resp.data.map(item => ({ |
| | | label: item.name, |
| | | value: item.id |
| | | })); |
| | | setHostList(list); |
| | | if (list && list.length > 0) { |
| | | form.setFieldsValue({ |
| | | hostId: list[0].value |
| | | }); |
| | | } |
| | | } |
| | | fetchHostList(); |
| | | }, []); |
| | | |
| | | const fetchUserInfo = async () => { |
| | | const userInfo = await initialState?.fetchUserInfo?.(); |
| | |
| | | } |
| | | }; |
| | | |
| | | |
| | | const handleSubmit = async (values) => { |
| | | try { |
| | | const r = await request('/api/login', { |
| | |
| | | }) |
| | | |
| | | if (r.code === 200) { |
| | | localStorage.removeItem("rememberData"); |
| | | if (rememberMe) { |
| | | setRememberData({ |
| | | username: values.username, |
| | | password: values.password |
| | | }) |
| | | } |
| | | message.success(intl.formatMessage({ |
| | | id: 'pages.login.success', |
| | | defaultMessage: '登录成功!', |
| | |
| | | }} |
| | | > |
| | | <LoginFormPage |
| | | backgroundImageUrl="https://mdn.alipayobjects.com/huamei_gcee1x/afts/img/A*y0ZTS6WLwvgAAAAAAAAAAAAADml6AQ/fmt.webp" |
| | | form={form} |
| | | logo={logo} |
| | | backgroundVideoUrl="https://gw.alipayobjects.com/v/huamei_gcee1x/afts/video/jXRBRK_VAwoAAAAAAAAAAAAAK4eUAQBr" |
| | | backgroundVideoUrl={logoBg} |
| | | // title="陆晓涛" |
| | | // subTitle="陆晓涛..." |
| | | containerStyle={{ |
| | | backgroundColor: 'rgba(0, 0, 0,0.65)', |
| | | backdropFilter: 'blur(4px)', |
| | | }} |
| | | initialValues={{ |
| | | username: 'root', |
| | | password: '123456', |
| | | autoLogin: true, |
| | | }} |
| | | onFinish={async (values) => { |
| | | await handleSubmit(values); |
| | | }} |
| | | initialValue={{ |
| | | }} |
| | | > |
| | | <Tabs |
| | |
| | | </Tabs> |
| | | {loginType === 'account' && ( |
| | | <> |
| | | <ProFormSelect |
| | | className="centered-select" |
| | | name="hostId" |
| | | placeholder="机构:" |
| | | rules={[ |
| | | { |
| | | required: true, |
| | | message: '请选择机构!', |
| | | }, |
| | | ]} |
| | | options={hostList} |
| | | /> |
| | | <ProFormText |
| | | name="username" |
| | | fieldProps={{ |
| | |
| | | /> |
| | | ), |
| | | }} |
| | | placeholder={'用户名: root'} |
| | | placeholder={'用户名: '} |
| | | rules={[ |
| | | { |
| | | required: true, |
| | |
| | | /> |
| | | ), |
| | | }} |
| | | placeholder={'密码: 123456'} |
| | | placeholder={'密码: '} |
| | | rules={[ |
| | | { |
| | | required: true, |
| | |
| | | )} |
| | | {loginType === 'phone' && ( |
| | | <> |
| | | <ProFormSelect |
| | | className="centered-select" |
| | | name="hostId" |
| | | placeholder="机构:" |
| | | rules={[ |
| | | { |
| | | required: true, |
| | | message: '请选择机构!', |
| | | }, |
| | | ]} |
| | | options={hostList} |
| | | /> |
| | | <ProFormText |
| | | fieldProps={{ |
| | | size: 'large', |
| | |
| | | <Page /> |
| | | </ProConfigProvider> |
| | | ); |
| | | }; |
| | | }; |