Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
CivManage
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ReactWeb5
CivManage
Commits
050641e6
Commit
050641e6
authored
Nov 23, 2021
by
邓超
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: 修改表格拖拽组件不能添加点击事件
parent
8396b5af
Pipeline
#38511
skipped with stages
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
17 additions
and
7 deletions
+17
-7
DragTable.jsx
src/components/DragTable/DragTable.jsx
+7
-4
DraggableBodyRow.jsx
src/components/DragTable/DraggableBodyRow.jsx
+10
-3
No files found.
src/components/DragTable/DragTable.jsx
View file @
050641e6
...
...
@@ -7,17 +7,18 @@ import { DndProvider } from 'react-dnd';
import
DraggableBodyRow
from
'./DraggableBodyRow'
;
const
DragTable
=
props
=>
{
const
{
columns
,
dataSource
,
dragCallBack
}
=
props
;
const
{
columns
,
dataSource
,
dragCallBack
,
ItemTypes
}
=
props
;
const
[
data
,
setData
]
=
useState
(
null
);
// 分组后的数组
const
components
=
{
body
:
{
row
:
DraggableBodyRow
,
},
};
useEffect
(()
=>
{
setData
(
dataSource
);
},
[]);
if
(
dataSource
.
length
>
0
)
{
setData
(
dataSource
);
}
},
[
dataSource
]);
// 每次拖拽后返回
useEffect
(()
=>
{
dragCallBack
(
data
);
...
...
@@ -56,7 +57,9 @@ const DragTable = props => {
components=
{
components
}
onRow=
{
(
record
,
index
)
=>
({
index
,
ItemTypes
,
moveRow
,
onClick
:
()
=>
props
.
onClick
(
record
),
})
}
{
...
props
}
/>
...
...
src/components/DragTable/DraggableBodyRow.jsx
View file @
050641e6
import
React
,
{
useRef
}
from
'react'
;
import
React
,
{
useRef
,
useState
,
useEffect
}
from
'react'
;
import
{
useDrag
,
useDrop
}
from
'react-dnd'
;
import
'./index.less'
;
...
...
@@ -9,11 +9,18 @@ const DraggableBodyRow = ({
className
,
style
,
tableType
,
ItemTypes
,
...
restProps
})
=>
{
const
[
type
,
setType
]
=
useState
(
''
);
const
ref
=
useRef
();
useEffect
(()
=>
{
if
(
ItemTypes
)
{
setType
(
ItemTypes
);
}
},
[
ItemTypes
]);
const
[{
isOver
,
dropClassName
},
drop
]
=
useDrop
({
accept
:
'DraggableBodyRow'
,
accept
:
type
,
collect
:
monitor
=>
{
const
{
index
:
dragIndex
}
=
monitor
.
getItem
()
||
{};
if
(
dragIndex
===
index
)
{
...
...
@@ -31,7 +38,7 @@ const DraggableBodyRow = ({
},
});
const
[,
drag
]
=
useDrag
({
type
:
'DraggableBodyRow'
,
type
,
item
:
{
index
},
collect
:
monitor
=>
({
isDragging
:
monitor
.
isDragging
(),
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment