diff --git a/packages/plugins/@nocobase/plugin-file-manager/src/client/hooks/useUploadFiles.ts b/packages/plugins/@nocobase/plugin-file-manager/src/client/hooks/useUploadFiles.ts index fbaf3c513..0156f4fa8 100644 --- a/packages/plugins/@nocobase/plugin-file-manager/src/client/hooks/useUploadFiles.ts +++ b/packages/plugins/@nocobase/plugin-file-manager/src/client/hooks/useUploadFiles.ts @@ -1,6 +1,12 @@ -import { RecordPickerContext, useActionContext, useBlockRequestContext } from '@nocobase/client'; +import { + RecordPickerContext, + useActionContext, + useBlockRequestContext, + useCollection, + useSourceIdFromParentRecord, +} from '@nocobase/client'; import { notification } from 'antd'; -import { useContext } from 'react'; +import { useContext, useMemo } from 'react'; import { useFmTranslation } from '../locale'; // 限制上传文件大小为 10M @@ -10,12 +16,24 @@ export const useUploadFiles = () => { const { service } = useBlockRequestContext(); const { t } = useFmTranslation(); const { setVisible } = useActionContext(); + const { props: blockProps } = useBlockRequestContext(); + const collection = useCollection(); + const sourceId = useSourceIdFromParentRecord(); + const action = useMemo(() => { + let action = `${collection.name}:create`; + if (blockProps?.association) { + const [s, t] = blockProps.association.split('.'); + action = `${s}/${sourceId}/${t}:create`; + } + return action; + }, [collection.name, blockProps?.association, sourceId]); const { setSelectedRows } = useContext(RecordPickerContext) || {}; const uploadingFiles = {}; let pendingNumber = 0; return { + action, /** * 返回 false 会阻止上传,返回 true 会继续上传 */ diff --git a/packages/plugins/@nocobase/plugin-file-manager/src/client/initializers/UploadActionInitializer.tsx b/packages/plugins/@nocobase/plugin-file-manager/src/client/initializers/UploadActionInitializer.tsx index e4e809609..7dee5f507 100644 --- a/packages/plugins/@nocobase/plugin-file-manager/src/client/initializers/UploadActionInitializer.tsx +++ b/packages/plugins/@nocobase/plugin-file-manager/src/client/initializers/UploadActionInitializer.tsx @@ -28,7 +28,7 @@ export const UploadActionInitializer = (props) => { 'x-component': 'Upload.DraggerV2', 'x-component-props': { height: '50vh', - action: `${collection.name}:create`, + // action: `${collection.name}:create`, useProps: '{{useUploadFiles}}', multiple: true, listType: 'picture',