index.jsx 5.52 KB
Newer Older
wuhao's avatar
wuhao committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
import {
  AlipayCircleOutlined,
  LockOutlined,
  MobileOutlined,
  TaobaoCircleOutlined,
  UserOutlined,
  ArrowLeftOutlined,
} from '@ant-design/icons';
import {
  LoginForm,
  ProFormCaptcha,
  ProFormCheckbox,
  ProFormText,
  ProConfigProvider,
} from '@ant-design/pro-components';
wuhao's avatar
wuhao committed
16
import { message, Space, Button } from 'antd';
wuhao's avatar
wuhao committed
17 18 19
import { useState } from 'react';
import './index.less';
import { history } from '@umijs/max';
wuhao's avatar
wuhao committed
20
import { postFetch,getFetch } from '@/utils/doFetch';
wuhao's avatar
wuhao committed
21 22 23 24


export default () => {
  const [loginType, setLoginType] = useState('account');
wuhao's avatar
wuhao committed
25 26
  const [login, setlogin] = useState(false);

wuhao's avatar
wuhao committed
27 28 29 30 31 32 33 34
  return (
    <div className="bg">
      <ul className="circles">
        {new Array(10).fill('').map((it) => (
          <li key={it} />
        ))}
      </ul>
      <div style={{ position: 'absolute', width: '100%', zIndex: 99999 }}>
wuhao's avatar
wuhao committed
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
        {login ? (
          <LoginForm
            logo="./logo.png"
            subTitle={
              <>
                <p style={{ fontSize: 17, marginBottom: 0 }}>
                  <b>江苏南高智能装备创新中心有限公司</b>
                </p>
                <p style={{ fontSize: 12, zoom: 0.8, margin: 0 }}>
                  Jiangsu Nangao Intelligent Equipment Innovation Center Co.,
                  Ltd.
                </p>
              </>
            }
            onFinish={(values) => {
wuhao's avatar
wuhao committed
50 51
              postFetch({
                url: `/token/oauth/token?grant_type=password&client_id=admin&client_secret=123456&username=${values?.username}&password=${values?.password}`,
wuhao's avatar
wuhao committed
52
              }).then((res) => {
wuhao's avatar
wuhao committed
53 54 55 56
                let token = res?.access_token;
                localStorage.setItem('TOKENES', token);
                message.success('🎉 🎉 🎉  登录成功!');
                history.push('/');
wuhao's avatar
wuhao committed
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160
              });
            }}
          >
            {loginType === 'account' && (
              <>
                <ProFormText
                  name="username"
                  fieldProps={{
                    size: 'large',
                    prefix: <UserOutlined className={'prefixIcon'} />,
                  }}
                  placeholder={'用户名: admin or user'}
                  rules={[
                    {
                      required: true,
                      message: '请输入用户名!',
                    },
                  ]}
                />
                <ProFormText.Password
                  name="password"
                  fieldProps={{
                    size: 'large',
                    prefix: <LockOutlined className={'prefixIcon'} />,
                  }}
                  placeholder={'密码: 123'}
                  rules={[
                    {
                      required: true,
                      message: '请输入密码!',
                    },
                  ]}
                />
                <div
                  style={{
                    marginBlockEnd: 24,
                  }}
                >
                  <ProFormCheckbox noStyle name="autoLogin">
                    自动登录
                  </ProFormCheckbox>
                  <a
                    style={{
                      float: 'right',
                    }}
                    onClick={() => {
                      setLoginType('phone');
                    }}
                  >
                    忘记密码
                  </a>
                </div>
              </>
            )}
            {loginType === 'phone' && (
              <>
                <ArrowLeftOutlined
                  style={{
                    fontSize: 20,
                    marginBottom: 12,
                    position: 'fixed',
                    left: 36,
                    top: 36,
                    zIndex: 99999,
                  }}
                  onClick={() => {
                    setLoginType('account');
                  }}
                />
                <ProFormText.Password
                  name="confirmpassword"
                  fieldProps={{
                    size: 'large',
                    prefix: <LockOutlined className={'prefixIcon'} />,
                  }}
                  placeholder={'密码'}
                  rules={[
                    {
                      required: true,
                      message: '请输入密码!',
                    },
                  ]}
                />
                <ProFormText.Password
                  name="password"
                  fieldProps={{
                    size: 'large',
                    prefix: <LockOutlined className={'prefixIcon'} />,
                  }}
                  placeholder={'确认密码'}
                  rules={[
                    {
                      required: true,
                      message: '请输入确认密码!',
                    },
                  ]}
                />
              </>
            )}
          </LoginForm>
        ) : (
          <div className="nologin">
            <img src="./logo.png" alt="" />
            <h2>欢迎</h2>
wuhao's avatar
wuhao committed
161 162 163 164 165 166 167 168
            <>
              <p style={{ fontSize: 17, marginBottom: 0 }}>
                <b>江苏南高智能装备创新中心有限公司</b>
              </p>
              <p style={{ fontSize: 12, zoom: 0.8, margin: 0 }}>
                Jiangsu Nangao Intelligent Equipment Innovation Center Co., Ltd.
              </p>
            </>
wuhao's avatar
wuhao committed
169 170 171 172 173
            <Button type="primary" style={{width:"278px",marginTop:36}} size='large' onClick={()=>{
              setlogin(true)
            }}>登录</Button>
          </div>
        )}
wuhao's avatar
wuhao committed
174 175 176 177
      </div>
    </div>
  );
};