mirror of
https://github.com/labring/FastGPT.git
synced 2025-10-17 00:14:51 +00:00
v4.6.9-alpha (#918)
Co-authored-by: Mufei <327958099@qq.com> Co-authored-by: heheer <71265218+newfish-cmyk@users.noreply.github.com>
This commit is contained in:
@@ -1,25 +1,28 @@
|
||||
import React, { useState, useCallback, useEffect } from 'react';
|
||||
import { Box, Flex, Image, useDisclosure } from '@chakra-ui/react';
|
||||
import { PageTypeEnum } from '@/constants/user';
|
||||
import { Box, Center, Flex, useDisclosure } from '@chakra-ui/react';
|
||||
import { LoginPageTypeEnum } from '@/constants/user';
|
||||
import { useSystemStore } from '@/web/common/system/useSystemStore';
|
||||
import type { ResLogin } from '@/global/support/api/userRes.d';
|
||||
import { useRouter } from 'next/router';
|
||||
import { useUserStore } from '@/web/support/user/useUserStore';
|
||||
import { useChatStore } from '@/web/core/chat/storeChat';
|
||||
import LoginForm from './components/LoginForm';
|
||||
import LoginForm from './components/LoginForm/LoginForm';
|
||||
import dynamic from 'next/dynamic';
|
||||
import { serviceSideProps } from '@/web/common/utils/i18n';
|
||||
import { clearToken, setToken } from '@/web/support/user/auth';
|
||||
import CommunityModal from '@/components/CommunityModal';
|
||||
import Script from 'next/script';
|
||||
import Loading from '@/components/Loading';
|
||||
|
||||
const RegisterForm = dynamic(() => import('./components/RegisterForm'));
|
||||
const ForgetPasswordForm = dynamic(() => import('./components/ForgetPasswordForm'));
|
||||
const WechatForm = dynamic(() => import('./components/LoginForm/WechatForm'));
|
||||
|
||||
const Login = () => {
|
||||
const router = useRouter();
|
||||
const { lastRoute = '' } = router.query as { lastRoute: string };
|
||||
const { feConfigs } = useSystemStore();
|
||||
const [pageType, setPageType] = useState<`${PageTypeEnum}`>(PageTypeEnum.login);
|
||||
const [pageType, setPageType] = useState<`${LoginPageTypeEnum}`>();
|
||||
const { setUserInfo } = useUserStore();
|
||||
const { setLastChatId, setLastChatAppId } = useChatStore();
|
||||
const { isOpen, onOpen, onClose } = useDisclosure();
|
||||
@@ -39,11 +42,12 @@ const Login = () => {
|
||||
[lastRoute, router, setLastChatId, setLastChatAppId, setUserInfo]
|
||||
);
|
||||
|
||||
function DynamicComponent({ type }: { type: `${PageTypeEnum}` }) {
|
||||
function DynamicComponent({ type }: { type: `${LoginPageTypeEnum}` }) {
|
||||
const TypeMap = {
|
||||
[PageTypeEnum.login]: LoginForm,
|
||||
[PageTypeEnum.register]: RegisterForm,
|
||||
[PageTypeEnum.forgetPassword]: ForgetPasswordForm
|
||||
[LoginPageTypeEnum.passwordLogin]: LoginForm,
|
||||
[LoginPageTypeEnum.register]: RegisterForm,
|
||||
[LoginPageTypeEnum.forgetPassword]: ForgetPasswordForm,
|
||||
[LoginPageTypeEnum.wechat]: WechatForm
|
||||
};
|
||||
|
||||
const Component = TypeMap[type];
|
||||
@@ -51,6 +55,13 @@ const Login = () => {
|
||||
return <Component setPageType={setPageType} loginSuccess={loginSuccess} />;
|
||||
}
|
||||
|
||||
/* default login type */
|
||||
useEffect(() => {
|
||||
if (!feConfigs.oauth) return;
|
||||
setPageType(
|
||||
feConfigs.oauth?.wechat ? LoginPageTypeEnum.wechat : LoginPageTypeEnum.passwordLogin
|
||||
);
|
||||
}, [feConfigs.oauth, feConfigs.oauth?.wechat]);
|
||||
useEffect(() => {
|
||||
clearToken();
|
||||
router.prefetch('/app/list');
|
||||
@@ -87,7 +98,13 @@ const Login = () => {
|
||||
]}
|
||||
>
|
||||
<Box w={['100%', '380px']} flex={'1 0 0'}>
|
||||
<DynamicComponent type={pageType} />
|
||||
{pageType ? (
|
||||
<DynamicComponent type={pageType} />
|
||||
) : (
|
||||
<Center w={'full'} h={'full'} position={'relative'}>
|
||||
<Loading fixed={false} />
|
||||
</Center>
|
||||
)}
|
||||
</Box>
|
||||
{feConfigs?.concatMd && (
|
||||
<Box
|
||||
|
Reference in New Issue
Block a user