|
| 1 | +import React from 'react'; |
| 2 | +import classnames from 'classnames'; |
| 3 | +import { Spin, Tabs } from 'antd'; |
| 4 | +import Footer from '@/components/Footer'; |
| 5 | +import { LoginForm, ProCard, ProFormCheckbox } from '@ant-design/pro-components'; |
| 6 | +import { FormattedMessage, Helmet, useIntl } from '@umijs/max'; |
| 7 | + |
| 8 | +import Settings from '../../../config/defaultSettings'; |
| 9 | + |
| 10 | +import useStyle from './style'; |
| 11 | +import { Lang } from './Lang'; |
| 12 | +import { Password } from './Password'; |
| 13 | +import { Captcha } from './Captcha'; |
| 14 | +import useLoginHook from './_hooks'; |
| 15 | +import { ProviderIcons } from './ProviderIcons'; |
| 16 | + |
| 17 | +const prefixCls = 'iam-login'; |
| 18 | + |
| 19 | +const INTL = { |
| 20 | + TITLE: { |
| 21 | + id: 'menu.login', |
| 22 | + }, |
| 23 | + LOGIN_CARD_SUB_TITLE: { |
| 24 | + id: 'pages.layouts.userLayout.title', |
| 25 | + }, |
| 26 | + ACCOUNT_LOGIN: { |
| 27 | + id: 'pages.login.accountLogin.tab', |
| 28 | + }, |
| 29 | + PHONE_LOGIN: { |
| 30 | + id: 'pages.login.phoneLogin.tab', |
| 31 | + }, |
| 32 | + REMEMBER_ME: { |
| 33 | + id: 'pages.login.rememberMe', |
| 34 | + }, |
| 35 | + FORGOT_PASSWORD: { |
| 36 | + id: 'pages.login.forgotPassword', |
| 37 | + }, |
| 38 | +}; |
| 39 | + |
| 40 | +const Login: React.FC = () => { |
| 41 | + const intl = useIntl(); |
| 42 | + const { styles } = useStyle({ prefix: prefixCls }); |
| 43 | + const { |
| 44 | + states: { loginType, appConf, loadAppConfLoading }, |
| 45 | + actions: { handleLogin, setLoginType, afterLoginSuccess }, |
| 46 | + } = useLoginHook(); |
| 47 | + |
| 48 | + return ( |
| 49 | + <div className={classnames(styles.main)}> |
| 50 | + <div className={classnames(`${prefixCls}-wrapper`)}> |
| 51 | + <Lang prefixCls={prefixCls} /> |
| 52 | + <Helmet> |
| 53 | + <title> |
| 54 | + {intl.formatMessage(INTL.TITLE)} - {Settings.title} |
| 55 | + </title> |
| 56 | + </Helmet> |
| 57 | + <div className={`${prefixCls}-container`}> |
| 58 | + <ProCard className={`${prefixCls}-login-card`}> |
| 59 | + <LoginForm |
| 60 | + className={`${prefixCls}-login-form`} |
| 61 | + title="WeCoding" |
| 62 | + subTitle={intl.formatMessage(INTL.LOGIN_CARD_SUB_TITLE)} |
| 63 | + initialValues={{ |
| 64 | + autoLogin: true, |
| 65 | + }} |
| 66 | + actions={[ |
| 67 | + <Spin key="provider-icons" spinning={loadAppConfLoading}> |
| 68 | + <ProviderIcons appConf={appConf} afterLoginSuccess={afterLoginSuccess} /> |
| 69 | + </Spin>, |
| 70 | + ]} |
| 71 | + onFinish={async (values) => { |
| 72 | + await handleLogin(values as API.LoginParams); |
| 73 | + }} |
| 74 | + > |
| 75 | + <Tabs |
| 76 | + activeKey={loginType} |
| 77 | + onChange={setLoginType} |
| 78 | + centered |
| 79 | + items={[ |
| 80 | + { |
| 81 | + key: 'account', |
| 82 | + label: intl.formatMessage(INTL.ACCOUNT_LOGIN), |
| 83 | + children: <Password />, |
| 84 | + }, |
| 85 | + { |
| 86 | + key: 'mobile', |
| 87 | + label: intl.formatMessage(INTL.PHONE_LOGIN), |
| 88 | + children: <Captcha />, |
| 89 | + }, |
| 90 | + ]} |
| 91 | + /> |
| 92 | + <div style={{ marginBottom: 24 }}> |
| 93 | + <ProFormCheckbox noStyle name="autoLogin"> |
| 94 | + <FormattedMessage {...INTL.REMEMBER_ME} /> |
| 95 | + </ProFormCheckbox> |
| 96 | + <a style={{ float: 'right' }}> |
| 97 | + <FormattedMessage {...INTL.FORGOT_PASSWORD} /> |
| 98 | + </a> |
| 99 | + </div> |
| 100 | + </LoginForm> |
| 101 | + </ProCard> |
| 102 | + </div> |
| 103 | + <Footer /> |
| 104 | + </div> |
| 105 | + </div> |
| 106 | + ); |
| 107 | +}; |
| 108 | + |
| 109 | +export default Login; |
0 commit comments