|
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
|
|
|
2
|
+import React, { useState, useRef, useEffect } from 'react';
|
|
|
3
|
+import { useIntl, FormattedMessage } from '@umijs/max';
|
|
|
4
|
+import type { FormInstance } from 'antd';
|
|
|
5
|
+import { Button, message, Modal, Image } from 'antd';
|
|
|
6
|
+import { ActionType, PageContainer, ProColumns, ProTable } from '@ant-design/pro-components';
|
|
|
7
|
+import { PlusOutlined } from '@ant-design/icons';
|
|
|
8
|
+import { getBannerList, saveBanner, deleteBanner,push } from '@/services/product/member';
|
|
|
9
|
+import BannerForm from './edit';
|
|
|
10
|
+import { KeepAlive } from 'react-activation';
|
|
|
11
|
+import './index.less'
|
|
|
12
|
+import { getDataEnumList } from '../../../services/system/Enum';
|
|
|
13
|
+
|
|
|
14
|
+
|
|
|
15
|
+const NoticeTableList: React.FC = () => {
|
|
|
16
|
+ const formTableRef = useRef<FormInstance>();
|
|
|
17
|
+
|
|
|
18
|
+ const [modalVisible, setModalVisible] = useState<boolean>(false);
|
|
|
19
|
+
|
|
|
20
|
+ const actionRef = useRef<ActionType>();
|
|
|
21
|
+ const intl = useIntl();
|
|
|
22
|
+ const [currentRow, setCurrentRow] = useState<any>();
|
|
|
23
|
+ const [enumList, setEnumList] = useState()
|
|
|
24
|
+
|
|
|
25
|
+ const handleRemoveOne = async (selectedRow: API.System.Notice) => {
|
|
|
26
|
+ const hide = message.loading(intl.formatMessage({ id: 'public.loadingDelete' }));
|
|
|
27
|
+ if (!selectedRow) return true;
|
|
|
28
|
+ try {
|
|
|
29
|
+ const params = [selectedRow.uuid];
|
|
|
30
|
+ const resp = await deleteBanner(params.join(','));
|
|
|
31
|
+ hide();
|
|
|
32
|
+ if (resp.code === 200) {
|
|
|
33
|
+ message.success(intl.formatMessage({ id: 'public.deleteSuccess' }));
|
|
|
34
|
+ } else {
|
|
|
35
|
+ message.error(resp.msg);
|
|
|
36
|
+ }
|
|
|
37
|
+ return true;
|
|
|
38
|
+ } catch (error) {
|
|
|
39
|
+ hide();
|
|
|
40
|
+ message.error(intl.formatMessage({ id: 'public.deleteError' }));
|
|
|
41
|
+ return false;
|
|
|
42
|
+ }
|
|
|
43
|
+ };
|
|
|
44
|
+
|
|
|
45
|
+ useEffect(() => {
|
|
|
46
|
+ getEnum()
|
|
|
47
|
+ }, [])
|
|
|
48
|
+
|
|
|
49
|
+ const getEnum = () => {
|
|
|
50
|
+ getDataEnumList({ enumUuid: '2024810214616101' }).then((res) => {
|
|
|
51
|
+ console.log(res.rows)
|
|
|
52
|
+
|
|
|
53
|
+ const enumOptions = res.rows.map((item: any) => ({
|
|
|
54
|
+ label: item.dataName,
|
|
|
55
|
+ value: item.uuid,
|
|
|
56
|
+ }));
|
|
|
57
|
+ setEnumList(enumOptions); // 设置 enumList
|
|
|
58
|
+ })
|
|
|
59
|
+ }
|
|
|
60
|
+ const columns: ProColumns<API.System.Notice>[] = [
|
|
|
61
|
+ {
|
|
|
62
|
+ title: '序号',
|
|
|
63
|
+ dataIndex: 'id',
|
|
|
64
|
+ valueType: 'text',
|
|
|
65
|
+ hideInSearch: true,
|
|
|
66
|
+ render: (_, record: any) => {
|
|
|
67
|
+ // console.log('record---',_,record)
|
|
|
68
|
+ return record.rowIndex;
|
|
|
69
|
+ },
|
|
|
70
|
+ },
|
|
|
71
|
+ {
|
|
|
72
|
+ title: 'logo图片',
|
|
|
73
|
+ dataIndex: 'pcImgUrl',
|
|
|
74
|
+ valueType: 'text',
|
|
|
75
|
+ hideInSearch: true,
|
|
|
76
|
+ render: (_, record: any) => {
|
|
|
77
|
+ // console.log('record---',_,record)
|
|
|
78
|
+ return <Image src={record.pcImgUrl} style={{ 'height': '40px' }}></Image>;
|
|
|
79
|
+ }
|
|
|
80
|
+ },
|
|
|
81
|
+ // {
|
|
|
82
|
+ // title: '焦点图(移动端)',
|
|
|
83
|
+ // dataIndex: 'mImgUrl',
|
|
|
84
|
+ // valueType: 'text',
|
|
|
85
|
+ // hideInSearch: true,
|
|
|
86
|
+ // render: (_, record: any) => {
|
|
|
87
|
+ // // console.log('record---',_,record)
|
|
|
88
|
+ // return <Image src={record.mImgUrl} style={{ 'height': '40px' }}></Image>;
|
|
|
89
|
+ // }
|
|
|
90
|
+ // },
|
|
|
91
|
+ {
|
|
|
92
|
+ title: '标题',
|
|
|
93
|
+ dataIndex: 'title',
|
|
|
94
|
+ valueType: 'text',
|
|
|
95
|
+ hideInSearch: true,
|
|
|
96
|
+ },
|
|
|
97
|
+ {
|
|
|
98
|
+ title: '简述',
|
|
|
99
|
+ dataIndex: 'digest',
|
|
|
100
|
+ valueType: 'text',
|
|
|
101
|
+ hideInSearch: true,
|
|
|
102
|
+ },
|
|
|
103
|
+ {
|
|
|
104
|
+ title: '链接',
|
|
|
105
|
+ dataIndex: 'url',
|
|
|
106
|
+ valueType: 'text',
|
|
|
107
|
+ hideInSearch: true,
|
|
|
108
|
+ },
|
|
|
109
|
+ {
|
|
|
110
|
+ title: '排序',
|
|
|
111
|
+ dataIndex: 'sort',
|
|
|
112
|
+ valueType: 'text',
|
|
|
113
|
+ hideInSearch: true,
|
|
|
114
|
+ },
|
|
|
115
|
+ {
|
|
|
116
|
+ title: '操作',
|
|
|
117
|
+ dataIndex: 'option',
|
|
|
118
|
+ width: '120px',
|
|
|
119
|
+ valueType: 'option',
|
|
|
120
|
+ render: (_, record: any) => [
|
|
|
121
|
+ <Button
|
|
|
122
|
+ type="link"
|
|
|
123
|
+ size="small"
|
|
|
124
|
+ key="edit"
|
|
|
125
|
+
|
|
|
126
|
+ onClick={() => {
|
|
|
127
|
+ setModalVisible(true);
|
|
|
128
|
+ setCurrentRow(record);
|
|
|
129
|
+ }}
|
|
|
130
|
+ >
|
|
|
131
|
+ 编辑
|
|
|
132
|
+ </Button>,
|
|
|
133
|
+
|
|
|
134
|
+ <Button
|
|
|
135
|
+ type="link"
|
|
|
136
|
+ size="small"
|
|
|
137
|
+ danger
|
|
|
138
|
+ key="batchRemove"
|
|
|
139
|
+
|
|
|
140
|
+ onClick={async () => {
|
|
|
141
|
+ Modal.confirm({
|
|
|
142
|
+ title: intl.formatMessage({ id: 'public.delete' }),
|
|
|
143
|
+ content: intl.formatMessage({ id: 'public.confirmdeletemsg' }),
|
|
|
144
|
+ okText: intl.formatMessage({ id: 'public.confirm' }),
|
|
|
145
|
+ cancelText: intl.formatMessage({ id: 'public.cancel' }),
|
|
|
146
|
+ onOk: async () => {
|
|
|
147
|
+ const success = await handleRemoveOne(record);
|
|
|
148
|
+ if (success) {
|
|
|
149
|
+ if (actionRef.current) {
|
|
|
150
|
+ actionRef.current.reload();
|
|
|
151
|
+ }
|
|
|
152
|
+ }
|
|
|
153
|
+ },
|
|
|
154
|
+ });
|
|
|
155
|
+ }}
|
|
|
156
|
+ >
|
|
|
157
|
+ <FormattedMessage id="public.delete" defaultMessage="删除" />
|
|
|
158
|
+ </Button>,
|
|
|
159
|
+ ],
|
|
|
160
|
+ },
|
|
|
161
|
+ ];
|
|
|
162
|
+
|
|
|
163
|
+ /**
|
|
|
164
|
+ * 一键发布
|
|
|
165
|
+ */
|
|
|
166
|
+ const publishing = async () => {
|
|
|
167
|
+ try {
|
|
|
168
|
+ const resp = await push();
|
|
|
169
|
+ if (resp.code === 200) {
|
|
|
170
|
+ message.success('发布成功');
|
|
|
171
|
+ } else {
|
|
|
172
|
+ message.error(resp.msg);
|
|
|
173
|
+ }
|
|
|
174
|
+ } catch (error) { }
|
|
|
175
|
+ }
|
|
|
176
|
+
|
|
|
177
|
+ return (
|
|
|
178
|
+ <KeepAlive name='成员名录' path="/Product/member">
|
|
|
179
|
+ <PageContainer>
|
|
|
180
|
+ <div style={{ width: '100%', float: 'right' }}>
|
|
|
181
|
+ <ProTable<API.System.Notice>
|
|
|
182
|
+ actionRef={actionRef}
|
|
|
183
|
+ formRef={formTableRef}
|
|
|
184
|
+ rowKey="uuid"
|
|
|
185
|
+ search={false}
|
|
|
186
|
+ toolBarRender={() => [
|
|
|
187
|
+ <Button
|
|
|
188
|
+ type="primary"
|
|
|
189
|
+ key="add"
|
|
|
190
|
+ onClick={async () => {
|
|
|
191
|
+ setCurrentRow(undefined);
|
|
|
192
|
+ setModalVisible(true);
|
|
|
193
|
+ }}
|
|
|
194
|
+ >
|
|
|
195
|
+ <PlusOutlined /> <FormattedMessage id="public.add" defaultMessage="新建" />
|
|
|
196
|
+ </Button>,
|
|
|
197
|
+ <Button
|
|
|
198
|
+ type="primary"
|
|
|
199
|
+ key="fabu"
|
|
|
200
|
+ onClick={publishing}
|
|
|
201
|
+ >
|
|
|
202
|
+ 一键发布
|
|
|
203
|
+ </Button>
|
|
|
204
|
+ ]}
|
|
|
205
|
+ request={(params) => {
|
|
|
206
|
+ return getBannerList({ ...params } as API.System.NoticeListParams).then((res) => {
|
|
|
207
|
+
|
|
|
208
|
+ res.rows.forEach((item: any, index: any) => {
|
|
|
209
|
+ item.rowIndex = index + 1
|
|
|
210
|
+ })
|
|
|
211
|
+ const result = {
|
|
|
212
|
+ data: res.rows,
|
|
|
213
|
+ total: res.total,
|
|
|
214
|
+ success: true,
|
|
|
215
|
+
|
|
|
216
|
+ };
|
|
|
217
|
+ return result;
|
|
|
218
|
+ })
|
|
|
219
|
+ }
|
|
|
220
|
+ }
|
|
|
221
|
+ columns={columns}
|
|
|
222
|
+ />
|
|
|
223
|
+ </div>
|
|
|
224
|
+ <BannerForm
|
|
|
225
|
+ onSubmit={async (values) => {
|
|
|
226
|
+ let success = false;
|
|
|
227
|
+ if (currentRow) {
|
|
|
228
|
+ values.uuid = currentRow.uuid;
|
|
|
229
|
+ }
|
|
|
230
|
+
|
|
|
231
|
+ success = await saveBanner({ ...values });
|
|
|
232
|
+ if (success) {
|
|
|
233
|
+ setModalVisible(false);
|
|
|
234
|
+ setCurrentRow(undefined);
|
|
|
235
|
+ if (actionRef.current) {
|
|
|
236
|
+ actionRef.current.reload();
|
|
|
237
|
+ }
|
|
|
238
|
+ }
|
|
|
239
|
+ }}
|
|
|
240
|
+ onCancel={() => {
|
|
|
241
|
+ setModalVisible(false);
|
|
|
242
|
+ setCurrentRow(undefined);
|
|
|
243
|
+ }}
|
|
|
244
|
+ currentRow={currentRow}
|
|
|
245
|
+ open={modalVisible}
|
|
|
246
|
+ />
|
|
|
247
|
+ </PageContainer>
|
|
|
248
|
+ </KeepAlive>
|
|
|
249
|
+
|
|
|
250
|
+ );
|
|
|
251
|
+};
|
|
|
252
|
+
|
|
|
253
|
+export default NoticeTableList;
|