Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
szse
Overview
Overview
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
zhaochengxiang
szse
Commits
2be49a33
Commit
2be49a33
authored
Mar 25, 2021
by
zhaochengxiang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
新增行
parent
de508d3b
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
129 additions
and
57 deletions
+129
-57
ImportAction.jsx
src/view/Manage/Model/Component/ImportAction.jsx
+129
-57
No files found.
src/view/Manage/Model/Component/ImportAction.jsx
View file @
2be49a33
import
React
,
{
useState
,
useCallback
,
useRef
}
from
'react'
;
import
React
,
{
useState
,
useCallback
,
useRef
}
from
'react'
;
import
{
Table
,
Input
,
InputNumber
,
Popconfirm
,
Form
,
Typography
,
Radio
,
Divider
,
Alert
}
from
'antd'
;
import
{
Table
,
Input
,
InputNumber
,
Form
,
Typography
,
Radio
,
Divider
,
Alert
,
Button
}
from
'antd'
;
import
{
DndProvider
,
useDrag
,
useDrop
}
from
'react-dnd'
;
import
{
DndProvider
,
useDrag
,
useDrop
}
from
'react-dnd'
;
import
{
HTML5Backend
}
from
'react-dnd-html5-backend'
;
import
{
HTML5Backend
}
from
'react-dnd-html5-backend'
;
import
update
from
'immutability-helper'
;
import
update
from
'immutability-helper'
;
...
@@ -55,11 +55,13 @@ const EditableCell = ({
...
@@ -55,11 +55,13 @@ const EditableCell = ({
};
};
const
DragableBodyRow
=
({
index
,
moveRow
,
className
,
style
,
...
restProps
})
=>
{
const
DragableBodyRow
=
({
index
,
moveRow
,
className
,
style
,
...
restProps
})
=>
{
const
ref
=
useRef
();
const
ref
=
useRef
();
const
[{
isOver
,
dropClassName
},
drop
]
=
useDrop
(
const
[{
isOver
,
dropClassName
},
drop
]
=
useDrop
(
()
=>
({
()
=>
({
accept
:
type
,
accept
:
type
,
collect
:
monitor
=>
{
collect
:
monitor
=>
{
const
{
index
:
dragIndex
}
=
monitor
.
getItem
()
||
{};
const
{
index
:
dragIndex
}
=
monitor
.
getItem
()
||
{};
if
(
dragIndex
===
index
)
{
if
(
dragIndex
===
index
)
{
return
{};
return
{};
...
@@ -70,7 +72,11 @@ const DragableBodyRow = ({ index, moveRow, className, style, ...restProps }) =>
...
@@ -70,7 +72,11 @@ const DragableBodyRow = ({ index, moveRow, className, style, ...restProps }) =>
};
};
},
},
drop
:
item
=>
{
drop
:
item
=>
{
if
(
className
===
'ant-table-expanded-row'
)
return
;
if
(
moveRow
)
{
moveRow
(
item
.
index
,
index
);
moveRow
(
item
.
index
,
index
);
}
},
},
}),
}),
[
index
],
[
index
],
...
@@ -102,11 +108,23 @@ const ImportAction = () => {
...
@@ -102,11 +108,23 @@ const ImportAction = () => {
const
[
data
,
setData
]
=
useState
(
originData
);
const
[
data
,
setData
]
=
useState
(
originData
);
const
[
editingKey
,
setEditingKey
]
=
useState
(
''
);
const
[
editingKey
,
setEditingKey
]
=
useState
(
''
);
const
[
recommends
,
setRecommends
]
=
useState
([]);
const
[
recommends
,
setRecommends
]
=
useState
([]);
const
[
suggests
,
setSuggests
]
=
useState
([]);
const
dataRef
=
useRef
();
const
dataRef
=
useRef
();
dataRef
.
current
=
data
;
dataRef
.
current
=
data
;
const
isEditing
=
(
record
)
=>
record
.
key
===
editingKey
;
const
isEditing
=
(
record
)
=>
record
.
key
===
editingKey
;
const
onAddClick
=
()
=>
{
const
newData
=
[{},
...
data
];
(
newData
||
[]).
forEach
((
item
,
index
)
=>
{
item
.
key
=
index
.
toString
();
})
setData
(
newData
);
edit
(
newData
[
0
]);
}
const
edit
=
(
record
)
=>
{
const
edit
=
(
record
)
=>
{
form
.
setFieldsValue
({
form
.
setFieldsValue
({
name
:
''
,
name
:
''
,
...
@@ -119,36 +137,93 @@ const ImportAction = () => {
...
@@ -119,36 +137,93 @@ const ImportAction = () => {
setEditingKey
(
record
.
key
);
setEditingKey
(
record
.
key
);
};
};
const
remove
=
(
record
)
=>
{
const
newData
=
[...
data
];
const
index
=
newData
.
findIndex
((
item
)
=>
record
.
key
===
item
.
key
);
newData
.
splice
(
index
,
1
);
setData
(
newData
);
}
const
cancel
=
()
=>
{
const
cancel
=
()
=>
{
setEditingKey
(
''
);
setEditingKey
(
''
);
setRecommends
([]);
};
};
const
save
=
async
(
key
)
=>
{
const
save
=
(
)
=>
{
try
{
try
{
setRecommends
([]);
const
_suggests
=
[
{
name
:
'建议1'
},
{
name
:
'建议2'
}
];
setSuggests
(
_suggests
)
if
(
_suggests
.
length
===
0
)
{
constraintSave
();
}
}
catch
(
errInfo
)
{
console
.
log
(
'Validate Failed:'
,
errInfo
);
}
};
const
constraintSave
=
async
()
=>
{
const
row
=
await
form
.
validateFields
();
const
row
=
await
form
.
validateFields
();
const
newData
=
[...
data
];
const
newData
=
[...
data
];
const
index
=
newData
.
findIndex
((
item
)
=>
k
ey
===
item
.
key
);
const
index
=
newData
.
findIndex
((
item
)
=>
editingK
ey
===
item
.
key
);
if
(
index
>
-
1
)
{
if
(
index
>
-
1
)
{
const
item
=
newData
[
index
];
const
item
=
newData
[
index
];
newData
.
splice
(
index
,
1
,
{
...
item
,
...
row
});
newData
.
splice
(
index
,
1
,
{
...
item
,
...
row
});
setData
(
newData
);
setData
(
newData
);
setEditingKey
(
''
);
dataRef
.
current
=
newData
;
dataRef
.
current
=
newData
;
}
else
{
}
else
{
newData
.
push
(
row
);
newData
.
push
(
row
);
setData
(
newData
);
setData
(
newData
);
setEditingKey
(
''
);
dataRef
.
current
=
newData
;
dataRef
.
current
=
newData
;
}
}
}
catch
(
errInfo
)
{
setEditingKey
(
''
);
console
.
log
(
'Validate Failed:'
,
errInfo
);
setSuggests
([]);
}
const
onValuesChange
=
(
changedValues
,
allValues
)
=>
{
// console.log('changed values', changedValues);
// console.log('all values', allValues);
setRecommends
([
{
name
:
'流水交易'
,
cnName
:
'trade_id'
,
type
:
'varchar'
,
length
:
32
,
desc
:
'流水交易'
},
{
key
:
0
,
name
:
`流水交易交易`
,
cnName
:
'trade_id'
,
type
:
'varchar'
,
length
:
32
,
desc
:
'流水单号'
}
}
])
};
const
onRecommendChange
=
(
e
)
=>
{
form
.
setFieldsValue
({
...
recommends
[
e
.
target
.
value
]
});
setRecommends
([]);
};
};
const
columns
=
[
const
columns
=
[
...
@@ -183,24 +258,23 @@ const ImportAction = () => {
...
@@ -183,24 +258,23 @@ const ImportAction = () => {
render
:
(
_
,
record
)
=>
{
render
:
(
_
,
record
)
=>
{
const
editable
=
isEditing
(
record
);
const
editable
=
isEditing
(
record
);
return
editable
?
(
return
editable
?
(
<
span
>
<>
<
a
<
Typography
.
Link
className=
'mr-3'
disabled=
{
editingKey
===
''
}
onClick=
{
()
=>
save
()
}
>
href=
"javascript:;"
onClick=
{
()
=>
save
(
record
.
key
)
}
style=
{
{
marginRight
:
8
,
}
}
>
保存
保存
</
a
>
</
Typography
.
Link
>
<
Popconfirm
title=
"Sure to cancel?"
onConfirm=
{
cancel
}
>
<
Typography
.
Link
disabled=
{
editingKey
===
''
}
onClick=
{
()
=>
{
cancel
()}
}
>
<
a
>
取消
</
a
>
取消
</
Popconfirm
>
</
Typography
.
Link
>
</
span
>
</
>
)
:
(
)
:
(
<
Typography
.
Link
disabled=
{
editingKey
!==
''
}
onClick=
{
()
=>
edit
(
record
)
}
>
<>
<
Typography
.
Link
className=
'mr-3'
disabled=
{
editingKey
!==
''
}
onClick=
{
()
=>
edit
(
record
)
}
>
编辑
编辑
</
Typography
.
Link
>
</
Typography
.
Link
>
<
Typography
.
Link
disabled=
{
editingKey
!==
''
}
onClick=
{
()
=>
remove
(
record
)
}
>
删除
</
Typography
.
Link
>
</>
);
);
},
},
},
},
...
@@ -215,7 +289,7 @@ const ImportAction = () => {
...
@@ -215,7 +289,7 @@ const ImportAction = () => {
...
col
,
...
col
,
onCell
:
(
record
)
=>
({
onCell
:
(
record
)
=>
({
record
,
record
,
inputType
:
col
.
dataIndex
===
'age'
?
'number'
:
'text'
,
inputType
:
'text'
,
dataIndex
:
col
.
dataIndex
,
dataIndex
:
col
.
dataIndex
,
title
:
col
.
title
,
title
:
col
.
title
,
editing
:
isEditing
(
record
),
editing
:
isEditing
(
record
),
...
@@ -240,38 +314,6 @@ const ImportAction = () => {
...
@@ -240,38 +314,6 @@ const ImportAction = () => {
[
data
],
[
data
],
);
);
const
onValuesChange
=
(
changedValues
,
allValues
)
=>
{
// console.log('changed values', changedValues);
// console.log('all values', allValues);
setRecommends
([
{
name
:
'流水交易'
,
cnName
:
'trade_id'
,
type
:
'varchar'
,
length
:
32
,
desc
:
'流水交易'
},
{
key
:
0
,
name
:
`流水交易交易`
,
cnName
:
'trade_id'
,
type
:
'varchar'
,
length
:
32
,
desc
:
'流水单号'
}
])
};
const
onRecommendChange
=
(
e
)
=>
{
form
.
setFieldsValue
({
...
recommends
[
e
.
target
.
value
]
});
setRecommends
([]);
};
return
(
return
(
<>
<>
<
Alert
<
Alert
...
@@ -280,6 +322,9 @@ const ImportAction = () => {
...
@@ -280,6 +322,9 @@ const ImportAction = () => {
closable
closable
className=
'mb-3'
className=
'mb-3'
/>
/>
<
div
className=
'd-flex mb-3'
>
<
Button
type=
"primary"
onClick=
{
onAddClick
}
style=
{
{
marginLeft
:
'auto'
}
}
disabled=
{
editingKey
!==
''
}
>
新增行
</
Button
>
</
div
>
<
DndProvider
backend=
{
HTML5Backend
}
>
<
DndProvider
backend=
{
HTML5Backend
}
>
<
Form
form=
{
form
}
component=
{
false
}
onValuesChange=
{
onValuesChange
}
>
<
Form
form=
{
form
}
component=
{
false
}
onValuesChange=
{
onValuesChange
}
>
<
Table
<
Table
...
@@ -302,6 +347,28 @@ const ImportAction = () => {
...
@@ -302,6 +347,28 @@ const ImportAction = () => {
expandable=
{
{
expandable=
{
{
expandedRowRender
:
record
=>
(
expandedRowRender
:
record
=>
(
<>
<>
{
editingKey
!==
''
&&
<>
{
suggests
&&
suggests
.
length
>
0
&&
(
<>
<
Divider
orientation=
"left"
>
建议
</
Divider
>
<
div
className=
'mb-3 ml-7'
>
{
suggests
&&
suggests
.
map
((
suggest
,
index
)
=>
{
return
(
<
div
className=
'mt-3'
>
{
suggest
.
name
||
''
}
</
div
>
)
})
}
</
div
>
<
Button
className=
'mb-3 ml-7'
type=
'primary'
onClick=
{
constraintSave
}
>
强制保存
</
Button
>
</>
)
}
{
recommends
&&
recommends
.
length
>
0
&&
(
<>
<
Divider
orientation=
"left"
>
智能推荐
</
Divider
>
<
Divider
orientation=
"left"
>
智能推荐
</
Divider
>
<
Radio
.
Group
onChange=
{
onRecommendChange
}
className=
'mb-3 ml-7'
>
<
Radio
.
Group
onChange=
{
onRecommendChange
}
className=
'mb-3 ml-7'
>
{
{
...
@@ -315,11 +382,16 @@ const ImportAction = () => {
...
@@ -315,11 +382,16 @@ const ImportAction = () => {
}
}
</
Radio
.
Group
>
</
Radio
.
Group
>
</>
</>
)
}
</>
}
</>
),
),
expandIcon
:
({
expanded
,
onExpand
,
record
})
=>
{
expandIcon
:
({
expanded
,
onExpand
,
record
})
=>
{
return
<></>;
return
<></>;
},
},
rowExpandable
:
record
=>
isEditing
(
record
)
&&
(
recommends
||
[]).
length
>
0
,
rowExpandable
:
record
=>
(
editingKey
!==
''
&&
((
recommends
||
[]).
length
>
0
||
(
suggests
||
[]).
length
>
0
))
,
expandedRowKeys
:
[
editingKey
]
expandedRowKeys
:
[
editingKey
]
}
}
}
}
/>
/>
...
...
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