index.js
5.1 KB
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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
/**
* Author: llw
* Date: 2020.7.16
* Description: [应用列表]
*/
import React, { useEffect } from 'react';
import { connect, Link } from 'umi';
import { Card, Form, DatePicker, Input, Button, Table, Divider, Modal } from 'antd';
import { ExclamationCircleOutlined } from '@ant-design/icons';
import { paginations } from '@/constants';
import moment from 'moment';
const { RangePicker } = DatePicker;
const FormItem = Form.Item;
/* SearchForm */
const SearchForm = props => {
const [form] = Form.useForm();
const {
dataSearch,
handleReset,
handleFinish,
dataSearch: { createTimeBegin, createTimeEnd }
} = props;
useEffect(() => {
form.setFieldsValue({
...dataSearch,
createTime: [createTimeBegin ? moment(createTimeBegin) : undefined, createTimeEnd ? moment(createTimeEnd) : undefined]
});
}, [dataSearch]);
/* 点击搜索 */
const onFinish = (values) => {
handleFinish(values);
};
/* 点击重置 */
const onReset = () => {
handleReset();
};
return (
<Form
name="Form_Application"
layout="inline"
form={form}
onFinish={onFinish}
>
<FormItem label="应用名称" name="name">
<Input placeholder="请输入应用名称" style={{width: "220px"}} />
</FormItem>
<FormItem label="创建时间" name="createTime">
<RangePicker allowClear={false} />
</FormItem>
<FormItem>
<Button type="primary" htmlType="submit" className="mr-15">搜索</Button>
<Button className="mr-15" htmlType="button" onClick={onReset}>重置</Button>
<Link to="/appliction/info"><Button>创建应用</Button></Link>
</FormItem>
</Form>
)
};
/* DataTable */
const DataTable = props => {
const {
loading,
handleDel,
handleGetList,
dataApplication: { data = [], page, size, totalItem }
} = props;
/* 点击分页 */
const handlePageChange = (page, size) => {
handleGetList(page, size);
};
const columns = [
{
title: '应用名称',
dataIndex: 'name',
align: 'center'
},
{
title: '应用标识码',
dataIndex: 'code',
align: 'center',
render(t, r) {
return t || '--'
}
},
{
title: '应用链接地址',
dataIndex: 'url',
align: 'center',
render(t, r) {
return t || '--'
}
},
{
title: '创建时间',
dataIndex: 'createTime',
align: 'center',
render(t, r) {
return t ? moment(t).format("YYYY-MM-DD HH:mm:ss") : '--'
}
},
{
title: '操作',
align: 'center',
render(t, r) {
return (
<>
<Link to={`/appliction/info?id=${r.id}`}>编辑</Link>
<Divider type="vertical" />
<a onClick={() => handleDel(r)}>删除</a>
</>
)
}
}
];
const pagination = {
...paginations,
total: totalItem,
pageSize: size,
current: page,
showSizeChanger: totalItem > 20,
onChange: (page, pageSize) => {
handlePageChange(page, pageSize);
},
onShowSizeChange: (page, pageSize) => {
handlePageChange(1, pageSize);
},
showTotal(total) {
return `总共 ${total} 条数据`;
},
};
return (
<Table
rowKey="id"
loading={loading}
dataSource={data}
columns={columns}
pagination={pagination}
/>
)
};
/* Main */
const Application = props => {
const { dispatch, loading, dataSearch, dataApplication, dataApplication: { size } } = props;
useEffect(() => {
handleGetList(1, 10);
}, [])
/* 应用列表 */
const handleGetList = (page, size) => {
dispatch({type: 'Application/getApplicationList', payload: {
page: page || 1,
size: size || 10
}});
};
/* 点击搜索 */
const handleFinish = (values) => {
const { createTime, name } = values;
dispatch({type: 'Application/changeState', payload: {
dataSearch: {
name,
createTimeBegin: createTime[0] ? createTime[0].startOf('day').valueOf() : undefined,
createTimeEnd: createTime[1] ? createTime[1].endOf('day').valueOf() : undefined,
}
}});
handleGetList(0, size);
};
/* 点击重置 */
const handleReset = () => {
dispatch({type: 'Application/resetSearch'});
handleGetList(0, 10);
};
/* 点击删除 */
const handleDel = ({ id }) => {
Modal.confirm({
title: '确定删除该应用吗?',
icon: <ExclamationCircleOutlined />,
okText: '确定',
cancelText: '取消',
onOk() {
dispatch({type: 'Application/delApplication', payload: {id}});
},
});
};
return (
<Card bordered={false}>
<SearchForm
dataSearch={dataSearch}
handleReset={handleReset}
handleFinish={handleFinish}
/>
<div className="mt-24">
<DataTable
loading={loading}
handleDel={handleDel}
handleGetList={handleGetList}
dataApplication={dataApplication}
/>
</div>
</Card>
)
};
export default connect(({ Application, loading }) => ({
...Application,
loading: loading.effects["Application/getApplicationList"]
}))(Application)