海口龙华志愿者后端管理页面
zhouxiantao
8 days ago 4def10e6567cf651ae333a2a65c497e717c06403
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
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
import React, { useEffect, useState } from 'react';
import { Row, Col, Card, Statistic, Button, Table, List, Avatar, Tag, message, Modal } from 'antd';
import { useNavigate } from 'react-router-dom';
import {
  UserOutlined,
  GiftOutlined,
  CalendarOutlined,
  TeamOutlined,
  PlusOutlined,
  EyeOutlined,
  EditOutlined,
} from '@ant-design/icons';
import ReactECharts from 'echarts-for-react';
import { statisticsAPI, dashboardAPI } from '../services/api';
import dayjs from 'dayjs';
 
const Dashboard = () => {
  const navigate = useNavigate();
  const [loading, setLoading] = useState(false);
  const [overviewData, setOverviewData] = useState({
    totalVolunteers: 0,
    totalPoints: 0,
    totalActivities: 0,
    totalRegistrations: 0,
  });
  const [recentActivities, setRecentActivities] = useState([]);
  const [recentVolunteers, setRecentVolunteers] = useState([]);
  const [pointsTrendData, setPointsTrendData] = useState({
    categories: [],
    totalPoints: [],
  });
  const [activityParticipationData, setActivityParticipationData] = useState([]);
  const [viewModalVisible, setViewModalVisible] = useState(false);
  const [viewingActivity, setViewingActivity] = useState(null);
 
  // 获取数据概览
  const fetchOverviewData = async () => {
    try {
      const response = await statisticsAPI.getOverview();
      if (response.code === 0) {
        setOverviewData(response.data);
      }
    } catch (error) {
      console.error('获取概览数据失败:', error);
      message.error('获取概览数据失败');
    }
  };
 
  // 获取最新活动列表
  const fetchRecentActivities = async () => {
    try {
      const response = await dashboardAPI.getRecentActivities(5);
      if (response.code === 0) {
        setRecentActivities(response.data);
      }
    } catch (error) {
      console.error('获取最新活动失败:', error);
      message.error('获取最新活动失败');
    }
  };
 
  // 获取最新志愿者列表
  const fetchRecentVolunteers = async () => {
    try {
      const response = await dashboardAPI.getRecentVolunteers(5);
      if (response.code === 0) {
        setRecentVolunteers(response.data);
      }
    } catch (error) {
      console.error('获取最新志愿者失败:', error);
      message.error('获取最新志愿者失败');
    }
  };
 
  // 获取积分趋势数据
  const fetchPointsTrend = async () => {
    try {
      const response = await statisticsAPI.getPointsTrend('month');
      if (response.code === 0) {
        setPointsTrendData(response.data);
      }
    } catch (error) {
      console.error('获取积分趋势失败:', error);
      message.error('获取积分趋势失败');
    }
  };
 
  // 获取活动参与度数据
  const fetchActivityParticipation = async () => {
    try {
      const response = await statisticsAPI.getActivityParticipation();
      if (response.code === 0) {
        setActivityParticipationData(response.data);
      }
    } catch (error) {
      console.error('获取活动参与度失败:', error);
      message.error('获取活动参与度失败');
    }
  };
 
  // 页面初始化加载数据
  useEffect(() => {
    const loadData = async () => {
      setLoading(true);
      try {
        await Promise.all([
          fetchOverviewData(),
          fetchRecentActivities(),
          fetchRecentVolunteers(),
          fetchPointsTrend(),
          fetchActivityParticipation(),
        ]);
      } finally {
        setLoading(false);
      }
    };
 
    loadData();
  }, []);
 
  // 积分趋势图表配置
  const pointsTrendOption = {
    title: {
      text: '积分趋势',
      left: 'center',
    },
    tooltip: {
      trigger: 'axis',
    },
    xAxis: {
      type: 'category',
      data: pointsTrendData.categories,
    },
    yAxis: {
      type: 'value',
    },
    series: [
      {
        name: '积分总数',
        type: 'line',
        data: pointsTrendData.totalPoints,
        smooth: true,
        itemStyle: {
          color: '#1890ff',
        },
      },
    ],
  };
 
  // 活动参与度图表配置
  const activityParticipationOption = {
    title: {
      text: '活动参与度',
      left: 'center',
    },
    tooltip: {
      trigger: 'item',
    },
    series: [
      {
        name: '参与情况',
        type: 'pie',
        radius: '50%',
        data: activityParticipationData,
        emphasis: {
          itemStyle: {
            shadowBlur: 10,
            shadowOffsetX: 0,
            shadowColor: 'rgba(0, 0, 0, 0.5)',
          },
        },
      },
    ],
  };
 
  // 查看活动详情
  const handleViewActivity = (activity) => {
    setViewingActivity(activity);
    setViewModalVisible(true);
  };
 
  const handleModalCancel = () => {
    setViewModalVisible(false);
    setViewingActivity(null);
  };
 
  // 活动状态转换函数
  const getActivityStatusText = (status) => {
    switch (status) {
      case '1':
        return '未开始';
      case '2':
        return '进行中';
      case '3':
        return '已结束';
      default:
        return status; // 如果不是数字状态码,直接返回原值
    }
  };
 
  const getStatusColor = (status) => {
    switch (status) {
      case '1':
      case '未开始':
        return 'default';
      case '2':
      case '进行中':
        return 'processing';
      case '3':
      case '已结束':
        return 'default';
      case '报名中':
        return 'warning';
      case '活跃':
        return 'success';
      default:
        return 'default';
    }
  };
 
  const quickActions = [
    {
      title: '发布活动',
      icon: <PlusOutlined />,
      color: '#1890ff',
      onClick: () => navigate('/activities/create'),
    },
    {
      title: '查看志愿者',
      icon: <TeamOutlined />,
      color: '#52c41a',
      onClick: () => navigate('/volunteers'),
    },
    {
      title: '积分查询',
      icon: <GiftOutlined />,
      color: '#faad14',
      onClick: () => navigate('/volunteers/points'),
    },
    {
      title: '数据统计',
      icon: <CalendarOutlined />,
      color: '#722ed1',
      onClick: () => navigate('/statistics/overview'),
    },
  ];
 
  return (
    <div>
      <div className="page-header">
        <h1 className="page-title">主控制台</h1>
        <p className="page-description">欢迎使用志愿者服务后台管理系统</p>
      </div>
 
      {/* 数据概览 */}
      <Row gutter={[16, 16]} style={{ marginBottom: 24 }}>
        <Col xs={24} sm={12} lg={6}>
          <Card>
            <Statistic
              title="志愿者总数"
              value={overviewData.totalVolunteers}
              prefix={<UserOutlined />}
              valueStyle={{ color: '#1890ff' }}
            />
          </Card>
        </Col>
        <Col xs={24} sm={12} lg={6}>
          <Card>
            <Statistic
              title="积分总数"
              value={overviewData.totalPoints}
              prefix={<GiftOutlined />}
              valueStyle={{ color: '#52c41a' }}
            />
          </Card>
        </Col>
        <Col xs={24} sm={12} lg={6}>
          <Card>
            <Statistic
              title="活动总数"
              value={overviewData.totalActivities}
              prefix={<CalendarOutlined />}
              valueStyle={{ color: '#faad14' }}
            />
          </Card>
        </Col>
        <Col xs={24} sm={12} lg={6}>
          <Card>
            <Statistic
              title="报名总数"
              value={overviewData.totalRegistrations}
              prefix={<TeamOutlined />}
              valueStyle={{ color: '#722ed1' }}
            />
          </Card>
        </Col>
      </Row>
 
      {/* 快捷操作 */}
      <Row gutter={[16, 16]} style={{ marginBottom: 24 }}>
        <Col span={24}>
          <Card title="快捷操作">
            <Row gutter={[16, 16]}>
              {quickActions.map((action, index) => (
                <Col xs={12} sm={6} key={index}>
                  <Button
                    type="dashed"
                    size="large"
                    icon={action.icon}
                    onClick={action.onClick}
                    style={{
                      width: '100%',
                      height: 80,
                      borderColor: action.color,
                      color: action.color,
                    }}
                  >
                    {action.title}
                  </Button>
                </Col>
              ))}
            </Row>
          </Card>
        </Col>
      </Row>
 
      {/* 图表区域 */}
      <Row gutter={[16, 16]} style={{ marginBottom: 24 }}>
        <Col xs={24} lg={12}>
          <Card>
            <ReactECharts option={pointsTrendOption} style={{ height: 300 }} />
          </Card>
        </Col>
        <Col xs={24} lg={12}>
          <Card>
            <ReactECharts option={activityParticipationOption} style={{ height: 300 }} />
          </Card>
        </Col>
      </Row>
 
      {/* 最新活动和志愿者 */}
      <Row gutter={[16, 16]}>
        <Col xs={24} lg={12}>
          <Card
            title="最新活动"
            extra={<Button type="link" onClick={() => navigate('/activities')}>查看全部</Button>}
          >
            <List
              dataSource={recentActivities}
              renderItem={(item) => (
                <List.Item
                  actions={[
                    <Button type="link" icon={<EyeOutlined />} onClick={() => handleViewActivity(item)}>
                      查看
                    </Button>
                  ]}
                >
                  <List.Item.Meta
                    title={item.title}
                    description={`${dayjs(item.date).format('YYYY-MM-DD HH:mm')} | 参与人数: ${item.participants}`}
                  />
                  <Tag color={getStatusColor(item.status)}>{getActivityStatusText(item.status)}</Tag>
                </List.Item>
              )}
            />
          </Card>
        </Col>
        <Col xs={24} lg={12}>
          <Card
            title="最新志愿者"
            extra={<Button type="link" onClick={() => navigate('/volunteers')}>查看全部</Button>}
          >
            <List
              dataSource={recentVolunteers}
              renderItem={(item) => (
                <List.Item
                  actions={[
                    <Button type="link" icon={<EyeOutlined />} onClick={() => navigate(`/volunteers/${item.id}`)}>
                      查看
                    </Button>
                  ]}
                >
                  <List.Item.Meta
                    avatar={<Avatar icon={<UserOutlined />} />}
                    title={item.name}
                    description={`加入时间: ${dayjs(item.joinDate).format('YYYY-MM-DD HH:mm')} | 积分: ${item.points}`}
                  />
                  <Tag color={getStatusColor(item.status)}>{item.status}</Tag>
                </List.Item>
              )}
            />
          </Card>
        </Col>
      </Row>
 
      {/* 查看活动详情弹窗 */}
      <Modal
        title="查看活动详情"
        open={viewModalVisible}
        onCancel={handleModalCancel}
        footer={[
          <Button key="close" onClick={handleModalCancel}>
            关闭
          </Button>
        ]}
        width={800}
      >
        {viewingActivity && (
          <div>
            <Row gutter={[24, 16]}>
              <Col span={12}>
                <div><strong>活动名称:</strong>{viewingActivity.title}</div>
              </Col>
              <Col span={12}>
                <div><strong>活动分类:</strong>{viewingActivity.categoryDesc || '未分类'}</div>
              </Col>
            </Row>
            <Row gutter={[24, 16]}>
              <Col span={12}>
                <div><strong>活动开始时间:</strong>{dayjs(viewingActivity.startTime || viewingActivity.date).format('YYYY-MM-DD HH:mm')}</div>
              </Col>
              <Col span={12}>
                <div><strong>活动结束时间:</strong>{dayjs(viewingActivity.endTime).format('YYYY-MM-DD HH:mm')}</div>
              </Col>
            </Row>
            <Row gutter={[24, 16]}>
              <Col span={12}>
                <div><strong>活动地点:</strong>{viewingActivity.location || '未设置'}</div>
              </Col>
              <Col span={12}>
                <div><strong>报名截止时间:</strong>{dayjs(viewingActivity.deadline).format('YYYY-MM-DD HH:mm')}</div>
              </Col>
            </Row>
            <Row gutter={[24, 16]}>
              <Col span={8}>
                <div><strong>最大志愿者人数:</strong>{viewingActivity.maxParticipants || '未设置'}</div>
              </Col>
              <Col span={8}>
                <div><strong>活动积分:</strong>{viewingActivity.points || 0}</div>
              </Col>
              <Col span={8}>
                <div><strong>状态:</strong>{getActivityStatusText(viewingActivity.status)}</div>
              </Col>
            </Row>
            <Row gutter={[24, 16]}>
              <Col span={12}>
                <div><strong>创建时间:</strong>{dayjs(viewingActivity.createTime).format('YYYY-MM-DD HH:mm')}</div>
              </Col>
              <Col span={12}>
                <div><strong>参与人数:</strong>{viewingActivity.participants || 0}</div>
              </Col>
            </Row>
            {viewingActivity.content && (
              <Row gutter={[24, 16]}>
                <Col span={24}>
                  <div><strong>活动内容:</strong></div>
                  <div style={{ marginTop: '8px', padding: '12px', backgroundColor: '#f5f5f5', borderRadius: '4px' }}>
                    {viewingActivity.content}
                  </div>
                </Col>
              </Row>
            )}
            {viewingActivity.cover && (
              <Row gutter={[24, 16]}>
                <Col span={24}>
                  <div><strong>活动封面:</strong></div>
                  <div style={{ marginTop: '8px' }}>
                    <img src={viewingActivity.cover} alt="活动封面" style={{ maxWidth: '200px', borderRadius: '4px' }} />
                  </div>
                </Col>
              </Row>
            )}
          </div>
        )}
      </Modal>
    </div>
  );
};
 
export default Dashboard;