feat: 补全管理台功能 - 总览指标、搜索筛选、编辑模式、删除确认、全局日志查询
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { useState, useEffect } from 'react';
|
||||
import { useLocation, useNavigate } from 'react-router-dom';
|
||||
import { FiHome, FiBarChart2, FiUsers, FiList } from 'react-icons/fi';
|
||||
import { FiHome, FiBarChart2, FiUsers, FiList, FiActivity } from 'react-icons/fi';
|
||||
import Layout from '../components/Layout.jsx';
|
||||
import SidebarBrand from '../components/layout/SidebarBrand.jsx';
|
||||
import SidebarUser from '../components/layout/SidebarUser.jsx';
|
||||
@@ -15,40 +15,72 @@ import AdminProjectsPage from './admin/AdminProjectsPage.jsx';
|
||||
import AddDepartmentPage from './admin/AddDepartmentPage.jsx';
|
||||
import AddUserPage from './admin/AddUserPage.jsx';
|
||||
import AddProjectPage from './admin/AddProjectPage.jsx';
|
||||
import AdminLogsPage from './admin/AdminLogsPage.jsx';
|
||||
|
||||
function AdminPage() {
|
||||
const location = useLocation();
|
||||
const navigate = useNavigate();
|
||||
|
||||
// 使用 usePageState 管理页面状态
|
||||
const { currentPage, setCurrentPage } = usePageState({
|
||||
storageKey: ADMIN_KEYS.CURRENT_PAGE,
|
||||
defaultPage: 'overview',
|
||||
pageTitles: ADMIN_PAGES,
|
||||
});
|
||||
|
||||
const [editData, setEditData] = useState(null);
|
||||
|
||||
const navigateTo = (page, data) => {
|
||||
setEditData(data || null);
|
||||
setCurrentPage(page);
|
||||
};
|
||||
|
||||
const renderPage = () => {
|
||||
switch (currentPage) {
|
||||
case 'overview':
|
||||
return <OverviewPage />;
|
||||
case 'departments':
|
||||
return <DepartmentsPage onAdd={() => setCurrentPage('addDepartment')} />;
|
||||
return <DepartmentsPage
|
||||
onAdd={() => navigateTo('addDepartment')}
|
||||
onEdit={(dept) => navigateTo('addDepartment', dept)}
|
||||
/>;
|
||||
case 'users':
|
||||
return <UsersPage onAdd={() => setCurrentPage('addUser')} />;
|
||||
return <UsersPage
|
||||
onAdd={() => navigateTo('addUser')}
|
||||
onEdit={(user) => navigateTo('addUser', user)}
|
||||
/>;
|
||||
case 'projects':
|
||||
return <AdminProjectsPage onAdd={() => setCurrentPage('addProject')} />;
|
||||
return <AdminProjectsPage
|
||||
onAdd={() => navigateTo('addProject')}
|
||||
onEdit={(project) => navigateTo('addProject', project)}
|
||||
/>;
|
||||
case 'adminLogs':
|
||||
return <AdminLogsPage />;
|
||||
case 'addDepartment':
|
||||
return <AddDepartmentPage onBack={() => setCurrentPage('departments')} />;
|
||||
return <AddDepartmentPage
|
||||
onBack={() => navigateTo('departments')}
|
||||
editData={editData}
|
||||
/>;
|
||||
case 'addUser':
|
||||
return <AddUserPage onBack={() => setCurrentPage('users')} />;
|
||||
return <AddUserPage
|
||||
onBack={() => navigateTo('users')}
|
||||
editData={editData}
|
||||
/>;
|
||||
case 'addProject':
|
||||
return <AddProjectPage onBack={() => setCurrentPage('projects')} />;
|
||||
return <AddProjectPage
|
||||
onBack={() => navigateTo('projects')}
|
||||
editData={editData}
|
||||
/>;
|
||||
default:
|
||||
return <div>Page not found</div>;
|
||||
}
|
||||
};
|
||||
|
||||
const getPageTitle = () => {
|
||||
if (editData && (currentPage === 'addDepartment' || currentPage === 'addUser' || currentPage === 'addProject')) {
|
||||
const prefix = '编辑';
|
||||
const nameMap = { addDepartment: '部门', addUser: '用户', addProject: '项目' };
|
||||
return prefix + nameMap[currentPage];
|
||||
}
|
||||
return ADMIN_PAGES[currentPage]?.title || '';
|
||||
};
|
||||
|
||||
@@ -62,7 +94,7 @@ function AdminPage() {
|
||||
icon={<FiHome />}
|
||||
label="总览"
|
||||
active={currentPage === 'overview'}
|
||||
onClick={() => setCurrentPage('overview')}
|
||||
onClick={() => navigateTo('overview')}
|
||||
itemClassName="admin-nav-item"
|
||||
iconClassName="admin-nav-icon"
|
||||
textClassName="admin-nav-text"
|
||||
@@ -71,7 +103,7 @@ function AdminPage() {
|
||||
icon={<FiBarChart2 />}
|
||||
label="部门管理"
|
||||
active={currentPage === 'departments'}
|
||||
onClick={() => setCurrentPage('departments')}
|
||||
onClick={() => navigateTo('departments')}
|
||||
itemClassName="admin-nav-item"
|
||||
iconClassName="admin-nav-icon"
|
||||
textClassName="admin-nav-text"
|
||||
@@ -80,7 +112,7 @@ function AdminPage() {
|
||||
icon={<FiUsers />}
|
||||
label="用户管理"
|
||||
active={currentPage === 'users'}
|
||||
onClick={() => setCurrentPage('users')}
|
||||
onClick={() => navigateTo('users')}
|
||||
itemClassName="admin-nav-item"
|
||||
iconClassName="admin-nav-icon"
|
||||
textClassName="admin-nav-text"
|
||||
@@ -89,7 +121,16 @@ function AdminPage() {
|
||||
icon={<FiList />}
|
||||
label="项目管理"
|
||||
active={currentPage === 'projects'}
|
||||
onClick={() => setCurrentPage('projects')}
|
||||
onClick={() => navigateTo('projects')}
|
||||
itemClassName="admin-nav-item"
|
||||
iconClassName="admin-nav-icon"
|
||||
textClassName="admin-nav-text"
|
||||
/>
|
||||
<SidebarNavItem
|
||||
icon={<FiActivity />}
|
||||
label="日志查询"
|
||||
active={currentPage === 'adminLogs'}
|
||||
onClick={() => navigateTo('adminLogs')}
|
||||
itemClassName="admin-nav-item"
|
||||
iconClassName="admin-nav-icon"
|
||||
textClassName="admin-nav-text"
|
||||
@@ -116,4 +157,4 @@ function AdminPage() {
|
||||
);
|
||||
}
|
||||
|
||||
export default AdminPage;
|
||||
export default AdminPage;
|
||||
|
||||
Reference in New Issue
Block a user