fix: upload action (#3577)

* fix: upload action

* fix: useSourceIdFromParentRecord
This commit is contained in:
chenos 2024-02-28 08:49:35 +08:00 committed by GitHub
parent fc5e67d96b
commit 89de8dc113
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 21 additions and 3 deletions

View File

@ -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 { notification } from 'antd';
import { useContext } from 'react'; import { useContext, useMemo } from 'react';
import { useFmTranslation } from '../locale'; import { useFmTranslation } from '../locale';
// 限制上传文件大小为 10M // 限制上传文件大小为 10M
@ -10,12 +16,24 @@ export const useUploadFiles = () => {
const { service } = useBlockRequestContext(); const { service } = useBlockRequestContext();
const { t } = useFmTranslation(); const { t } = useFmTranslation();
const { setVisible } = useActionContext(); 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 { setSelectedRows } = useContext(RecordPickerContext) || {};
const uploadingFiles = {}; const uploadingFiles = {};
let pendingNumber = 0; let pendingNumber = 0;
return { return {
action,
/** /**
* false true * false true
*/ */

View File

@ -28,7 +28,7 @@ export const UploadActionInitializer = (props) => {
'x-component': 'Upload.DraggerV2', 'x-component': 'Upload.DraggerV2',
'x-component-props': { 'x-component-props': {
height: '50vh', height: '50vh',
action: `${collection.name}:create`, // action: `${collection.name}:create`,
useProps: '{{useUploadFiles}}', useProps: '{{useUploadFiles}}',
multiple: true, multiple: true,
listType: 'picture', listType: 'picture',