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(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, clientId: 'webApp', deviceId: uuid }); // 检查多种可能的token字段位置 const accessToken = res?.access_token || res?.data?.access_token || res?.accessToken; if (accessToken) { sessionStorage.setItem('access_token', accessToken); // 登录后预热可访问租户树缓存,便于各页快速使用 try { const { ensureTenantCacheTokenGuard, setTenantTreeCache } = await import('@/utils/tenantCache'); const { tenantApi } = await import('@/services/tenant'); ensureTenantCacheTokenGuard(); const treeRes: any = await tenantApi.getAccessibleTenants(); let list: any[] = []; if (typeof treeRes?.success !== 'undefined') list = treeRes.success ? (treeRes.data || []) : []; else if (Array.isArray(treeRes)) list = treeRes as any[]; if (list && list.length) setTenantTreeCache(list); } catch {} localStorage.setItem('tenant_client_id', 'webApp'); 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 (

Go-Fly Admin

G0-Fly后台管理系统,支持多租户与子租户查询。

  • 全球景区智能服务运营商
  • 让旅行记忆触手可及
  • 统一下载/导出与请求封装
} title="Go-Fly Admin" subTitle="请输入账号后继续" initialValues={{ autoLogin: true }} form={form} onFinish={handleSubmit as any} submitter={{ searchConfig: { submitText: '登录' } }} > }} placeholder="请输入租户标识" rules={[{ required: true, message: '请输入租户标识' }]} /> }} placeholder="请输入用户名" rules={[{ required: true, message: '请输入用户名' }]} /> }} placeholder="请输入密码" rules={[{ required: true, message: '请输入密码' }]} /> }} captchaProps={{ size: 'large' }} placeholder="请输入验证码" captchaTextRender={() => ( 验证码 setUuid(uuidv4())} /> )} onGetCaptcha={async () => Promise.resolve()} rules={[{ required: true, message: '请输入验证码' }]} />
自动登录
© {new Date().getFullYear()} Go-Fly
); }; export default LoginPage;