perf: ssr and iphone daapt

This commit is contained in:
archer
2023-05-11 09:50:40 +08:00
parent 1ab45651e0
commit 451f234f68
8 changed files with 67 additions and 33 deletions

View File

@@ -1,12 +1,12 @@
import React, { useEffect, useMemo } from 'react'; import React, { useEffect, useMemo } from 'react';
import { Box, useColorMode, Flex } from '@chakra-ui/react'; import { Box, useColorMode, Flex } from '@chakra-ui/react';
import Navbar from './navbar';
import NavbarPhone from './navbarPhone';
import { useRouter } from 'next/router'; import { useRouter } from 'next/router';
import { useScreen } from '@/hooks/useScreen'; import { useScreen } from '@/hooks/useScreen';
import { useLoading } from '@/hooks/useLoading'; import { useLoading } from '@/hooks/useLoading';
import Auth from './auth';
import { useGlobalStore } from '@/store/global'; import { useGlobalStore } from '@/store/global';
import Auth from './auth';
import Navbar from './navbar';
import NavbarPhone from './navbarPhone';
const pcUnShowLayoutRoute: Record<string, boolean> = { const pcUnShowLayoutRoute: Record<string, boolean> = {
'/login': true '/login': true

View File

@@ -0,0 +1,22 @@
import React from 'react';
import { Spinner, Flex } from '@chakra-ui/react';
const Loading = ({ fixed = true }: { fixed?: boolean }) => {
return (
<Flex
position={fixed ? 'fixed' : 'absolute'}
zIndex={100}
backgroundColor={'rgba(255,255,255,0.5)'}
top={0}
left={0}
right={0}
bottom={0}
alignItems={'center'}
justifyContent={'center'}
>
<Spinner thickness="4px" speed="0.65s" emptyColor="gray.200" color="myBlue.500" size="xl" />
</Flex>
);
};
export default Loading;

View File

@@ -1,32 +1,12 @@
import { useState, useCallback } from 'react'; import { useState, useCallback } from 'react';
import { Spinner, Flex } from '@chakra-ui/react'; import LoadingComponent from '@/components/Loading';
export const useLoading = (props?: { defaultLoading: boolean }) => { export const useLoading = (props?: { defaultLoading: boolean }) => {
const [isLoading, setIsLoading] = useState(props?.defaultLoading || false); const [isLoading, setIsLoading] = useState(props?.defaultLoading || false);
const Loading = useCallback( const Loading = useCallback(
({ loading, fixed = true }: { loading?: boolean; fixed?: boolean }): JSX.Element | null => { ({ loading, fixed = true }: { loading?: boolean; fixed?: boolean }): JSX.Element | null => {
return isLoading || loading ? ( return isLoading || loading ? <LoadingComponent fixed={fixed} /> : null;
<Flex
position={fixed ? 'fixed' : 'absolute'}
zIndex={100}
backgroundColor={'rgba(255,255,255,0.5)'}
top={0}
left={0}
right={0}
bottom={0}
alignItems={'center'}
justifyContent={'center'}
>
<Spinner
thickness="4px"
speed="0.65s"
emptyColor="gray.200"
color="myBlue.500"
size="xl"
/>
</Flex>
) : null;
}, },
[isLoading] [isLoading]
); );

View File

@@ -45,9 +45,10 @@ export default function App({ Component, pageProps }: AppProps) {
<Head> <Head>
<title>Fast GPT</title> <title>Fast GPT</title>
<meta name="description" content="Generated by Fast GPT" /> <meta name="description" content="Generated by Fast GPT" />
<meta <meta
name="viewport" name="viewport"
content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" content="width=device-width,initial-scale=1.0,maximum-scale=1.0,minimum-scale=1.0,user-scalable=no, viewport-fit=cover"
/> />
<link rel="icon" href="/favicon.ico" /> <link rel="icon" href="/favicon.ico" />
</Head> </Head>

View File

@@ -44,10 +44,20 @@ import { useLoading } from '@/hooks/useLoading';
import { fileDownload } from '@/utils/file'; import { fileDownload } from '@/utils/file';
import { htmlTemplate } from '@/constants/common'; import { htmlTemplate } from '@/constants/common';
import { useUserStore } from '@/store/user'; import { useUserStore } from '@/store/user';
import Loading from '@/components/Loading';
const PhoneSliderBar = dynamic(() => import('./components/PhoneSliderBar')); const PhoneSliderBar = dynamic(() => import('./components/PhoneSliderBar'), {
const History = dynamic(() => import('./components/History')); loading: () => <Loading fixed={false} />,
const Empty = dynamic(() => import('./components/Empty')); ssr: false
});
const History = dynamic(() => import('./components/History'), {
loading: () => <Loading fixed={false} />,
ssr: false
});
const Empty = dynamic(() => import('./components/Empty'), {
loading: () => <Loading fixed={false} />,
ssr: false
});
import styles from './index.module.scss'; import styles from './index.module.scss';

View File

@@ -5,8 +5,12 @@ import { useRouter } from 'next/router';
import ModelList from './components/ModelList'; import ModelList from './components/ModelList';
import dynamic from 'next/dynamic'; import dynamic from 'next/dynamic';
import { useUserStore } from '@/store/user'; import { useUserStore } from '@/store/user';
import Loading from '@/components/Loading';
const ModelDetail = dynamic(() => import('./components/detail/index')); const ModelDetail = dynamic(() => import('./components/detail/index'), {
loading: () => <Loading fixed={false} />,
ssr: false
});
const Model = ({ modelId, isPcDevice }: { modelId: string; isPcDevice: boolean }) => { const Model = ({ modelId, isPcDevice }: { modelId: string; isPcDevice: boolean }) => {
const router = useRouter(); const router = useRouter();

View File

@@ -13,10 +13,20 @@ import { useQuery } from '@tanstack/react-query';
import dynamic from 'next/dynamic'; import dynamic from 'next/dynamic';
import { useSelectFile } from '@/hooks/useSelectFile'; import { useSelectFile } from '@/hooks/useSelectFile';
import { compressImg } from '@/utils/file'; import { compressImg } from '@/utils/file';
import Loading from '@/components/Loading';
const PayRecordTable = dynamic(() => import('./components/PayRecordTable')); const PayRecordTable = dynamic(() => import('./components/PayRecordTable'), {
const BilTable = dynamic(() => import('./components/BillTable')); loading: () => <Loading fixed={false} />,
const PayModal = dynamic(() => import('./components/PayModal')); ssr: false
});
const BilTable = dynamic(() => import('./components/BillTable'), {
loading: () => <Loading fixed={false} />,
ssr: false
});
const PayModal = dynamic(() => import('./components/PayModal'), {
loading: () => <Loading fixed={false} />,
ssr: false
});
const NumberSetting = () => { const NumberSetting = () => {
const router = useRouter(); const router = useRouter();

View File

@@ -87,6 +87,13 @@ textarea::placeholder {
} }
} }
@supports (bottom: constant(safe-area-inset-bottom)) or (bottom: env(safe-area-inset-bottom)) {
body {
padding-bottom: constant(safe-area-inset-bottom);
padding-bottom: env(safe-area-inset-bottom);
}
}
#nprogress .bar { #nprogress .bar {
background: '#85b1ff' !important; //自定义颜色 background: '#85b1ff' !important; //自定义颜色
} }