后台仪表盘重新设计---待测试
This commit is contained in:
@@ -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 = [
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -110,6 +110,9 @@ export const adminAPI = {
|
||||
updateQuizConfig: (data: any) => api.put('/admin/config', data),
|
||||
getStatistics: () => api.get('/admin/statistics'),
|
||||
getActiveTasksStats: () => api.get('/admin/active-tasks'),
|
||||
getUserStats: () => api.get('/admin/statistics/users'),
|
||||
getSubjectStats: () => api.get('/admin/statistics/subjects'),
|
||||
getTaskStats: () => api.get('/admin/statistics/tasks'),
|
||||
updatePassword: (data: { username: string; oldPassword: string; newPassword: string }) =>
|
||||
api.put('/admin/password', data),
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user