-
-
Notifications
You must be signed in to change notification settings - Fork 40
/
Copy pathindex.js
181 lines (173 loc) · 4.49 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
import React, { PureComponent } from 'react';
import { connect } from 'dva';
import { Avatar, message, Button, Menu, Dropdown, Icon, Modal } from 'antd';
import { Curd } from 'antd-curd';
import { modelName } from '../models/curdPage.ts';
import setFormItemsConfig from './map';
import styles from './index.less';
@connect(({ [modelName]: model, loading }) => ({
data: model.data,
detail: model.detail,
fetchLoading: loading.effects[`${modelName}/fetch`],
detailLoading: loading.effects[`${modelName}/detail`],
createLoading: loading.effects[`${modelName}/create`],
updateLoading: loading.effects[`${modelName}/update`],
deleteLoading: loading.effects[`${modelName}/delete`],
}))
class TableList extends PureComponent {
state = {
customModelVisible: false,
selectedRows: [],
};
queryArgsConfig = [
{
type: 'string',
field: 'username',
formItemProps: {
label: '姓名',
},
},
{
type: 'string',
field: 'nickname',
formItemProps: {
label: '昵称',
},
},
{
type: 'string',
field: 'habit',
formItemProps: {
label: '爱好',
},
},
];
columns = [
{
title: '公式照',
dataIndex: 'avatar',
render: value => (
<div className={styles.avatarWrapper}>
<Avatar src={value} size="large" />
</div>
),
},
{
title: '姓名',
dataIndex: 'name',
render: (value, record) => (
<a href={record.profile} target="_blank" rel="noreferrer noopener">
{value}
</a>
),
},
{
title: '昵称',
dataIndex: 'nickname',
},
{
title: '生日',
dataIndex: 'birthday',
},
{
title: '特长',
dataIndex: 'speciality',
},
{
title: '爱好',
dataIndex: 'habit',
},
];
render() {
const { customModelVisible, selectedRows } = this.state;
const actionsConfig = {
extraActions: [
{
key: 13,
title: '外务',
handleClick: record => message.info(`调用 ${record.name} 的外务事件`),
},
{
key: 14,
title: '兼职',
handleClick: record => message.info(`调用 ${record.name} 的兼职事件`),
},
{
key: 15,
title: '弹出子组件',
handleClick: () => this.setState({ customModelVisible: true }),
},
],
confirmKeys: [
[4, record => `确定查看 ${record.name} 的详情吗?`],
[12, () => `确定删除吗?`],
[13, record => `确定让 ${record.name} 出外务吗?`],
14,
],
};
return (
<Curd modelName={modelName} {...this.props}>
<Curd.QueryPanel queryArgsConfig={this.queryArgsConfig} />
<Curd.CurdTable
columns={this.columns}
actionsConfig={actionsConfig}
setFormItemsConfig={setFormItemsConfig}
popupType="drawer"
popupProps={{
drawerConfig: {
width: 560,
},
}}
operators={[<TableActions key="more" selectedRows={selectedRows} />]}
selectedRows={selectedRows}
onSelectRow={rows => this.setState({ selectedRows: rows })}
{...this.props}
/>
<CustomModal
title="弹出子组件"
visible={customModelVisible}
onCancel={() => this.setState({ customModelVisible: false })}
okButtonProps={{ style: { display: 'none' } }}
/>
</Curd>
);
}
}
export default TableList;
function TableActions(props) {
const { selectedRows } = props;
const menu = (
<Menu>
<Menu.Item key="remove">删除</Menu.Item>
<Menu.Item key="approval">批量审批</Menu.Item>
</Menu>
);
return (
selectedRows.length > 0 && (
<span>
<Button>批量操作</Button>
<Dropdown overlay={menu}>
<Button>
更多操作 <Icon type="down" />
</Button>
</Dropdown>
</span>
)
);
}
function CustomModal(props) {
const { __curd__, ...rest } = props;
if (!__curd__) return null;
return (
<Modal {...rest}>
<Button
onClick={() => {
__curd__.handleSearch();
rest.onCancel();
}}
>
重新搜索
</Button>
</Modal>
);
}