fix: improve code

This commit is contained in:
chenos 2025-06-29 13:12:42 +08:00
parent 4ec878af8c
commit bc0394cdb4
4 changed files with 21 additions and 12 deletions

View File

@ -159,3 +159,7 @@ QuickEditForm.registerFlow({
}, },
}, },
}); });
QuickEditForm.define({
hide: true,
});

View File

@ -212,13 +212,7 @@ export class TableModel extends DataBlockModel<TableModelStructure> {
return ( return (
<Card> <Card>
<Spin spinning={this.resource.loading}> <Spin spinning={this.resource.loading}>
<DndProvider <DndProvider>
onDragEnd={({ active, over }) => {
if (active.id && over?.id && active.id !== over.id) {
this.flowEngine.moveModel(active.id as string, over.id as string);
}
}}
>
<div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', marginBottom: 16 }}> <div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', marginBottom: 16 }}>
<Space> <Space>
{this.mapSubModels('actions', (action) => { {this.mapSubModels('actions', (action) => {
@ -235,6 +229,8 @@ export class TableModel extends DataBlockModel<TableModelStructure> {
return null; return null;
})} })}
{/* 占位 */}
<span></span>
</Space> </Space>
<Space> <Space>
{this.mapSubModels('actions', (action) => { {this.mapSubModels('actions', (action) => {

View File

@ -11,6 +11,7 @@ import { DragOutlined } from '@ant-design/icons';
import { DndContext, DndContextProps, DragOverlay, useDraggable, useDroppable } from '@dnd-kit/core'; import { DndContext, DndContextProps, DragOverlay, useDraggable, useDroppable } from '@dnd-kit/core';
import React, { FC, useState } from 'react'; import React, { FC, useState } from 'react';
import { FlowModel } from '../../models'; import { FlowModel } from '../../models';
import { useFlowEngine } from '../../provider';
// 可拖拽图标组件 // 可拖拽图标组件
export const DragHandler: FC<{ model: FlowModel }> = ({ model, children = <DragOutlined /> }) => { export const DragHandler: FC<{ model: FlowModel }> = ({ model, children = <DragOutlined /> }) => {
@ -58,9 +59,9 @@ export const Droppable: FC<{ model: FlowModel; children: React.ReactNode }> = ({
}; };
// 提供一个封装了 DragOverlay 的 DndProvider 组件,继承 DndContext 的所有 props // 提供一个封装了 DragOverlay 的 DndProvider 组件,继承 DndContext 的所有 props
export const DndProvider: FC<DndContextProps> = ({ children, ...restProps }) => { export const DndProvider: FC<DndContextProps> = ({ children, onDragEnd, ...restProps }) => {
const [activeId, setActiveId] = useState<string | null>(null); const [activeId, setActiveId] = useState<string | null>(null);
const flowEngine = useFlowEngine();
return ( return (
<DndContext <DndContext
onDragStart={(event) => { onDragStart={(event) => {
@ -69,7 +70,15 @@ export const DndProvider: FC<DndContextProps> = ({ children, ...restProps }) =>
}} }}
onDragEnd={(event) => { onDragEnd={(event) => {
setActiveId(null); setActiveId(null);
restProps.onDragEnd?.(event); // 如果没有 onDragEnd 回调,则默认调用 flowEngine 的 moveModel 方法
if (!onDragEnd) {
if (event.over) {
flowEngine.moveModel(event.active.id, event.over.id);
}
} else {
// 如果有 onDragEnd 回调,则调用它
onDragEnd(event);
}
}} }}
{...restProps} {...restProps}
> >

View File

@ -8,10 +8,10 @@
*/ */
import { ISchema } from '@formily/json-schema'; import { ISchema } from '@formily/json-schema';
import { APIClient } from '@nocobase/sdk';
import type { FlowEngine } from './flowEngine'; import type { FlowEngine } from './flowEngine';
import type { FlowModel } from './models'; import type { FlowModel } from './models';
import { ReactView } from './ReactView'; import { ReactView } from './ReactView';
import { APIClient } from '@nocobase/sdk';
/** /**
* T T * T T
@ -326,7 +326,7 @@ export interface FlowModelOptions<Structure extends { parent?: FlowModel; subMod
} }
export interface FlowModelMeta { export interface FlowModelMeta {
title: string; title?: string;
group?: string; group?: string;
requiresDataSource?: boolean; // 是否需要数据源 requiresDataSource?: boolean; // 是否需要数据源
defaultOptions?: Record<string, any>; defaultOptions?: Record<string, any>;