wip: 基本解决了新建拖动排序的问题
This commit is contained in:
parent
b2bbfab22c
commit
d9d939ff37
@ -1,80 +0,0 @@
|
|||||||
import { makeStyles } from "@mui/styles";
|
|
||||||
import { Tag } from "antd";
|
|
||||||
|
|
||||||
const useStyles = makeStyles({
|
|
||||||
container: {
|
|
||||||
height: '200px',
|
|
||||||
width: '600px',
|
|
||||||
border: '1px solid black',
|
|
||||||
margin: "100px",
|
|
||||||
display: 'flex',
|
|
||||||
flexDirection: 'column',
|
|
||||||
flexWrap: 'wrap',
|
|
||||||
overflowY: 'scroll',
|
|
||||||
},
|
|
||||||
names: {
|
|
||||||
maxWidth: '140px',
|
|
||||||
minWidth: '140px',
|
|
||||||
},
|
|
||||||
phones: {
|
|
||||||
maxWidth: '140px',
|
|
||||||
minWidth: '140px',
|
|
||||||
},
|
|
||||||
address: {
|
|
||||||
maxWidth: '140px',
|
|
||||||
minWidth: '140px',
|
|
||||||
}
|
|
||||||
});
|
|
||||||
export const TestPage = () => {
|
|
||||||
const style = useStyles();
|
|
||||||
return (
|
|
||||||
<div className={style.container}>
|
|
||||||
<div className={style.names}>
|
|
||||||
<Tag>name1</Tag>
|
|
||||||
<Tag>name2</Tag>
|
|
||||||
<Tag>name3</Tag>
|
|
||||||
<Tag>name4</Tag>
|
|
||||||
<Tag>name5</Tag>
|
|
||||||
<Tag>name6</Tag>
|
|
||||||
<Tag>name7</Tag>
|
|
||||||
<Tag>name8</Tag>
|
|
||||||
<Tag>name9</Tag>
|
|
||||||
<Tag>name10</Tag>
|
|
||||||
<Tag>name11</Tag>
|
|
||||||
<Tag>name12</Tag>
|
|
||||||
<Tag>name13</Tag>
|
|
||||||
<Tag>name14</Tag>
|
|
||||||
<Tag>name15</Tag>
|
|
||||||
</div>
|
|
||||||
<div className={style.phones}>
|
|
||||||
<Tag color="success">phone1</Tag>
|
|
||||||
<Tag color="success">phone2</Tag>
|
|
||||||
<Tag color="success">phone3</Tag>
|
|
||||||
<Tag color="success">phone4</Tag>
|
|
||||||
<Tag color="success">phone5</Tag>
|
|
||||||
<Tag color="success">phone6</Tag>
|
|
||||||
<Tag color="success">phone7</Tag>
|
|
||||||
<Tag color="success">phone8</Tag>
|
|
||||||
<Tag color="success">phone9</Tag>
|
|
||||||
</div>
|
|
||||||
<div className={style.address}>
|
|
||||||
<Tag color="error">address1</Tag>
|
|
||||||
<Tag color="error">address2</Tag>
|
|
||||||
<Tag color="error">address3</Tag>
|
|
||||||
<Tag color="error">address4</Tag>
|
|
||||||
<Tag color="error">address5</Tag>
|
|
||||||
<Tag color="error">address6</Tag>
|
|
||||||
<Tag color="error">address7</Tag>
|
|
||||||
<Tag color="error">address8</Tag>
|
|
||||||
</div>
|
|
||||||
<div>
|
|
||||||
<Tag color="warning">birthday</Tag>
|
|
||||||
<Tag color="warning">birthday</Tag>
|
|
||||||
<Tag color="warning">birthday</Tag>
|
|
||||||
<Tag color="warning">birthday</Tag>
|
|
||||||
<Tag color="warning">birthday</Tag>
|
|
||||||
<Tag color="warning">birthday</Tag>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
@ -1,6 +1,6 @@
|
|||||||
import { makeStyles } from "@mui/styles"
|
import { makeStyles } from "@mui/styles"
|
||||||
import { Modal, Collapse } from "antd"
|
import { Modal, Collapse } from "antd"
|
||||||
import { DndContext } from '@dnd-kit/core'
|
import { DndContext, } from '@dnd-kit/core'
|
||||||
import { SortableContext, useSortable, verticalListSortingStrategy } from '@dnd-kit/sortable';
|
import { SortableContext, useSortable, verticalListSortingStrategy } from '@dnd-kit/sortable';
|
||||||
import { CSS } from '@dnd-kit/utilities'
|
import { CSS } from '@dnd-kit/utilities'
|
||||||
import { arrayMove } from '@dnd-kit/sortable'
|
import { arrayMove } from '@dnd-kit/sortable'
|
||||||
@ -11,7 +11,8 @@ const useStyle = makeStyles({
|
|||||||
footer: {
|
footer: {
|
||||||
display: 'flex',
|
display: 'flex',
|
||||||
flexDirection: 'row',
|
flexDirection: 'row',
|
||||||
}
|
},
|
||||||
|
dnd: {}
|
||||||
})
|
})
|
||||||
|
|
||||||
export interface TaskCreateProps {
|
export interface TaskCreateProps {
|
||||||
@ -34,7 +35,7 @@ export const TaskCreate = (props: TaskCreateProps) => {
|
|||||||
const style = useStyle();
|
const style = useStyle();
|
||||||
const [items, setItems] = useState(steps);
|
const [items, setItems] = useState(steps);
|
||||||
|
|
||||||
const onDragEnd = ({ active, over }) => {
|
const onDragEnd = ({ active, over }: { active: any, over: any }) => {
|
||||||
if (active.id !== over?.id) {
|
if (active.id !== over?.id) {
|
||||||
setItems(items => {
|
setItems(items => {
|
||||||
const oldIndex = items.findIndex(item => item.id === active.id);
|
const oldIndex = items.findIndex(item => item.id === active.id);
|
||||||
@ -57,44 +58,59 @@ export const TaskCreate = (props: TaskCreateProps) => {
|
|||||||
title="新建任务"
|
title="新建任务"
|
||||||
open={props.open}
|
open={props.open}
|
||||||
>
|
>
|
||||||
|
|
||||||
|
<SortableItem key={items[0].id} id={items[0].id} disabled>
|
||||||
|
<Collapse style={{flex:1}} items={[items[0]].map(v => { return { key: v.id, label: v.title, children: <p>hello</p> } })}>
|
||||||
|
</Collapse>
|
||||||
|
</SortableItem>
|
||||||
<DndContext onDragEnd={onDragEnd}>
|
<DndContext onDragEnd={onDragEnd}>
|
||||||
<SortableContext items={items} strategy={verticalListSortingStrategy}>
|
<SortableContext items={items} strategy={verticalListSortingStrategy}>
|
||||||
<Collapse>
|
{
|
||||||
{items.map(item => (
|
items.filter(v => v.type === "mid").map(v => {
|
||||||
<SortableItem key={item.id} id={item.id}>
|
return (
|
||||||
<Collapse.Panel key={item.id} header={item.title}>
|
<SortableItem key={v.id} id={v.id}>
|
||||||
{'步骤内容-' + item.type}
|
<Collapse items={[{ key: v.id, label: v.title, children: <p>hello</p> }]} style={{ flex: 1 }}>
|
||||||
</Collapse.Panel>
|
</Collapse>
|
||||||
</SortableItem>
|
</SortableItem>
|
||||||
))}
|
)
|
||||||
</Collapse>
|
})
|
||||||
|
}
|
||||||
</SortableContext>
|
</SortableContext>
|
||||||
</DndContext>
|
</DndContext>
|
||||||
|
<SortableItem key={items[items.length - 1].id} id={items[items.length - 1].id} disabled>
|
||||||
|
<Collapse style={{flex:1}} items={[items[items.length - 1]].map(v => { return { key: v.id, label: v.title, children: <p>hello</p> } })}>
|
||||||
|
</Collapse>
|
||||||
|
</SortableItem>
|
||||||
</Modal>
|
</Modal>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
const SortableItem = ({ id, children }: { id: number; children: JSX.Element }) => {
|
const SortableItem = ({ id, children, disabled=false }: { id: number; children: JSX.Element;disabled? : boolean}) => {
|
||||||
const { attributes, listeners, setNodeRef, transform, transition } = useSortable({ id });
|
const { attributes, listeners, setNodeRef, transform, transition } = useSortable({ id });
|
||||||
|
|
||||||
const style = {
|
const style = {
|
||||||
transform: CSS.Transform.toString(transform),
|
'transform': CSS.Transform.toString(transform),
|
||||||
transition,
|
transition,
|
||||||
cursor: 'move',
|
'cursor': disabled? 'not-allowed': 'move',
|
||||||
backgroundColor: 'white',
|
'background-color': 'white',
|
||||||
marginBottom: 8,
|
'margin-bottom': 8,
|
||||||
borderRadius: 4,
|
'border-radius': 4,
|
||||||
boxShadow: '0 2px 4px rgba(0,0,0,0.1)'
|
'box-shadow': '0 2px 4px rgba(0,0,0,0.1)',
|
||||||
|
'display': 'flex', // Add this line to make the item a flex container
|
||||||
|
'flex-direction': 'row', // Add this line to set the direction of the flex container to row
|
||||||
|
'padding': '10px',
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div ref={setNodeRef} style={style} {...attributes}>
|
<div ref={setNodeRef} style={style} {...attributes}>
|
||||||
<div {...listeners} style={{
|
<div {...listeners} style={{
|
||||||
padding: '8px 16px',
|
padding: '8px 16px',
|
||||||
borderRight: '2px solid #1890ff',
|
borderRight: disabled?'2px solid red':'2px solid green',
|
||||||
display: 'inline-block',
|
display: 'flex',
|
||||||
|
justifyContent: 'center',
|
||||||
|
alignItems: 'center',
|
||||||
marginRight: 16
|
marginRight: 16
|
||||||
}}>⋮⋮</div>
|
}}>⋮⋮</div>
|
||||||
{children}
|
{children}
|
||||||
|
@ -3,7 +3,6 @@ import { HomePage } from './pages/HomePage';
|
|||||||
import { AboutPage } from './pages/AboutPage';
|
import { AboutPage } from './pages/AboutPage';
|
||||||
import TaskPage from './pages/task/TaskPage';
|
import TaskPage from './pages/task/TaskPage';
|
||||||
import LoginPage from './pages/LoginPage';
|
import LoginPage from './pages/LoginPage';
|
||||||
import { TestPage } from './pages/TestPage';
|
|
||||||
|
|
||||||
const AppRoutes = () => {
|
const AppRoutes = () => {
|
||||||
return (
|
return (
|
||||||
@ -13,7 +12,6 @@ const AppRoutes = () => {
|
|||||||
<Route path="/about" element={<AboutPage />} />
|
<Route path="/about" element={<AboutPage />} />
|
||||||
<Route path="/tasks" element={<TaskPage />} />
|
<Route path="/tasks" element={<TaskPage />} />
|
||||||
<Route path="/login" element={<LoginPage />} />
|
<Route path="/login" element={<LoginPage />} />
|
||||||
<Route path="/test" element={<TestPage/>} />
|
|
||||||
</Routes>
|
</Routes>
|
||||||
</Router>
|
</Router>
|
||||||
);
|
);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user