diff --git a/packages/core/client/src/schema-component/antd/page/FixedBlock.tsx b/packages/core/client/src/schema-component/antd/page/FixedBlock.tsx index ebc2fee89..3eab38abf 100644 --- a/packages/core/client/src/schema-component/antd/page/FixedBlock.tsx +++ b/packages/core/client/src/schema-component/antd/page/FixedBlock.tsx @@ -1,10 +1,11 @@ -import React, { useContext, useEffect, useMemo, useRef, useState } from 'react'; -import { useField, useFieldSchema } from '@formily/react'; import { css } from '@emotion/css'; -import { SchemaSettings } from '../../../schema-settings'; +import { useField, useFieldSchema } from '@formily/react'; +import React, { useContext, useEffect, useRef, useState } from 'react'; import { useTranslation } from 'react-i18next'; -import { useDesignable } from '../../hooks'; import { useRecord } from '../../../record-provider'; +import { SchemaSettings } from '../../../schema-settings'; +import { useDesignable } from '../../hooks'; +import { useIsBlockInPage } from './hooks/useIsBlockInPage'; const FixedBlockContext = React.createContext<{ setFixedBlock: (value: string | false) => void; @@ -70,10 +71,10 @@ export const FixedBlockDesignerItem = () => { const { t } = useTranslation(); const fieldSchema = useFieldSchema(); const { dn } = useDesignable(); - const record = useRecord(); const { inFixedBlock } = useFixedBlock(); + const { isBlockInPage } = useIsBlockInPage(); - if (Object.keys(record).length || !inFixedBlock) { + if (!isBlockInPage() || !inFixedBlock) { return null; } return ( diff --git a/packages/core/client/src/schema-component/antd/page/hooks/useIsBlockInPage.ts b/packages/core/client/src/schema-component/antd/page/hooks/useIsBlockInPage.ts new file mode 100644 index 000000000..1d7b3a55f --- /dev/null +++ b/packages/core/client/src/schema-component/antd/page/hooks/useIsBlockInPage.ts @@ -0,0 +1,15 @@ +import { useCallback } from 'react'; +import { useActionContext } from '../../action'; + +/** + * 判断当前区块是否在页面而不是在弹窗中 + */ +export const useIsBlockInPage = () => { + const { visible } = useActionContext(); + + const isBlockInPage = useCallback(() => { + return !visible; + }, [visible]); + + return { isBlockInPage }; +};