mirror of
https://gitee.com/nocobase/nocobase.git
synced 2025-07-01 18:52:20 +08:00
fix: improve code
This commit is contained in:
parent
4ec878af8c
commit
bc0394cdb4
@ -159,3 +159,7 @@ QuickEditForm.registerFlow({
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
QuickEditForm.define({
|
||||||
|
hide: true,
|
||||||
|
});
|
||||||
|
@ -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) => {
|
||||||
|
@ -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}
|
||||||
>
|
>
|
||||||
|
@ -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>;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user