feat: add Kanban.useCreateResource
This commit is contained in:
		
							parent
							
								
									622a6d5a27
								
							
						
					
					
						commit
						52699b0302
					
				@ -384,6 +384,9 @@ function generateCardItemSchema(component) {
 | 
			
		||||
              type: 'void',
 | 
			
		||||
              title: '创建数据',
 | 
			
		||||
              'x-decorator': 'Form',
 | 
			
		||||
              'x-decorator-props': {
 | 
			
		||||
                useResource: '{{ Kanban.useCreateResource }}',
 | 
			
		||||
              },
 | 
			
		||||
              'x-component': 'Action.Drawer',
 | 
			
		||||
              'x-component-props': {
 | 
			
		||||
                useOkAction: '{{ Kanban.useCreateAction }}',
 | 
			
		||||
 | 
			
		||||
@ -415,6 +415,27 @@ export const Kanban: any = observer((props: any) => {
 | 
			
		||||
  );
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
Kanban.useCreateResource = ({ onSuccess }) => {
 | 
			
		||||
  const { props } = useKanban();
 | 
			
		||||
  const column = useContext(KanbanColumnContext);
 | 
			
		||||
  const { collection } = useCollectionContext();
 | 
			
		||||
  const resource = Resource.make({
 | 
			
		||||
    resourceName: collection?.name || props.collectionName,
 | 
			
		||||
  });
 | 
			
		||||
  const groupField = props.groupField;
 | 
			
		||||
  const service = useRequest(
 | 
			
		||||
    (params?: any) => {
 | 
			
		||||
      return Promise.resolve({
 | 
			
		||||
        [groupField.name]: column.value
 | 
			
		||||
      });
 | 
			
		||||
    },
 | 
			
		||||
    {
 | 
			
		||||
      onSuccess,
 | 
			
		||||
    },
 | 
			
		||||
  );
 | 
			
		||||
  return { resource, service, initialValues: service.data, ...service };
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
Kanban.useCreateAction = () => {
 | 
			
		||||
  const { service, resource, props } = useKanban();
 | 
			
		||||
  const column = useContext(KanbanColumnContext);
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user