Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
pro-blocks
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
duanledexianxianxian
pro-blocks
Commits
33ef0ada
Commit
33ef0ada
authored
Jan 25, 2018
by
ddcat1115
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor StandardTable
- extract columns - support multiple sums display
parent
25668347
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
112 additions
and
79 deletions
+112
-79
src/components/StandardTable/index.js
src/components/StandardTable/index.js
+46
-77
src/routes/List/TableList.js
src/routes/List/TableList.js
+66
-2
No files found.
src/components/StandardTable/index.js
View file @
33ef0ada
import
React
,
{
PureComponent
,
Fragment
}
from
'
react
'
;
import
React
,
{
PureComponent
}
from
'
react
'
;
import
moment
from
'
moment
'
;
import
{
Table
,
Alert
}
from
'
antd
'
;
import
{
Table
,
Alert
,
Badge
,
Divider
}
from
'
antd
'
;
import
styles
from
'
./index.less
'
;
import
styles
from
'
./index.less
'
;
const
statusMap
=
[
'
default
'
,
'
processing
'
,
'
success
'
,
'
error
'
];
function
initTotalList
(
columns
)
{
const
totalList
=
[];
columns
.
forEach
((
column
)
=>
{
if
(
column
.
needTotal
)
{
totalList
.
push
({
...
column
,
total
:
0
});
}
});
return
totalList
;
}
class
StandardTable
extends
PureComponent
{
class
StandardTable
extends
PureComponent
{
state
=
{
constructor
(
props
)
{
selectedRowKeys
:
[],
super
(
props
);
totalCallNo
:
0
,
const
{
columns
}
=
props
;
};
const
needTotalList
=
initTotalList
(
columns
);
this
.
state
=
{
selectedRowKeys
:
[],
needTotalList
,
};
}
componentWillReceiveProps
(
nextProps
)
{
componentWillReceiveProps
(
nextProps
)
{
// clean state
// clean state
if
(
nextProps
.
selectedRows
.
length
===
0
)
{
if
(
nextProps
.
selectedRows
.
length
===
0
)
{
const
needTotalList
=
initTotalList
(
nextProps
.
columns
);
this
.
setState
({
this
.
setState
({
selectedRowKeys
:
[],
selectedRowKeys
:
[],
totalCallNo
:
0
,
needTotalList
,
});
});
}
}
}
}
handleRowSelectChange
=
(
selectedRowKeys
,
selectedRows
)
=>
{
handleRowSelectChange
=
(
selectedRowKeys
,
selectedRows
)
=>
{
const
totalCallNo
=
selectedRows
.
reduce
((
sum
,
val
)
=>
{
let
needTotalList
=
[...
this
.
state
.
needTotalList
];
return
sum
+
parseFloat
(
val
.
callNo
,
10
);
needTotalList
=
needTotalList
.
map
((
item
)
=>
{
},
0
);
return
{
...
item
,
total
:
selectedRows
.
reduce
((
sum
,
val
)
=>
{
return
sum
+
parseFloat
(
val
[
item
.
dataIndex
],
10
);
},
0
),
};
});
if
(
this
.
props
.
onSelectRow
)
{
if
(
this
.
props
.
onSelectRow
)
{
this
.
props
.
onSelectRow
(
selectedRows
);
this
.
props
.
onSelectRow
(
selectedRows
);
}
}
this
.
setState
({
selectedRowKeys
,
totalCallNo
});
this
.
setState
({
selectedRowKeys
,
needTotalList
});
}
}
handleTableChange
=
(
pagination
,
filters
,
sorter
)
=>
{
handleTableChange
=
(
pagination
,
filters
,
sorter
)
=>
{
...
@@ -41,69 +62,8 @@ class StandardTable extends PureComponent {
...
@@ -41,69 +62,8 @@ class StandardTable extends PureComponent {
}
}
render
()
{
render
()
{
const
{
selectedRowKeys
,
totalCallNo
}
=
this
.
state
;
const
{
selectedRowKeys
,
needTotalList
}
=
this
.
state
;
const
{
data
:
{
list
,
pagination
},
loading
}
=
this
.
props
;
const
{
data
:
{
list
,
pagination
},
loading
,
columns
}
=
this
.
props
;
const
status
=
[
'
关闭
'
,
'
运行中
'
,
'
已上线
'
,
'
异常
'
];
const
columns
=
[
{
title
:
'
规则编号
'
,
dataIndex
:
'
no
'
,
},
{
title
:
'
描述
'
,
dataIndex
:
'
description
'
,
},
{
title
:
'
服务调用次数
'
,
dataIndex
:
'
callNo
'
,
sorter
:
true
,
align
:
'
right
'
,
render
:
val
=>
`
${
val
}
万`
,
},
{
title
:
'
状态
'
,
dataIndex
:
'
status
'
,
filters
:
[
{
text
:
status
[
0
],
value
:
0
,
},
{
text
:
status
[
1
],
value
:
1
,
},
{
text
:
status
[
2
],
value
:
2
,
},
{
text
:
status
[
3
],
value
:
3
,
},
],
render
(
val
)
{
return
<
Badge
status
=
{
statusMap
[
val
]}
text
=
{
status
[
val
]}
/>
;
},
},
{
title
:
'
更新时间
'
,
dataIndex
:
'
updatedAt
'
,
sorter
:
true
,
render
:
val
=>
<
span
>
{
moment
(
val
).
format
(
'
YYYY-MM-DD HH:mm:ss
'
)}
<
/span>
,
},
{
title
:
'
操作
'
,
render
:
()
=>
(
<
Fragment
>
<
a
href
=
""
>
配置
<
/a
>
<
Divider
type
=
"
vertical
"
/>
<
a
href
=
""
>
订阅警报
<
/a
>
<
/Fragment
>
),
},
];
const
paginationProps
=
{
const
paginationProps
=
{
showSizeChanger
:
true
,
showSizeChanger
:
true
,
...
@@ -126,7 +86,16 @@ class StandardTable extends PureComponent {
...
@@ -126,7 +86,16 @@ class StandardTable extends PureComponent {
message
=
{(
message
=
{(
<
div
>
<
div
>
已选择
<
a
style
=
{{
fontWeight
:
600
}}
>
{
selectedRowKeys
.
length
}
<
/a> 项  
;
已选择
<
a
style
=
{{
fontWeight
:
600
}}
>
{
selectedRowKeys
.
length
}
<
/a> 项  
;
服务调用总计
<
span
style
=
{{
fontWeight
:
600
}}
>
{
totalCallNo
}
<
/span>
万
{
needTotalList
.
map
(
item
=>
(
<
span
style
=
{{
marginLeft
:
8
}}
key
=
{
item
.
dataIndex
}
>
{
item
.
title
}
总计
&
nbsp
;
<
span
style
=
{{
fontWeight
:
600
}}
>
{
item
.
render
?
item
.
render
(
item
.
total
)
:
item
.
total
}
<
/span
>
<
/span
>
)
)
}
<
a
onClick
=
{
this
.
cleanSelectedKeys
}
style
=
{{
marginLeft
:
24
}}
>
清空
<
/a
>
<
a
onClick
=
{
this
.
cleanSelectedKeys
}
style
=
{{
marginLeft
:
24
}}
>
清空
<
/a
>
<
/div
>
<
/div
>
)}
)}
...
...
src/routes/List/TableList.js
View file @
33ef0ada
import
React
,
{
PureComponent
}
from
'
react
'
;
import
React
,
{
PureComponent
,
Fragment
}
from
'
react
'
;
import
{
connect
}
from
'
dva
'
;
import
{
connect
}
from
'
dva
'
;
import
{
Row
,
Col
,
Card
,
Form
,
Input
,
Select
,
Icon
,
Button
,
Dropdown
,
Menu
,
InputNumber
,
DatePicker
,
Modal
,
message
}
from
'
antd
'
;
import
moment
from
'
moment
'
;
import
{
Row
,
Col
,
Card
,
Form
,
Input
,
Select
,
Icon
,
Button
,
Dropdown
,
Menu
,
InputNumber
,
DatePicker
,
Modal
,
message
,
Badge
,
Divider
}
from
'
antd
'
;
import
StandardTable
from
'
../../components/StandardTable
'
;
import
StandardTable
from
'
../../components/StandardTable
'
;
import
PageHeaderLayout
from
'
../../layouts/PageHeaderLayout
'
;
import
PageHeaderLayout
from
'
../../layouts/PageHeaderLayout
'
;
...
@@ -9,6 +10,68 @@ import styles from './TableList.less';
...
@@ -9,6 +10,68 @@ import styles from './TableList.less';
const
FormItem
=
Form
.
Item
;
const
FormItem
=
Form
.
Item
;
const
{
Option
}
=
Select
;
const
{
Option
}
=
Select
;
const
getValue
=
obj
=>
Object
.
keys
(
obj
).
map
(
key
=>
obj
[
key
]).
join
(
'
,
'
);
const
getValue
=
obj
=>
Object
.
keys
(
obj
).
map
(
key
=>
obj
[
key
]).
join
(
'
,
'
);
const
statusMap
=
[
'
default
'
,
'
processing
'
,
'
success
'
,
'
error
'
];
const
status
=
[
'
关闭
'
,
'
运行中
'
,
'
已上线
'
,
'
异常
'
];
const
columns
=
[
{
title
:
'
规则编号
'
,
dataIndex
:
'
no
'
,
},
{
title
:
'
描述
'
,
dataIndex
:
'
description
'
,
},
{
title
:
'
服务调用次数
'
,
dataIndex
:
'
callNo
'
,
sorter
:
true
,
align
:
'
right
'
,
render
:
val
=>
`
${
val
}
万`
,
// mark to display a total number
needTotal
:
true
,
},
{
title
:
'
状态
'
,
dataIndex
:
'
status
'
,
filters
:
[
{
text
:
status
[
0
],
value
:
0
,
},
{
text
:
status
[
1
],
value
:
1
,
},
{
text
:
status
[
2
],
value
:
2
,
},
{
text
:
status
[
3
],
value
:
3
,
},
],
render
(
val
)
{
return
<
Badge
status
=
{
statusMap
[
val
]}
text
=
{
status
[
val
]}
/>
;
},
},
{
title
:
'
更新时间
'
,
dataIndex
:
'
updatedAt
'
,
sorter
:
true
,
render
:
val
=>
<
span
>
{
moment
(
val
).
format
(
'
YYYY-MM-DD HH:mm:ss
'
)}
<
/span>
,
},
{
title
:
'
操作
'
,
render
:
()
=>
(
<
Fragment
>
<
a
href
=
""
>
配置
<
/a
>
<
Divider
type
=
"
vertical
"
/>
<
a
href
=
""
>
订阅警报
<
/a
>
<
/Fragment
>
),
},
];
const
CreateForm
=
Form
.
create
()((
props
)
=>
{
const
CreateForm
=
Form
.
create
()((
props
)
=>
{
const
{
modalVisible
,
form
,
handleAdd
,
handleModalVisible
}
=
props
;
const
{
modalVisible
,
form
,
handleAdd
,
handleModalVisible
}
=
props
;
...
@@ -335,6 +398,7 @@ export default class TableList extends PureComponent {
...
@@ -335,6 +398,7 @@ export default class TableList extends PureComponent {
selectedRows
=
{
selectedRows
}
selectedRows
=
{
selectedRows
}
loading
=
{
loading
}
loading
=
{
loading
}
data
=
{
data
}
data
=
{
data
}
columns
=
{
columns
}
onSelectRow
=
{
this
.
handleSelectRows
}
onSelectRow
=
{
this
.
handleSelectRows
}
onChange
=
{
this
.
handleStandardTableChange
}
onChange
=
{
this
.
handleStandardTableChange
}
/
>
/
>
...
...
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