fix: upload action (#3577)
* fix: upload action * fix: useSourceIdFromParentRecord
This commit is contained in:
		
							parent
							
								
									fc5e67d96b
								
							
						
					
					
						commit
						89de8dc113
					
				@ -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 会继续上传
 | 
			
		||||
     */
 | 
			
		||||
 | 
			
		||||
@ -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',
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user