mirror of
https://github.com/labring/FastGPT.git
synced 2025-07-27 08:25:07 +00:00
ssr init
This commit is contained in:
@@ -63,7 +63,7 @@ const Layout = ({ children }: { children: JSX.Element }) => {
|
||||
return (
|
||||
<>
|
||||
<Box h={'100%'} bg={'myWhite.600'}>
|
||||
{isPc ? (
|
||||
{isPc === true && (
|
||||
<>
|
||||
{pcUnShowLayoutRoute[router.pathname] ? (
|
||||
<Auth>{children}</Auth>
|
||||
@@ -78,7 +78,8 @@ const Layout = ({ children }: { children: JSX.Element }) => {
|
||||
</>
|
||||
)}
|
||||
</>
|
||||
) : (
|
||||
)}
|
||||
{isPc === false && (
|
||||
<>
|
||||
<Box h={'100%'} display={['block', 'none']}>
|
||||
{phoneUnShowLayoutRoute[router.pathname] || isChatPage ? (
|
||||
|
@@ -11,6 +11,9 @@ import Router from 'next/router';
|
||||
import 'nprogress/nprogress.css';
|
||||
import '@/styles/reset.scss';
|
||||
import { clientInitData } from '@/store/static';
|
||||
import { NextPageContext } from 'next';
|
||||
import { useGlobalStore } from '@/store/global';
|
||||
import { GET } from '@/service/api/axios';
|
||||
|
||||
//Binding events.
|
||||
Router.events.on('routeChangeStart', () => NProgress.start());
|
||||
@@ -28,9 +31,14 @@ const queryClient = new QueryClient({
|
||||
}
|
||||
});
|
||||
|
||||
function App({ Component, pageProps }: AppProps) {
|
||||
function App({ Component, pageProps, isPc }: AppProps & { isPc?: boolean; response: any }) {
|
||||
const [googleVerKey, setGoogleVerKey] = useState<string>();
|
||||
const [baiduTongji, setBaiduTongji] = useState<string>();
|
||||
const { initIsPc } = useGlobalStore();
|
||||
|
||||
if (isPc !== undefined) {
|
||||
initIsPc(isPc);
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
(async () => {
|
||||
@@ -76,4 +84,12 @@ function App({ Component, pageProps }: AppProps) {
|
||||
);
|
||||
}
|
||||
|
||||
App.getInitialProps = async ({ ctx }: { ctx: NextPageContext }) => {
|
||||
const reg = /mobile/gi;
|
||||
|
||||
const isPc = !reg.test(ctx.req?.headers?.['user-agent'] || '');
|
||||
|
||||
return { isPc };
|
||||
};
|
||||
|
||||
export default App;
|
||||
|
@@ -1,4 +1,13 @@
|
||||
import { useEffect } from 'react';
|
||||
import { useRouter } from 'next/router';
|
||||
function Error() {
|
||||
const router = useRouter();
|
||||
useEffect(() => {
|
||||
setTimeout(() => {
|
||||
router.replace('/app/list');
|
||||
}, 2000);
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<p>
|
||||
部分系统不兼容,导致页面崩溃。如果可以,请联系作者,反馈下具体操作和页面。大部分是 苹果 的
|
||||
|
@@ -90,7 +90,9 @@ const ShareChat = ({ shareId, historyId }: { shareId: string; historyId: string
|
||||
|
||||
const loadAppInfo = useCallback(
|
||||
async (shareId: string, historyId: string) => {
|
||||
if (!shareId || !historyId) return null;
|
||||
console.log(shareId, historyId);
|
||||
|
||||
if (!shareId) return null;
|
||||
const history = shareChatHistory.find((item) => item._id === historyId) || defaultHistory;
|
||||
|
||||
ChatBoxRef.current?.resetHistory(history.chats);
|
||||
@@ -129,9 +131,9 @@ const ShareChat = ({ shareId, historyId }: { shareId: string; historyId: string
|
||||
[delManyShareChatHistoryByShareId, setShareChatData, shareChatData, shareChatHistory, toast]
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
loadAppInfo(shareId, historyId);
|
||||
}, [shareId, historyId]);
|
||||
useQuery(['init', shareId, historyId], () => {
|
||||
return loadAppInfo(shareId, historyId);
|
||||
});
|
||||
|
||||
return (
|
||||
<PageContainer>
|
||||
@@ -168,7 +170,6 @@ const ShareChat = ({ shareId, historyId }: { shareId: string; historyId: string
|
||||
}
|
||||
}}
|
||||
onDelHistory={delOneShareHistoryByHistoryId}
|
||||
onCloseSlider={onCloseSlider}
|
||||
/>
|
||||
)}
|
||||
|
||||
|
@@ -145,6 +145,12 @@ const Info = (
|
||||
|
||||
return (
|
||||
<Flex p={5} flexDirection={'column'} alignItems={'center'}>
|
||||
<Flex mt={5} w={'100%'} maxW={'350px'} alignItems={'center'}>
|
||||
<Box flex={'0 0 90px'} w={0}>
|
||||
知识库 ID
|
||||
</Box>
|
||||
<Box flex={1}>{kbDetail._id}</Box>
|
||||
</Flex>
|
||||
<Flex mt={5} w={'100%'} maxW={'350px'} alignItems={'center'}>
|
||||
<Box flex={'0 0 90px'} w={0}>
|
||||
知识库头像
|
||||
|
@@ -7,7 +7,8 @@ type State = {
|
||||
setLoading: (val: boolean) => null;
|
||||
screenWidth: number;
|
||||
setScreenWidth: (val: number) => void;
|
||||
isPc: boolean;
|
||||
isPc?: boolean;
|
||||
initIsPc(val: boolean): void;
|
||||
};
|
||||
|
||||
export const useGlobalStore = create<State>()(
|
||||
@@ -27,7 +28,14 @@ export const useGlobalStore = create<State>()(
|
||||
state.isPc = val < 900 ? false : true;
|
||||
});
|
||||
},
|
||||
isPc: false
|
||||
isPc: undefined,
|
||||
initIsPc(val: boolean) {
|
||||
if (get().isPc !== undefined) return;
|
||||
|
||||
set((state) => {
|
||||
state.isPc = val;
|
||||
});
|
||||
}
|
||||
}))
|
||||
)
|
||||
);
|
||||
|
Reference in New Issue
Block a user