feat: data config set scripts

This commit is contained in:
archer
2023-08-10 09:36:55 +08:00
parent b7b222fdfb
commit 85feb005b9
3 changed files with 11 additions and 7 deletions

View File

@@ -7,7 +7,8 @@
"show_git": true, "show_git": true,
"systemTitle": "FastGPT", "systemTitle": "FastGPT",
"authorText": "Made by FastGPT Team.", "authorText": "Made by FastGPT Team.",
"gitLoginKey": "" "gitLoginKey": "",
"scripts": []
}, },
"SystemParams": { "SystemParams": {
"gitLoginSecret": "", "gitLoginSecret": "",

View File

@@ -15,6 +15,7 @@ import { useRouter } from 'next/router';
import 'nprogress/nprogress.css'; import 'nprogress/nprogress.css';
import '@/styles/reset.scss'; import '@/styles/reset.scss';
import { FeConfigsType } from '@/types';
//Binding events. //Binding events.
Router.events.on('routeChangeStart', () => NProgress.start()); Router.events.on('routeChangeStart', () => NProgress.start());
@@ -36,16 +37,16 @@ function App({ Component, pageProps }: AppProps) {
const router = useRouter(); const router = useRouter();
const { i18n } = useTranslation(); const { i18n } = useTranslation();
const [scripts, setScripts] = useState<FeConfigsType['scripts']>([]);
const [googleClientVerKey, setGoogleVerKey] = useState<string>(); const [googleClientVerKey, setGoogleVerKey] = useState<string>();
const [baiduTongjiUrl, setBaiduTongjiUrl] = useState<string>();
useEffect(() => { useEffect(() => {
(async () => { (async () => {
const { const {
feConfigs: { googleClientVerKey, baiduTongjiUrl } feConfigs: { scripts, googleClientVerKey }
} = await clientInitData(); } = await clientInitData();
setScripts(scripts || []);
setGoogleVerKey(googleClientVerKey); setGoogleVerKey(googleClientVerKey);
setBaiduTongjiUrl(baiduTongjiUrl);
})(); })();
}, []); }, []);
@@ -68,12 +69,14 @@ function App({ Component, pageProps }: AppProps) {
<Script src="/js/qrcode.min.js" strategy="lazyOnload"></Script> <Script src="/js/qrcode.min.js" strategy="lazyOnload"></Script>
<Script src="/js/pdf.js" strategy="lazyOnload"></Script> <Script src="/js/pdf.js" strategy="lazyOnload"></Script>
<Script src="/js/html2pdf.bundle.min.js" strategy="lazyOnload"></Script> <Script src="/js/html2pdf.bundle.min.js" strategy="lazyOnload"></Script>
{baiduTongjiUrl && <Script src={baiduTongjiUrl} strategy="lazyOnload"></Script>} {scripts?.map((item, i) => (
<Script key={i} strategy="lazyOnload" {...item}></Script>
))}
{googleClientVerKey && ( {googleClientVerKey && (
<> <>
<Script <Script
src={`https://www.recaptcha.net/recaptcha/api.js?render=${googleClientVerKey}`} src={`https://www.recaptcha.net/recaptcha/api.js?render=${googleClientVerKey}`}
strategy="afterInteractive" strategy="lazyOnload"
></Script> ></Script>
</> </>
)} )}

View File

@@ -23,8 +23,8 @@ export type FeConfigsType = {
authorText?: string; authorText?: string;
beianText?: string; beianText?: string;
googleClientVerKey?: string; googleClientVerKey?: string;
baiduTongjiUrl?: string;
gitLoginKey?: string; gitLoginKey?: string;
scripts?: { [key: string]: string }[];
}; };
export type SystemEnvType = { export type SystemEnvType = {
googleServiceVerKey?: string; googleServiceVerKey?: string;