From b8bc32f4218af2e9387b81118a210553132a3fad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=A2=AB=E9=9B=A8=E6=B0=B4=E8=BF=87=E6=BB=A4=E7=9A=84?= =?UTF-8?q?=E7=A9=BA=E6=B0=94-Rain?= <958414905@qq.com> Date: Wed, 25 Oct 2023 22:50:28 +0800 Subject: [PATCH] fix: disappearing of fixed-block option (#2914) --- .../src/schema-component/antd/page/FixedBlock.tsx | 13 +++++++------ .../antd/page/hooks/useIsBlockInPage.ts | 15 +++++++++++++++ 2 files changed, 22 insertions(+), 6 deletions(-) create mode 100644 packages/core/client/src/schema-component/antd/page/hooks/useIsBlockInPage.ts 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 }; +};