|
@@ -1,53 +1,75 @@
|
1
|
|
-import { history, Link } from 'umi';
|
2
|
|
-import { useRef } from 'react';
|
3
|
|
-import { Button, Modal, message, Popconfirm, Tooltip } from 'antd';
|
4
|
|
-import { PlusOutlined, QuestionCircleOutlined } from '@ant-design/icons';
|
|
1
|
+import React, { useState, useEffect, useRef } from 'react';
|
|
2
|
+import { Button, Popconfirm, Modal, Form, Input, message } from 'antd';
|
|
3
|
+import { PlusOutlined } from '@ant-design/icons';
|
5
|
4
|
import { PageHeaderWrapper } from '@ant-design/pro-layout';
|
6
|
|
-import ProTable, { TableDropdown } from '@ant-design/pro-table';
|
|
5
|
+import moment from 'moment';
|
|
6
|
+import PageTable from '@/components/PageTable';
|
|
7
|
+import { getNewsTypeList, addNewsType, deleteNewsType, updateNewsType } from '@/services/newsType';
|
7
|
8
|
|
8
|
|
-export default (props) => {
|
9
|
|
- const dataSource = [
|
10
|
|
- {
|
11
|
|
- id: 9,
|
12
|
|
- key: '1',
|
13
|
|
- name: '胡彦斌',
|
14
|
|
- age: 32,
|
15
|
|
- zz: '西湖区湖底公园1号',
|
16
|
|
- },
|
17
|
|
- ];
|
18
|
|
-
|
19
|
|
- // 测试内容👆-------------------------
|
|
9
|
+const formatterTime = (val) => {
|
|
10
|
+ return val && val !== '-' ? moment(val).format('YYYY-MM-DD') : '-';
|
|
11
|
+};
|
|
12
|
+const FormItem = Form.Item;
|
20
|
13
|
|
|
14
|
+export default (props) => {
|
|
15
|
+ const formItemLayout = { labelCol: { span: 6 }, wrapperCol: { span: 14 } };
|
|
16
|
+ const [form] = Form.useForm();
|
|
17
|
+ const [editModal, setEditModal] = useState(false);
|
|
18
|
+ const [loading, setLoading] = useState(false);
|
|
19
|
+ const [typeId, setTypeId] = useState();
|
21
|
20
|
const actionRef = useRef();
|
22
|
|
- const gotoDetail = (id) => {
|
23
|
|
- history.push(`InformationClassification/InformationClassificationEdit`);
|
24
|
|
- };
|
25
|
|
-
|
26
|
|
- const handleDelete = (e) => {
|
27
|
|
- deleteNote(e.noteId).then((res) => {
|
28
|
|
- message.success('删除成功');
|
29
|
|
- actionRef.current.reload();
|
30
|
|
- });
|
31
|
|
- };
|
32
|
21
|
|
33
|
|
- const handleOK = (record, data) => {
|
34
|
|
- const titleCourse = record.status
|
35
|
|
- ? '您确定要禁用该用户吗? 禁用后该用户不能在后台登陆!'
|
36
|
|
- : '您确定要启用该用户吗? 启用后该用户将允许在后台登陆!';
|
37
|
|
- Modal.confirm({
|
38
|
|
- title: titleCourse,
|
39
|
|
- okText: '确认',
|
40
|
|
- cancelText: '取消',
|
41
|
|
- onOk() {
|
42
|
|
- publishNote(record.noteId, record.status ? 'off' : 'on').then((res) => {
|
43
|
|
- message.success('操作成功');
|
|
22
|
+ const Submit = (values) => {
|
|
23
|
+ setLoading(true);
|
|
24
|
+ if (typeId) {
|
|
25
|
+ updateNewsType(typeId, values).then(() => {
|
|
26
|
+ setLoading(false);
|
|
27
|
+ message.success(`修改成功`);
|
|
28
|
+ onCancel();
|
|
29
|
+ actionRef.current.reload();
|
|
30
|
+ });
|
|
31
|
+ } else {
|
|
32
|
+ addNewsType(values)
|
|
33
|
+ .then(() => {
|
|
34
|
+ setLoading(false);
|
|
35
|
+ message.success(`保存成功`);
|
|
36
|
+ onCancel();
|
44
|
37
|
actionRef.current.reload();
|
|
38
|
+ })
|
|
39
|
+ .catch((err) => {
|
|
40
|
+ setLoading(false);
|
|
41
|
+ message.error(err.message || err);
|
45
|
42
|
});
|
46
|
|
- },
|
47
|
|
- });
|
|
43
|
+ }
|
|
44
|
+ };
|
|
45
|
+ const handelEdit = (val) => {
|
|
46
|
+ setTypeId(val.typeId);
|
|
47
|
+ form.setFieldsValue(val);
|
|
48
|
+ setEditModal(true);
|
|
49
|
+ };
|
|
50
|
+ const onCancel = () => {
|
|
51
|
+ setTypeId();
|
|
52
|
+ form.resetFields();
|
|
53
|
+ setEditModal(false);
|
48
|
54
|
};
|
|
55
|
+ const handleDelete = (id) => {
|
|
56
|
+ deleteNewsType(id)
|
|
57
|
+ .then(() => {
|
|
58
|
+ message.success('删除成功');
|
|
59
|
+ actionRef.current.reload();
|
|
60
|
+ })
|
|
61
|
+ .catch((err) => {
|
|
62
|
+ message.error(err);
|
|
63
|
+ });
|
|
64
|
+ };
|
|
65
|
+ useEffect(() => {
|
|
66
|
+ if (typeId) {
|
|
67
|
+ } else {
|
|
68
|
+ form.resetFields();
|
|
69
|
+ }
|
|
70
|
+ }, [typeId]);
|
49
|
71
|
const actions = () => [
|
50
|
|
- <Button key="add" type="primary" icon={<PlusOutlined />} onClick={() => gotoDetail()}>
|
|
72
|
+ <Button key="add" type="primary" icon={<PlusOutlined />} onClick={() => setEditModal(true)}>
|
51
|
73
|
新增
|
52
|
74
|
</Button>,
|
53
|
75
|
];
|
|
@@ -56,45 +78,33 @@ export default (props) => {
|
56
|
78
|
title: '分类名',
|
57
|
79
|
dataIndex: 'name',
|
58
|
80
|
key: 'name',
|
59
|
|
- search: false,
|
60
|
81
|
},
|
61
|
|
-
|
62
|
82
|
{
|
63
|
|
- title: (
|
64
|
|
- <>
|
65
|
|
- 创建时间
|
66
|
|
- <Tooltip placement="top">
|
67
|
|
- <QuestionCircleOutlined style={{ marginLeft: 4 }} />
|
68
|
|
- </Tooltip>
|
69
|
|
- </>
|
70
|
|
- ),
|
71
|
|
- // hideInTable: true,
|
|
83
|
+ title: '创建时间',
|
|
84
|
+ dataIndex: 'createDate',
|
|
85
|
+ key: 'createDate',
|
|
86
|
+ render: formatterTime,
|
72
|
87
|
search: false,
|
73
|
|
-
|
74
|
|
- key: 'createdAt',
|
75
|
|
- dataIndex: 'createdAt',
|
76
|
|
- valueType: 'date',
|
77
|
|
- // render: (t) => formatterTime(t),
|
78
|
|
- sorter: (a, b) => a.createdAt - b.createdAt, //时间排序
|
|
88
|
+ width: 240,
|
79
|
89
|
},
|
80
|
90
|
{
|
81
|
91
|
title: '操作',
|
82
|
92
|
valueType: 'option',
|
83
|
|
- key: 'option',
|
84
|
|
- ellipsis: true,
|
85
|
|
- width: 200,
|
|
93
|
+ width: 160,
|
86
|
94
|
render: (_, record) => [
|
87
|
|
- <Link key={2} to={`InformationClassification/InformationClassificationEdit`}>
|
|
95
|
+ <Button type="link" style={{ padding: 0 }} key={1} onClick={() => handelEdit(record)}>
|
88
|
96
|
编辑
|
89
|
|
- </Link>,
|
|
97
|
+ </Button>,
|
90
|
98
|
<Popconfirm
|
91
|
|
- key={3}
|
|
99
|
+ key={2}
|
92
|
100
|
title="您是否确认删除 ?"
|
93
|
|
- onConfirm={() => handleDelete(record)}
|
|
101
|
+ onConfirm={() => handleDelete(record.typeId)}
|
94
|
102
|
okText="确定"
|
95
|
103
|
cancelText="取消"
|
96
|
104
|
>
|
97
|
|
- <a href="#">删除</a>
|
|
105
|
+ <Button style={{ padding: 0 }} type="link">
|
|
106
|
+ 删除
|
|
107
|
+ </Button>
|
98
|
108
|
</Popconfirm>,
|
99
|
109
|
],
|
100
|
110
|
},
|
|
@@ -102,16 +112,44 @@ export default (props) => {
|
102
|
112
|
|
103
|
113
|
return (
|
104
|
114
|
<PageHeaderWrapper>
|
105
|
|
- <ProTable
|
106
|
|
- dataSource={dataSource}
|
|
115
|
+ <PageTable
|
|
116
|
+ request={getNewsTypeList}
|
107
|
117
|
columns={columns}
|
108
|
|
- // request={getNoteList} 请求
|
109
|
|
- // rowKey="noteId"
|
110
|
|
- search={false}
|
|
118
|
+ actionRef={actionRef}
|
|
119
|
+ rowKey="typeId"
|
111
|
120
|
options={false}
|
112
|
121
|
toolBarRender={actions}
|
113
|
|
- actionRef={actionRef}
|
|
122
|
+ scroll={{ x: 1000 }}
|
114
|
123
|
/>
|
|
124
|
+ <Modal
|
|
125
|
+ forceRender
|
|
126
|
+ title={typeId ? '分类编辑' : '分类新增'}
|
|
127
|
+ visible={editModal}
|
|
128
|
+ onCancel={onCancel}
|
|
129
|
+ keyboard={false}
|
|
130
|
+ maskClosable={false}
|
|
131
|
+ destroyOnClose={true}
|
|
132
|
+ footer={null}
|
|
133
|
+ >
|
|
134
|
+ <Form {...formItemLayout} onFinish={Submit} form={form}>
|
|
135
|
+ <FormItem label="分类名" name="name" rules={[{ required: true, message: '请输入' }]}>
|
|
136
|
+ <Input placeholder="请输入" />
|
|
137
|
+ </FormItem>
|
|
138
|
+ <FormItem label=" " colon={false}>
|
|
139
|
+ <Button type="default" onClick={onCancel}>
|
|
140
|
+ 取消
|
|
141
|
+ </Button>
|
|
142
|
+ <Button
|
|
143
|
+ type="primary"
|
|
144
|
+ loading={loading}
|
|
145
|
+ htmlType="Submit"
|
|
146
|
+ style={{ marginLeft: '4em' }}
|
|
147
|
+ >
|
|
148
|
+ 确认
|
|
149
|
+ </Button>
|
|
150
|
+ </FormItem>
|
|
151
|
+ </Form>
|
|
152
|
+ </Modal>
|
115
|
153
|
</PageHeaderWrapper>
|
116
|
154
|
);
|
117
|
155
|
};
|