fix: 修复proxy_service和account_service中不当的顶层import

- proxy_service.py: 将requests和WhitelistManager改为函数内延迟import,
  避免启动时加载不需要的依赖;移除未使用的get_exit_ip_via_proxy导入
- account_service.py: 移除未使用的func、joinedload、AuditLog、
  user_has_permission顶层导入
This commit is contained in:
yml2213
2026-06-23 08:35:29 +08:00
parent 2ab6724543
commit dd56de9bd4
40 changed files with 2006 additions and 936 deletions
+13 -9
View File
@@ -7,9 +7,10 @@ import {
SunOutlined, MoonOutlined, DesktopOutlined, FileTextOutlined,
} from '@ant-design/icons';
import { useNavigate, useLocation, Outlet } from 'react-router-dom';
import { getUser, clearAuth, hasPerm, type AuthUser } from '../store/auth';
import { getUser, clearAuth, type AuthUser } from '../store/auth';
import { authApi } from '../api/modules';
import { useTheme, type ThemeMode } from '../store/theme';
import { usePermissions } from '../hooks/usePermissions';
const { Sider, Content } = Layout;
const { Text } = Typography;
@@ -32,6 +33,7 @@ export default function MainLayout({ onLogout }: { onLogout?: () => void }) {
const [user] = useState<AuthUser | null>(getUser());
const [collapsed, setCollapsed] = useState(false);
const { mode, isDark, setMode } = useTheme();
const { can, canAny } = usePermissions(user);
useEffect(() => {
if (!user) navigate('/login');
@@ -45,37 +47,37 @@ export default function MainLayout({ onLogout }: { onLogout?: () => void }) {
menuItems.push({ key: '/', label: '概览', icon: <DashboardOutlined /> });
// 账号管理
if (hasPerm(user, 'account:view_all') || hasPerm(user, 'account:view_assigned')) {
if (canAny(['account:view_all', 'account:view_assigned'])) {
menuItems.push({ key: '/accounts', label: '账号管理', icon: <UserOutlined /> });
}
// 分配管理
if (hasPerm(user, 'account:assign')) {
if (can('account:assign')) {
menuItems.push({ key: '/assignments', label: '分配管理', icon: <SwapOutlined /> });
}
// 登录任务
if (hasPerm(user, 'login:batch') || hasPerm(user, 'login:view_all')) {
if (canAny(['login:batch', 'login:view_all'])) {
menuItems.push({ key: '/login-tasks', label: '登录任务', icon: <ApiOutlined /> });
}
// Cookie 管理
if (hasPerm(user, 'cookie:view')) {
if (can('cookie:view')) {
menuItems.push({ key: '/cookies', label: 'Cookie 管理', icon: <KeyOutlined /> });
}
// 代理配置
if (hasPerm(user, 'proxy:manage')) {
if (can('proxy:manage')) {
menuItems.push({ key: '/proxy', label: '代理配置', icon: <CloudServerOutlined /> });
}
// 请求日志(运营和管理员可见)
if (hasPerm(user, 'audit:view') || hasPerm(user, 'login:batch')) {
if (canAny(['audit:view', 'login:batch'])) {
menuItems.push({ key: '/http-logs', label: '请求日志', icon: <FileTextOutlined /> });
}
// 用户管理
if (hasPerm(user, 'user:view')) {
if (can('user:view')) {
menuItems.push({ key: '/users', label: '用户管理', icon: <TeamOutlined /> });
}
@@ -90,7 +92,9 @@ export default function MainLayout({ onLogout }: { onLogout?: () => void }) {
onOk: async () => {
try {
await authApi.logout();
} catch {}
} catch {
// 忽略服务端登出失败,仍继续清理本地登录态。
}
clearAuth();
onLogout?.();
navigate('/login', { replace: true });