diff --git a/packages/core/client/src/block-provider/DetailsBlockProvider.tsx b/packages/core/client/src/block-provider/DetailsBlockProvider.tsx index 8899a1e5a..a0abf1c1b 100644 --- a/packages/core/client/src/block-provider/DetailsBlockProvider.tsx +++ b/packages/core/client/src/block-provider/DetailsBlockProvider.tsx @@ -2,7 +2,7 @@ import { createForm } from '@formily/core'; import { useField } from '@formily/react'; import { Spin } from 'antd'; import _ from 'lodash'; -import React, { createContext, useContext, useEffect, useMemo } from 'react'; +import React, { createContext, useContext, useEffect, useMemo, useRef } from 'react'; import { useCollectionParentRecord } from '../data-source/collection-record/CollectionRecordProvider'; import { RecordProvider } from '../record-provider'; import { BlockProvider, useBlockRequestContext } from './BlockProvider'; @@ -25,6 +25,7 @@ const InternalDetailsBlockProvider = (props) => { const { resource, service } = useBlockRequestContext(); const parentRecord = useCollectionParentRecord(); const currentRecord = (action === 'list' ? service?.data?.data?.[0] : service?.data?.data) || {}; + const formBlockRef = useRef(); const detailsBLockValue = useMemo(() => { return { action, @@ -32,6 +33,7 @@ const InternalDetailsBlockProvider = (props) => { field, service, resource, + formBlockRef, }; }, [action, field, form, resource, service]); @@ -51,9 +53,11 @@ const InternalDetailsBlockProvider = (props) => { return ( - - {props.children} - +
+ + {props.children} + +
); }; diff --git a/packages/core/client/src/block-provider/index.tsx b/packages/core/client/src/block-provider/index.tsx index 422b36faf..9074b0d19 100644 --- a/packages/core/client/src/block-provider/index.tsx +++ b/packages/core/client/src/block-provider/index.tsx @@ -6,4 +6,5 @@ export * from './FormFieldProvider'; export * from './TableBlockProvider'; export * from './TableFieldProvider'; export * from './TableSelectorProvider'; +export * from './DetailsBlockProvider'; export * from './hooks'; diff --git a/packages/plugins/@nocobase/plugin-action-print/src/client/utils.ts b/packages/plugins/@nocobase/plugin-action-print/src/client/utils.ts index 23785a01e..1412c6f97 100644 --- a/packages/plugins/@nocobase/plugin-action-print/src/client/utils.ts +++ b/packages/plugins/@nocobase/plugin-action-print/src/client/utils.ts @@ -1,9 +1,8 @@ -import { useFormBlockContext } from '@nocobase/client'; +import { useDetailsBlockContext } from '@nocobase/client'; import { useReactToPrint } from 'react-to-print'; export const useDetailPrintActionProps = () => { - const { formBlockRef } = useFormBlockContext(); - + const { formBlockRef } = useDetailsBlockContext(); const printHandler = useReactToPrint({ content: () => formBlockRef.current, pageStyle: `@media print {