fix: issue with public form page title displaying 'Loading...' (#6569)

This commit is contained in:
Katherine 2025-03-27 11:07:25 +08:00 committed by GitHub
parent ec9dbe865a
commit ce4794bd27
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 15 additions and 2 deletions

View File

@ -24,6 +24,7 @@ import {
TextAreaWithGlobalScope,
ApplicationContext,
useGlobalVariable,
useCompile,
} from '@nocobase/client';
import {
Breadcrumb,
@ -71,6 +72,7 @@ export function AdminPublicFormPage() {
const { t } = usePublicFormTranslation();
const { theme } = useGlobalTheme();
const apiClient = useAPIClient();
const compile = useCompile();
const { token } = AntdTheme.useToken();
const app = useApp();
const environmentCtx = useGlobalVariable('$env');
@ -150,7 +152,7 @@ export function AdminPublicFormPage() {
title: <Link to={`/admin/settings/public-forms`}>{t('Public forms', { ns: NAMESPACE })}</Link>,
},
{
title: title,
title: compile(title),
},
]}
/>

View File

@ -28,6 +28,7 @@ import {
useApp,
useRequest,
VariablesProvider,
useCompile,
} from '@nocobase/client';
import { Input, Modal, Spin } from 'antd';
import React, { createContext, useContext, useEffect, useMemo, useState } from 'react';
@ -35,7 +36,6 @@ import { isDesktop } from 'react-device-detect';
import { useParams } from 'react-router';
import { usePublicSubmitActionProps } from '../hooks';
import { UnEnabledFormPlaceholder, UnFoundFormPlaceholder } from './UnEnabledFormPlaceholder';
import { Button as MobileButton, Dialog as MobileDialog } from 'antd-mobile';
import { MobileDateTimePicker } from './components/MobileDatePicker';
import { MobilePicker } from './components/MobilePicker';
@ -83,6 +83,14 @@ function PublicAPIClientProvider({ children }) {
return <APIClientProvider apiClient={apiClient}>{children}</APIClientProvider>;
}
function useTitle(data) {
const compile = useCompile();
useEffect(() => {
if (!data) return;
document.title = compile(data?.data?.title);
}, [data]);
}
export const PublicFormMessageContext = createContext<any>({});
export const PageBackgroundColor = '#f5f5f5';
@ -174,6 +182,7 @@ function InternalPublicForm() {
);
const [pwd, setPwd] = useState('');
const ctx = useContext(SchemaComponentContext);
useTitle(data);
// 设置的移动端 meta
useEffect(() => {
if (!isDesktop) {

View File

@ -73,6 +73,7 @@ export class PluginPublicFormsServer extends Plugin {
const keys = instance.collection.split(':');
const collectionName = keys.pop();
const dataSourceKey = keys.pop() || 'main';
const title = instance.get('title');
const schema = await uiSchema.getJsonSchema(filterByTk);
const { getAssociationAppends } = parseAssociationNames(dataSourceKey, collectionName, this.app, schema);
const { appends } = getAssociationAppends();
@ -94,6 +95,7 @@ export class PluginPublicFormsServer extends Plugin {
},
),
schema,
title,
};
}