mirror of
https://github.com/nocobase/nocobase
synced 2024-11-15 16:36:56 +00:00
feat: improve code
This commit is contained in:
parent
80f4635bb6
commit
7eb6297d0f
@ -6,7 +6,16 @@ import {
|
|||||||
useField,
|
useField,
|
||||||
useForm,
|
useForm,
|
||||||
} from '@formily/react';
|
} from '@formily/react';
|
||||||
import { DndContext, DragOverlay, closestCorners } from '@dnd-kit/core';
|
import {
|
||||||
|
DndContext,
|
||||||
|
DragOverlay,
|
||||||
|
closestCorners,
|
||||||
|
rectIntersection,
|
||||||
|
closestCenter,
|
||||||
|
useSensors,
|
||||||
|
useSensor,
|
||||||
|
MouseSensor,
|
||||||
|
} from '@dnd-kit/core';
|
||||||
import {
|
import {
|
||||||
SortableContext,
|
SortableContext,
|
||||||
rectSortingStrategy,
|
rectSortingStrategy,
|
||||||
@ -48,6 +57,7 @@ export function SortableItem(props) {
|
|||||||
transition,
|
transition,
|
||||||
} = useSortable({
|
} = useSortable({
|
||||||
id: props.id,
|
id: props.id,
|
||||||
|
disabled: props.disabled,
|
||||||
data: {
|
data: {
|
||||||
type: props.type,
|
type: props.type,
|
||||||
nodeRef,
|
nodeRef,
|
||||||
@ -70,6 +80,7 @@ export function SortableItem(props) {
|
|||||||
{...attributes}
|
{...attributes}
|
||||||
{...listeners}
|
{...listeners}
|
||||||
>
|
>
|
||||||
|
{/* <div {...listeners}>drag</div> */}
|
||||||
{props.children}
|
{props.children}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
@ -110,6 +121,22 @@ export const useKanban = () => {
|
|||||||
return useContext(KanbanContext);
|
return useContext(KanbanContext);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class MyMouseSensor extends MouseSensor {
|
||||||
|
static activators = [
|
||||||
|
{
|
||||||
|
eventName: 'onMouseDown' as const,
|
||||||
|
handler: (event) => {
|
||||||
|
if (event.target.tagName === 'DIV') {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
console.log('event.target.tagName', event.target.tagName);
|
||||||
|
event.target;
|
||||||
|
return false;
|
||||||
|
},
|
||||||
|
},
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
const InternalKanban = observer((props: any) => {
|
const InternalKanban = observer((props: any) => {
|
||||||
const field = useField<Formily.Core.Models.ArrayField>();
|
const field = useField<Formily.Core.Models.ArrayField>();
|
||||||
const groupName = field.componentProps.groupName;
|
const groupName = field.componentProps.groupName;
|
||||||
@ -163,7 +190,8 @@ const InternalKanban = observer((props: any) => {
|
|||||||
const [dragOverlayContent, setDragOverlayContent] = useState('');
|
const [dragOverlayContent, setDragOverlayContent] = useState('');
|
||||||
const [style, setStyle] = useState({});
|
const [style, setStyle] = useState({});
|
||||||
const containerRef = useRef<HTMLDivElement>();
|
const containerRef = useRef<HTMLDivElement>();
|
||||||
console.log({ style })
|
console.log({ style });
|
||||||
|
const sensors = useSensors(useSensor(MyMouseSensor));
|
||||||
return (
|
return (
|
||||||
<KanbanContext.Provider value={{ field, resource, service, props }}>
|
<KanbanContext.Provider value={{ field, resource, service, props }}>
|
||||||
<div>
|
<div>
|
||||||
@ -173,14 +201,18 @@ const InternalKanban = observer((props: any) => {
|
|||||||
<div className={'kanban'}>
|
<div className={'kanban'}>
|
||||||
<div ref={containerRef} className={'kanban-container'}>
|
<div ref={containerRef} className={'kanban-container'}>
|
||||||
<DndContext
|
<DndContext
|
||||||
|
sensors={sensors}
|
||||||
onDragStart={(event) => {
|
onDragStart={(event) => {
|
||||||
const el = event?.active?.data?.current?.nodeRef
|
const el = event?.active?.data?.current?.nodeRef
|
||||||
?.current as HTMLElement;
|
?.current as HTMLElement;
|
||||||
console.log(event, el);
|
console.log(event, el);
|
||||||
setDragOverlayContent(el?.outerHTML);
|
setDragOverlayContent(el?.outerHTML);
|
||||||
setStyle({ width: el.clientWidth, height: containerRef.current?.clientHeight });
|
setStyle({
|
||||||
|
width: el.clientWidth,
|
||||||
|
height: containerRef.current?.clientHeight,
|
||||||
|
});
|
||||||
}}
|
}}
|
||||||
// collisionDetection={closestCorners}
|
collisionDetection={closestCenter}
|
||||||
onDragEnd={({ active, over }) => {
|
onDragEnd={({ active, over }) => {
|
||||||
const source = values.find((item) => item.id === active?.id);
|
const source = values.find((item) => item.id === active?.id);
|
||||||
const target = values.find((item) => item.id === over?.id);
|
const target = values.find((item) => item.id === over?.id);
|
||||||
@ -225,7 +257,8 @@ const InternalKanban = observer((props: any) => {
|
|||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<DragOverlay
|
<DragOverlay
|
||||||
style={{ pointerEvents: 'none' }}
|
style={{ ...style }}
|
||||||
|
// style={{ pointerEvents: 'none' }}
|
||||||
>
|
>
|
||||||
<div
|
<div
|
||||||
className={'nb-kanban-drag-overlay'}
|
className={'nb-kanban-drag-overlay'}
|
||||||
@ -250,6 +283,7 @@ const InternalKanban = observer((props: any) => {
|
|||||||
id={column.value}
|
id={column.value}
|
||||||
key={column.value}
|
key={column.value}
|
||||||
type={'column'}
|
type={'column'}
|
||||||
|
disabled
|
||||||
className={'column'}
|
className={'column'}
|
||||||
>
|
>
|
||||||
<KanbanColumnContext.Provider value={column}>
|
<KanbanColumnContext.Provider value={column}>
|
||||||
@ -269,6 +303,7 @@ const InternalKanban = observer((props: any) => {
|
|||||||
key={item.id}
|
key={item.id}
|
||||||
className={'item'}
|
className={'item'}
|
||||||
id={item.id}
|
id={item.id}
|
||||||
|
// disabled
|
||||||
type={'item'}
|
type={'item'}
|
||||||
>
|
>
|
||||||
<KanbanCardContext.Provider
|
<KanbanCardContext.Provider
|
||||||
@ -291,33 +326,9 @@ const InternalKanban = observer((props: any) => {
|
|||||||
name={addCardSchema?.name}
|
name={addCardSchema?.name}
|
||||||
schema={addCardSchema}
|
schema={addCardSchema}
|
||||||
/>
|
/>
|
||||||
{/* <Button
|
|
||||||
type={'text'}
|
|
||||||
icon={<PlusOutlined />}
|
|
||||||
onClick={() => {
|
|
||||||
field.push({
|
|
||||||
id: uid(),
|
|
||||||
title: uid(),
|
|
||||||
[groupName]: column.value,
|
|
||||||
});
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
添加卡片
|
|
||||||
</Button> */}
|
|
||||||
</KanbanColumnContext.Provider>
|
</KanbanColumnContext.Provider>
|
||||||
</SortableItem>
|
</SortableItem>
|
||||||
))}
|
))}
|
||||||
<div
|
|
||||||
id={'addColumn'}
|
|
||||||
key={'addColumn'}
|
|
||||||
// type={'column'}
|
|
||||||
className={'column add-column'}
|
|
||||||
>
|
|
||||||
{/* <span className={'add-column-plus'}/> */}
|
|
||||||
<span>
|
|
||||||
<PlusOutlined /> 添加列表
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
</SortableContext>
|
</SortableContext>
|
||||||
</DndContext>
|
</DndContext>
|
||||||
</div>
|
</div>
|
||||||
|
Loading…
Reference in New Issue
Block a user