From 5b9332c67373d96e716740127898cd2c3c17f725 Mon Sep 17 00:00:00 2001
From: archer <545436317@qq.com>
Date: Sat, 9 Sep 2023 09:39:54 +0800
Subject: [PATCH] perf: script load
---
client/src/components/ChatBox/index.tsx | 3 +
client/src/pages/_app.tsx | 16 +--
client/src/pages/account/index.tsx | 92 +++++++------
client/src/pages/kb/detail/index.tsx | 174 ++++++++++++------------
client/src/pages/login/index.tsx | 120 ++++++++--------
client/src/types/index.d.ts | 1 -
6 files changed, 206 insertions(+), 200 deletions(-)
diff --git a/client/src/components/ChatBox/index.tsx b/client/src/components/ChatBox/index.tsx
index 86b8255b7..2bbbcfaba 100644
--- a/client/src/components/ChatBox/index.tsx
+++ b/client/src/components/ChatBox/index.tsx
@@ -55,6 +55,7 @@ const SelectDataset = dynamic(() => import('./SelectDataset'));
const InputDataModal = dynamic(() => import('@/pages/kb/detail/components/InputDataModal'));
import styles from './index.module.scss';
+import Script from 'next/script';
const nanoid = customAlphabet('abcdefghijklmnopqrstuvwxyz1234567890', 24);
@@ -535,6 +536,8 @@ const ChatBox = (
return (
+
+
{showEmpty && }
diff --git a/client/src/pages/_app.tsx b/client/src/pages/_app.tsx
index 65491bc40..64fba807b 100644
--- a/client/src/pages/_app.tsx
+++ b/client/src/pages/_app.tsx
@@ -41,16 +41,14 @@ function App({ Component, pageProps }: AppProps) {
const { setLastRoute } = useGlobalStore();
const [scripts, setScripts] = useState([]);
- const [googleClientVerKey, setGoogleVerKey] = useState();
useEffect(() => {
// get init data
(async () => {
const {
- feConfigs: { scripts, googleClientVerKey }
+ feConfigs: { scripts }
} = await clientInitData();
setScripts(scripts || []);
- setGoogleVerKey(googleClientVerKey);
})();
// add window error track
window.onerror = function (msg, url) {
@@ -94,20 +92,10 @@ function App({ Component, pageProps }: AppProps) {
/>
-
-
-
{scripts?.map((item, i) => (
))}
- {googleClientVerKey && (
- <>
-
- >
- )}
+
diff --git a/client/src/pages/account/index.tsx b/client/src/pages/account/index.tsx
index d46dd0d21..d15bafecc 100644
--- a/client/src/pages/account/index.tsx
+++ b/client/src/pages/account/index.tsx
@@ -13,6 +13,7 @@ import UserInfo from './components/Info';
import { serviceSideProps } from '@/utils/i18n';
import { feConfigs } from '@/store/static';
import { useTranslation } from 'react-i18next';
+import Script from 'next/script';
const Promotion = dynamic(() => import('./components/Promotion'));
const BillTable = dynamic(() => import('./components/BillTable'));
@@ -97,51 +98,54 @@ const Account = ({ currentTab }: { currentTab: `${TabEnum}` }) => {
);
return (
-
-
- {isPc ? (
-
-
-
- ) : (
-
- ({
- id: item.id,
- label: item.label
- }))}
- activeId={currentTab}
- onChange={setCurrentTab}
- />
-
- )}
+ <>
+
+
+
+ {isPc ? (
+
+
+
+ ) : (
+
+ ({
+ id: item.id,
+ label: item.label
+ }))}
+ activeId={currentTab}
+ onChange={setCurrentTab}
+ />
+
+ )}
-
- {currentTab === TabEnum.info && }
- {currentTab === TabEnum.promotion && }
- {currentTab === TabEnum.bill && }
- {currentTab === TabEnum.pay && }
- {currentTab === TabEnum.inform && }
-
-
-
-
+
+ {currentTab === TabEnum.info && }
+ {currentTab === TabEnum.promotion && }
+ {currentTab === TabEnum.bill && }
+ {currentTab === TabEnum.pay && }
+ {currentTab === TabEnum.inform && }
+
+
+
+
+ >
);
};
diff --git a/client/src/pages/kb/detail/index.tsx b/client/src/pages/kb/detail/index.tsx
index 9e65d2784..722d50274 100644
--- a/client/src/pages/kb/detail/index.tsx
+++ b/client/src/pages/kb/detail/index.tsx
@@ -23,6 +23,7 @@ import { getTrainingQueueLen } from '@/api/plugins/kb';
import MyTooltip from '@/components/MyTooltip';
import { QuestionOutlineIcon } from '@chakra-ui/icons';
import { feConfigs } from '@/store/static';
+import Script from 'next/script';
const ImportData = dynamic(() => import('./components/Import'), {
ssr: false
@@ -89,96 +90,99 @@ const Detail = ({ kbId, currentTab }: { kbId: string; currentTab: `${TabEnum}` }
});
return (
-
-
- {isPc ? (
-
-
-
-
- {kbDetail.name}
-
-
- {
- setCurrentTab(e);
- }}
- />
-
-
-
- {t('dataset.System Data Queue')}
-
-
-
-
-
- {trainingQueueLen}
-
-
+ <>
+
+
+
+ {isPc ? (
router.back()}
+ flexDirection={'column'}
+ p={4}
+ h={'100%'}
+ flex={'0 0 200px'}
+ borderRight={theme.borders.base}
>
- }
- bg={'white'}
- boxShadow={'1px 1px 9px rgba(0,0,0,0.15)'}
- h={'28px'}
- size={'sm'}
- borderRadius={'50%'}
- aria-label={''}
+
+
+
+ {kbDetail.name}
+
+
+ {
+ setCurrentTab(e);
+ }}
/>
- 全部知识库
+
+
+
+ {t('dataset.System Data Queue')}
+
+
+
+
+
+ {trainingQueueLen}
+
+
+ router.back()}
+ >
+ }
+ bg={'white'}
+ boxShadow={'1px 1px 9px rgba(0,0,0,0.15)'}
+ h={'28px'}
+ size={'sm'}
+ borderRadius={'50%'}
+ aria-label={''}
+ />
+ 全部知识库
+
-
- ) : (
-
- ({
- id: item.id,
- label: item.label
- }))}
- activeId={currentTab}
- onChange={(e: any) => setCurrentTab(e)}
- />
-
- )}
+ ) : (
+
+ ({
+ id: item.id,
+ label: item.label
+ }))}
+ activeId={currentTab}
+ onChange={(e: any) => setCurrentTab(e)}
+ />
+
+ )}
- {!!kbDetail._id && (
-
- {currentTab === TabEnum.data && }
- {currentTab === TabEnum.import && }
- {currentTab === TabEnum.test && }
- {currentTab === TabEnum.info && }
-
- )}
-
-
+ {!!kbDetail._id && (
+
+ {currentTab === TabEnum.data && }
+ {currentTab === TabEnum.import && }
+ {currentTab === TabEnum.test && }
+ {currentTab === TabEnum.info && }
+
+ )}
+
+
+ >
);
};
diff --git a/client/src/pages/login/index.tsx b/client/src/pages/login/index.tsx
index 88078bedc..97364ec5e 100644
--- a/client/src/pages/login/index.tsx
+++ b/client/src/pages/login/index.tsx
@@ -13,6 +13,7 @@ import { serviceSideProps } from '@/utils/i18n';
import { setToken } from '@/utils/user';
import { feConfigs } from '@/store/static';
import CommunityModal from '@/components/CommunityModal';
+import Script from 'next/script';
const RegisterForm = dynamic(() => import('./components/RegisterForm'));
const ForgetPasswordForm = dynamic(() => import('./components/ForgetPasswordForm'));
@@ -53,70 +54,77 @@ const Login = () => {
}
return (
-
+ <>
+ {feConfigs.googleClientVerKey && (
+
+ )}
- {isPc && (
-
- )}
-
-
-
-
- {feConfigs?.show_contact && (
-
- 无法登录,点击联系
-
+ {isPc && (
+
)}
-
-
- {isOpen && }
-
+
+
+
+ {feConfigs?.show_contact && (
+
+ 无法登录,点击联系
+
+ )}
+
+
+
+ {isOpen && }
+
+ >
);
};
diff --git a/client/src/types/index.d.ts b/client/src/types/index.d.ts
index 045228e0e..8e32f4dc4 100644
--- a/client/src/types/index.d.ts
+++ b/client/src/types/index.d.ts
@@ -58,7 +58,6 @@ declare global {
interface Window {
['pdfjs-dist/build/pdf']: any;
- particlesJS: any;
grecaptcha: any;
QRCode: any;
umami?: {