feat(react-web-next): 新增.editorconfig和.prettierrc配置文件,添加public/.gitkeep占位文件
This commit is contained in:
@@ -0,0 +1,131 @@
|
||||
import logo from '@/assets/logo.png';
|
||||
import React, { useEffect, useRef, useState } from 'react';
|
||||
import { LoginForm, ProFormText, ProFormCaptcha, ProFormCheckbox } from '@ant-design/pro-components';
|
||||
import { AppstoreOutlined, LockOutlined, UserOutlined } from '@ant-design/icons';
|
||||
import { Form, message, Spin } from 'antd';
|
||||
import { v4 as uuidv4 } from 'uuid';
|
||||
import { history } from 'umi';
|
||||
import { login, LoginParams } from '@/services/login';
|
||||
import './index.less';
|
||||
|
||||
const LoginPage: React.FC = () => {
|
||||
const [uuid, setUuid] = useState<string>(uuidv4());
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [form] = Form.useForm();
|
||||
const mountedRef = useRef(true);
|
||||
|
||||
useEffect(() => () => { mountedRef.current = false; }, []);
|
||||
|
||||
// 自动回填“租户标识”
|
||||
useEffect(() => {
|
||||
const clientId = localStorage.getItem('tenant_client_id');
|
||||
if (clientId) form.setFieldsValue({ clientId });
|
||||
}, []);
|
||||
|
||||
const handleSubmit = async (values: LoginParams) => {
|
||||
if (loading) return;
|
||||
setLoading(true);
|
||||
try {
|
||||
const res = await login({ ...values, deviceId: uuid });
|
||||
|
||||
// 检查多种可能的token字段位置
|
||||
const accessToken = res?.access_token || res?.data?.access_token || res?.accessToken;
|
||||
|
||||
if (accessToken) {
|
||||
sessionStorage.setItem('access_token', accessToken);
|
||||
localStorage.setItem('tenant_client_id', String(values.clientId ?? ''));
|
||||
message.success('登录成功,正在跳转...');
|
||||
|
||||
// 使用umi的history进行路由跳转
|
||||
setTimeout(() => {
|
||||
const { query } = history.location as any;
|
||||
const { redirect } = query || {};
|
||||
const targetPath = redirect || '/welcome';
|
||||
history.push(targetPath);
|
||||
}, 1000);
|
||||
|
||||
// 注意:不要在这里return,让finally块执行
|
||||
} else {
|
||||
const errorMsg = (res as any)?.resp_msg || (res as any)?.msg || '登录失败';
|
||||
message.error(errorMsg);
|
||||
setUuid(uuidv4());
|
||||
}
|
||||
} catch (e) {
|
||||
const errorMsg = (e as any)?.message || '登录失败,请重试';
|
||||
message.error(errorMsg);
|
||||
} finally {
|
||||
if (mountedRef.current) setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="login-page">
|
||||
<div className="login-wrap">
|
||||
<div className="login-hero">
|
||||
<h1>Go-Fly Admin</h1>
|
||||
<p>G0-Fly后台管理系统,支持多租户与子租户查询。</p>
|
||||
<ul>
|
||||
<li>全球景区智能服务运营商</li>
|
||||
<li>让旅行记忆触手可及</li>
|
||||
<li>统一下载/导出与请求封装</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div className="login-form-card">
|
||||
<Spin spinning={loading}>
|
||||
<LoginForm
|
||||
className="login-form"
|
||||
logo={<img alt="logo" src={logo} />}
|
||||
title="Go-Fly Admin"
|
||||
subTitle="请输入账号后继续"
|
||||
initialValues={{ autoLogin: true }}
|
||||
form={form}
|
||||
onFinish={handleSubmit as any}
|
||||
submitter={{ searchConfig: { submitText: '登录' } }}
|
||||
>
|
||||
<ProFormText
|
||||
name="clientId"
|
||||
fieldProps={{ size: 'large', prefix: <AppstoreOutlined /> }}
|
||||
placeholder="请输入租户标识"
|
||||
rules={[{ required: true, message: '请输入租户标识' }]}
|
||||
/>
|
||||
<ProFormText
|
||||
name="username"
|
||||
fieldProps={{ size: 'large', prefix: <UserOutlined /> }}
|
||||
placeholder="请输入用户名"
|
||||
rules={[{ required: true, message: '请输入用户名' }]}
|
||||
/>
|
||||
<ProFormText.Password
|
||||
name="password"
|
||||
fieldProps={{ size: 'large', prefix: <LockOutlined /> }}
|
||||
placeholder="请输入密码"
|
||||
rules={[{ required: true, message: '请输入密码' }]}
|
||||
/>
|
||||
<ProFormCaptcha
|
||||
name="validCode"
|
||||
fieldProps={{ size: 'large', prefix: <LockOutlined /> }}
|
||||
captchaProps={{ size: 'large' }}
|
||||
placeholder="请输入验证码"
|
||||
captchaTextRender={() => (
|
||||
<img
|
||||
src={`/api-uaa/validata/code/${uuid}`}
|
||||
alt="验证码"
|
||||
style={{ height: 32, cursor: 'pointer' }}
|
||||
onClick={() => setUuid(uuidv4())}
|
||||
/>
|
||||
)}
|
||||
onGetCaptcha={async () => Promise.resolve()}
|
||||
rules={[{ required: true, message: '请输入验证码' }]}
|
||||
/>
|
||||
<div className="login-form-extra">
|
||||
<ProFormCheckbox noStyle name="autoLogin">自动登录</ProFormCheckbox>
|
||||
</div>
|
||||
</LoginForm>
|
||||
</Spin>
|
||||
</div>
|
||||
</div>
|
||||
<div className="login-footer">© {new Date().getFullYear()} Go-Fly</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default LoginPage;
|
||||
Reference in New Issue
Block a user