fix: left menu title modify (#3956)

This commit is contained in:
jack zhang 2024-04-07 16:14:02 +08:00 committed by GitHub
parent 89b73ba389
commit 606ef55db8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 19 additions and 14 deletions

View File

@ -126,18 +126,6 @@ const MenuEditor = (props) => {
},
);
const match = useMatch('/admin/:name');
useEffect(() => {
if (match) {
const schema = filterByACL(data?.data, ctx);
const s = findByUid(schema, defaultSelectedUid);
if (s) {
setTitle(s.title);
}
}
}, [data?.data, location.pathname, defaultSelectedUid]);
useEffect(() => {
const properties = Object.values(current?.root?.properties || {}).shift()?.['properties'] || data?.data?.properties;
if (sideMenuRef.current) {

View File

@ -4,7 +4,7 @@ import { ISchema, Schema, useField, useFieldSchema } from '@formily/react';
import React from 'react';
import { useTranslation } from 'react-i18next';
import { findByUid } from '.';
import { createDesignable } from '../..';
import { createDesignable, useCompile } from '../..';
import {
GeneralSchemaDesigner,
SchemaSettingsDivider,
@ -208,6 +208,8 @@ export const MenuDesigner = () => {
const { dn, refresh } = useDesignable();
const { t } = useTranslation();
const menuSchema = findMenuSchema(fieldSchema);
const compile = useCompile();
const onSelect = compile(menuSchema?.['x-component-props']?.['onSelect']);
const items = toItems(menuSchema?.properties);
const effects = (form) => {
onFieldChange('target', (field: Field) => {
@ -286,6 +288,7 @@ export const MenuDesigner = () => {
fieldSchema['x-component-props'] = fieldSchema['x-component-props'] || {};
fieldSchema['x-component-props']['icon'] = icon;
fieldSchema['x-component-props']['href'] = href;
onSelect?.({ item: { props: { schema: fieldSchema } } });
dn.emit('patch', {
schema,
});

View File

@ -24,6 +24,7 @@ import { ErrorFallback } from '../error-fallback';
import FixedBlock from './FixedBlock';
import { PageDesigner, PageTabDesigner } from './PageTabDesigner';
import { useStyles } from './style';
import { useRequest } from '../../../api-client';
export const Page = (props) => {
const { children, ...others } = props;
@ -62,11 +63,24 @@ export const Page = (props) => {
const { wrapSSR, hashId, componentCls } = useStyles();
const aclStyles = useAClStyles();
const pageHeaderTitle = hidePageTitle ? undefined : fieldSchema.title || compile(title);
useRequest(
{
url: `/uiSchemas:getParentJsonSchema/${fieldSchema['x-uid']}`,
},
{
ready: !hidePageTitle && !pageHeaderTitle,
onSuccess(data) {
setTitle(data.data.title);
},
},
);
const handleErrors = (error) => {
console.error(error);
};
const pageHeaderTitle = hidePageTitle ? undefined : fieldSchema.title || compile(title);
return wrapSSR(
<div className={`${componentCls} ${hashId} ${aclStyles.styles}`}>
<PageDesigner title={fieldSchema.title || title} />