后台仪表盘重新设计---待测试

This commit is contained in:
2025-12-22 21:58:18 +08:00
parent b765a5d4ed
commit 24984796cf
8 changed files with 239 additions and 60 deletions

View File

@@ -1,12 +1,12 @@
import { useState, useEffect } from 'react';
import { Card, Row, Col, Statistic, Button, Table, message, Tooltip } from 'antd';
import { Card, Row, Col, Statistic, Button, Table, message } from 'antd';
import {
UserOutlined,
QuestionCircleOutlined,
BarChartOutlined,
ReloadOutlined
} from '@ant-design/icons';
import { adminAPI } from '../../services/api';
import { adminAPI, quizAPI } from '../../services/api';
import { formatDateTime } from '../../utils/validation';
import { PieChart, Pie, Cell, ResponsiveContainer, Tooltip as RechartsTooltip, Legend, Label } from 'recharts';
@@ -73,14 +73,8 @@ const AdminDashboardPage = () => {
};
const fetchRecentRecords = async () => {
// 这里简化处理实际应该调用专门的API
const response = await fetch('/api/quiz/records?page=1&limit=10', {
headers: {
'Authorization': `Bearer ${localStorage.getItem('survey_admin') ? JSON.parse(localStorage.getItem('survey_admin')!).token : ''}`
}
});
const data = await response.json();
return data.success ? data.data : [];
const response = await quizAPI.getAllRecords({ page: 1, limit: 10 }) as any;
return response.data || [];
};
const columns = [

View File

@@ -1,7 +1,7 @@
import { useState, useEffect } from 'react';
import { Card, Row, Col, Statistic, Table, DatePicker, Button, message, Tabs, Select } from 'antd';
import { BarChart, Bar, XAxis, YAxis, CartesianGrid, Tooltip, ResponsiveContainer, PieChart, Pie, Cell, LineChart, Line } from 'recharts';
import { adminAPI } from '../../services/api';
import api, { adminAPI, quizAPI } from '../../services/api';
import { formatDateTime } from '../../utils/validation';
const { RangePicker } = DatePicker;
@@ -98,15 +98,8 @@ const StatisticsPage = () => {
const fetchRecords = async () => {
try {
const response = await fetch('/api/quiz/records?page=1&limit=100', {
headers: {
'Authorization': `Bearer ${localStorage.getItem('survey_admin') ? JSON.parse(localStorage.getItem('survey_admin')!).token : ''}`
}
});
const data = await response.json();
if (data.success) {
setRecords(data.data);
}
const response = await quizAPI.getAllRecords({ page: 1, limit: 100 }) as any;
setRecords(response.data || []);
} catch (error) {
console.error('获取答题记录失败:', error);
}
@@ -114,15 +107,8 @@ const StatisticsPage = () => {
const fetchUserStats = async () => {
try {
const response = await fetch('/api/admin/statistics/users', {
headers: {
'Authorization': `Bearer ${localStorage.getItem('survey_admin') ? JSON.parse(localStorage.getItem('survey_admin')!).token : ''}`
}
});
const data = await response.json();
if (data.success) {
setUserStats(data.data);
}
const response = await adminAPI.getUserStats() as any;
setUserStats(response.data || []);
} catch (error) {
console.error('获取用户统计失败:', error);
}
@@ -130,15 +116,8 @@ const StatisticsPage = () => {
const fetchSubjectStats = async () => {
try {
const response = await fetch('/api/admin/statistics/subjects', {
headers: {
'Authorization': `Bearer ${localStorage.getItem('survey_admin') ? JSON.parse(localStorage.getItem('survey_admin')!).token : ''}`
}
});
const data = await response.json();
if (data.success) {
setSubjectStats(data.data);
}
const response = await adminAPI.getSubjectStats() as any;
setSubjectStats(response.data || []);
} catch (error) {
console.error('获取科目统计失败:', error);
}
@@ -146,15 +125,8 @@ const StatisticsPage = () => {
const fetchTaskStats = async () => {
try {
const response = await fetch('/api/admin/statistics/tasks', {
headers: {
'Authorization': `Bearer ${localStorage.getItem('survey_admin') ? JSON.parse(localStorage.getItem('survey_admin')!).token : ''}`
}
});
const data = await response.json();
if (data.success) {
setTaskStats(data.data);
}
const response = await adminAPI.getTaskStats() as any;
setTaskStats(response.data || []);
} catch (error) {
console.error('获取任务统计失败:', error);
}
@@ -162,11 +134,8 @@ const StatisticsPage = () => {
const fetchSubjects = async () => {
try {
const response = await fetch('/api/exam-subjects');
const data = await response.json();
if (data.success) {
setSubjects(data.data);
}
const response = await api.get('/exam-subjects') as any;
setSubjects(response.data || []);
} catch (error) {
console.error('获取科目列表失败:', error);
}
@@ -174,11 +143,8 @@ const StatisticsPage = () => {
const fetchTasks = async () => {
try {
const response = await fetch('/api/exam-tasks');
const data = await response.json();
if (data.success) {
setTasks(data.data);
}
const response = await api.get('/exam-tasks') as any;
setTasks(response.data || []);
} catch (error) {
console.error('获取任务列表失败:', error);
}
@@ -433,4 +399,4 @@ const StatisticsPage = () => {
);
};
export default StatisticsPage;
export default StatisticsPage;