fix: reporting error when clicking on the print button for the detail block (#3845)
This commit is contained in:
parent
8a215e2fbe
commit
e88082232d
@ -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 (
|
||||
<DetailsBlockContext.Provider value={detailsBLockValue}>
|
||||
<div ref={formBlockRef}>
|
||||
<RecordProvider isNew={false} record={currentRecord} parent={parentRecord?.data}>
|
||||
{props.children}
|
||||
</RecordProvider>
|
||||
</div>
|
||||
</DetailsBlockContext.Provider>
|
||||
);
|
||||
};
|
||||
|
@ -6,4 +6,5 @@ export * from './FormFieldProvider';
|
||||
export * from './TableBlockProvider';
|
||||
export * from './TableFieldProvider';
|
||||
export * from './TableSelectorProvider';
|
||||
export * from './DetailsBlockProvider';
|
||||
export * from './hooks';
|
||||
|
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user