mirror of
https://github.com/router-for-me/Cli-Proxy-API-Management-Center.git
synced 2026-02-03 11:20:50 +08:00
Compare commits
9 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
589a5bad4c | ||
|
|
bcaa0c8545 | ||
|
|
312a06a8b8 | ||
|
|
24861dabd2 | ||
|
|
ea1bdc3ac1 | ||
|
|
46701b40ad | ||
|
|
c9fc22bae5 | ||
|
|
961cc802b2 | ||
|
|
5f7df33469 |
@@ -31,10 +31,11 @@ function App() {
|
|||||||
const [authReady, setAuthReady] = useState(false);
|
const [authReady, setAuthReady] = useState(false);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
initializeTheme();
|
const cleanupTheme = initializeTheme();
|
||||||
void restoreSession().finally(() => {
|
void restoreSession().finally(() => {
|
||||||
setAuthReady(true);
|
setAuthReady(true);
|
||||||
});
|
});
|
||||||
|
return cleanupTheme;
|
||||||
}, [initializeTheme, restoreSession]);
|
}, [initializeTheme, restoreSession]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|||||||
@@ -1,4 +1,12 @@
|
|||||||
import { ReactNode, SVGProps, useCallback, useEffect, useLayoutEffect, useRef, useState } from 'react';
|
import {
|
||||||
|
ReactNode,
|
||||||
|
SVGProps,
|
||||||
|
useCallback,
|
||||||
|
useEffect,
|
||||||
|
useLayoutEffect,
|
||||||
|
useRef,
|
||||||
|
useState,
|
||||||
|
} from 'react';
|
||||||
import { NavLink, Outlet } from 'react-router-dom';
|
import { NavLink, Outlet } from 'react-router-dom';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
import { Button } from '@/components/ui/Button';
|
import { Button } from '@/components/ui/Button';
|
||||||
@@ -14,10 +22,16 @@ import {
|
|||||||
IconScrollText,
|
IconScrollText,
|
||||||
IconSettings,
|
IconSettings,
|
||||||
IconShield,
|
IconShield,
|
||||||
IconSlidersHorizontal
|
IconSlidersHorizontal,
|
||||||
} from '@/components/ui/icons';
|
} from '@/components/ui/icons';
|
||||||
import { INLINE_LOGO_JPEG } from '@/assets/logoInline';
|
import { INLINE_LOGO_JPEG } from '@/assets/logoInline';
|
||||||
import { useAuthStore, useConfigStore, useLanguageStore, useNotificationStore, useThemeStore } from '@/stores';
|
import {
|
||||||
|
useAuthStore,
|
||||||
|
useConfigStore,
|
||||||
|
useLanguageStore,
|
||||||
|
useNotificationStore,
|
||||||
|
useThemeStore,
|
||||||
|
} from '@/stores';
|
||||||
import { configApi, versionApi } from '@/services/api';
|
import { configApi, versionApi } from '@/services/api';
|
||||||
|
|
||||||
const sidebarIcons: Record<string, ReactNode> = {
|
const sidebarIcons: Record<string, ReactNode> = {
|
||||||
@@ -30,7 +44,7 @@ const sidebarIcons: Record<string, ReactNode> = {
|
|||||||
usage: <IconChartLine size={18} />,
|
usage: <IconChartLine size={18} />,
|
||||||
config: <IconSettings size={18} />,
|
config: <IconSettings size={18} />,
|
||||||
logs: <IconScrollText size={18} />,
|
logs: <IconScrollText size={18} />,
|
||||||
system: <IconInfo size={18} />
|
system: <IconInfo size={18} />,
|
||||||
};
|
};
|
||||||
|
|
||||||
// Header action icons - smaller size for header buttons
|
// Header action icons - smaller size for header buttons
|
||||||
@@ -44,7 +58,7 @@ const headerIconProps: SVGProps<SVGSVGElement> = {
|
|||||||
strokeLinecap: 'round',
|
strokeLinecap: 'round',
|
||||||
strokeLinejoin: 'round',
|
strokeLinejoin: 'round',
|
||||||
'aria-hidden': 'true',
|
'aria-hidden': 'true',
|
||||||
focusable: 'false'
|
focusable: 'false',
|
||||||
};
|
};
|
||||||
|
|
||||||
const headerIcons = {
|
const headerIcons = {
|
||||||
@@ -97,19 +111,38 @@ const headerIcons = {
|
|||||||
<path d="m19.07 4.93-1.41 1.41" />
|
<path d="m19.07 4.93-1.41 1.41" />
|
||||||
</svg>
|
</svg>
|
||||||
),
|
),
|
||||||
moon: (
|
moon: (
|
||||||
<svg {...headerIconProps}>
|
<svg {...headerIconProps}>
|
||||||
<path d="M12 3a6 6 0 0 0 9 9 9 9 0 1 1-9-9z" />
|
<path d="M12 3a6 6 0 0 0 9 9 9 9 0 1 1-9-9z" />
|
||||||
</svg>
|
</svg>
|
||||||
),
|
),
|
||||||
logout: (
|
autoTheme: (
|
||||||
<svg {...headerIconProps}>
|
<svg {...headerIconProps}>
|
||||||
<path d="M9 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h4" />
|
<defs>
|
||||||
<path d="m16 17 5-5-5-5" />
|
<clipPath id="mainLayoutAutoThemeSunLeftHalf">
|
||||||
<path d="M21 12H9" />
|
<rect x="0" y="0" width="12" height="24" />
|
||||||
</svg>
|
</clipPath>
|
||||||
)
|
</defs>
|
||||||
};
|
<circle cx="12" cy="12" r="4" />
|
||||||
|
<circle cx="12" cy="12" r="4" clipPath="url(#mainLayoutAutoThemeSunLeftHalf)" fill="currentColor" />
|
||||||
|
<path d="M12 2v2" />
|
||||||
|
<path d="M12 20v2" />
|
||||||
|
<path d="M4.93 4.93l1.41 1.41" />
|
||||||
|
<path d="M17.66 17.66l1.41 1.41" />
|
||||||
|
<path d="M2 12h2" />
|
||||||
|
<path d="M20 12h2" />
|
||||||
|
<path d="M6.34 17.66l-1.41 1.41" />
|
||||||
|
<path d="M19.07 4.93l-1.41 1.41" />
|
||||||
|
</svg>
|
||||||
|
),
|
||||||
|
logout: (
|
||||||
|
<svg {...headerIconProps}>
|
||||||
|
<path d="M9 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h4" />
|
||||||
|
<path d="m16 17 5-5-5-5" />
|
||||||
|
<path d="M21 12H9" />
|
||||||
|
</svg>
|
||||||
|
),
|
||||||
|
};
|
||||||
|
|
||||||
const parseVersionSegments = (version?: string | null) => {
|
const parseVersionSegments = (version?: string | null) => {
|
||||||
if (!version) return null;
|
if (!version) return null;
|
||||||
@@ -153,7 +186,7 @@ export function MainLayout() {
|
|||||||
const updateConfigValue = useConfigStore((state) => state.updateConfigValue);
|
const updateConfigValue = useConfigStore((state) => state.updateConfigValue);
|
||||||
|
|
||||||
const theme = useThemeStore((state) => state.theme);
|
const theme = useThemeStore((state) => state.theme);
|
||||||
const toggleTheme = useThemeStore((state) => state.toggleTheme);
|
const cycleTheme = useThemeStore((state) => state.cycleTheme);
|
||||||
const toggleLanguage = useLanguageStore((state) => state.toggleLanguage);
|
const toggleLanguage = useLanguageStore((state) => state.toggleLanguage);
|
||||||
|
|
||||||
const [sidebarOpen, setSidebarOpen] = useState(false);
|
const [sidebarOpen, setSidebarOpen] = useState(false);
|
||||||
@@ -187,7 +220,9 @@ export function MainLayout() {
|
|||||||
updateHeaderHeight();
|
updateHeaderHeight();
|
||||||
|
|
||||||
const resizeObserver =
|
const resizeObserver =
|
||||||
typeof ResizeObserver !== 'undefined' && headerRef.current ? new ResizeObserver(updateHeaderHeight) : null;
|
typeof ResizeObserver !== 'undefined' && headerRef.current
|
||||||
|
? new ResizeObserver(updateHeaderHeight)
|
||||||
|
: null;
|
||||||
if (resizeObserver && headerRef.current) {
|
if (resizeObserver && headerRef.current) {
|
||||||
resizeObserver.observe(headerRef.current);
|
resizeObserver.observe(headerRef.current);
|
||||||
}
|
}
|
||||||
@@ -320,8 +355,10 @@ export function MainLayout() {
|
|||||||
{ path: '/oauth', label: t('nav.oauth', { defaultValue: 'OAuth' }), icon: sidebarIcons.oauth },
|
{ path: '/oauth', label: t('nav.oauth', { defaultValue: 'OAuth' }), icon: sidebarIcons.oauth },
|
||||||
{ path: '/usage', label: t('nav.usage_stats'), icon: sidebarIcons.usage },
|
{ path: '/usage', label: t('nav.usage_stats'), icon: sidebarIcons.usage },
|
||||||
{ path: '/config', label: t('nav.config_management'), icon: sidebarIcons.config },
|
{ path: '/config', label: t('nav.config_management'), icon: sidebarIcons.config },
|
||||||
...(config?.loggingToFile ? [{ path: '/logs', label: t('nav.logs'), icon: sidebarIcons.logs }] : []),
|
...(config?.loggingToFile
|
||||||
{ path: '/system', label: t('nav.system_info'), icon: sidebarIcons.system }
|
? [{ path: '/logs', label: t('nav.logs'), icon: sidebarIcons.logs }]
|
||||||
|
: []),
|
||||||
|
{ path: '/system', label: t('nav.system_info'), icon: sidebarIcons.system },
|
||||||
];
|
];
|
||||||
|
|
||||||
const handleRefreshAll = async () => {
|
const handleRefreshAll = async () => {
|
||||||
@@ -370,7 +407,11 @@ export function MainLayout() {
|
|||||||
<button
|
<button
|
||||||
className="sidebar-toggle-header"
|
className="sidebar-toggle-header"
|
||||||
onClick={() => setSidebarCollapsed((prev) => !prev)}
|
onClick={() => setSidebarCollapsed((prev) => !prev)}
|
||||||
title={sidebarCollapsed ? t('sidebar.expand', { defaultValue: '展开' }) : t('sidebar.collapse', { defaultValue: '收起' })}
|
title={
|
||||||
|
sidebarCollapsed
|
||||||
|
? t('sidebar.expand', { defaultValue: '展开' })
|
||||||
|
: t('sidebar.collapse', { defaultValue: '收起' })
|
||||||
|
}
|
||||||
>
|
>
|
||||||
{sidebarCollapsed ? headerIcons.chevronRight : headerIcons.chevronLeft}
|
{sidebarCollapsed ? headerIcons.chevronRight : headerIcons.chevronLeft}
|
||||||
</button>
|
</button>
|
||||||
@@ -400,20 +441,40 @@ export function MainLayout() {
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="header-actions">
|
<div className="header-actions">
|
||||||
<Button className="mobile-menu-btn" variant="ghost" size="sm" onClick={() => setSidebarOpen((prev) => !prev)}>
|
<Button
|
||||||
|
className="mobile-menu-btn"
|
||||||
|
variant="ghost"
|
||||||
|
size="sm"
|
||||||
|
onClick={() => setSidebarOpen((prev) => !prev)}
|
||||||
|
>
|
||||||
{headerIcons.menu}
|
{headerIcons.menu}
|
||||||
</Button>
|
</Button>
|
||||||
<Button variant="ghost" size="sm" onClick={handleRefreshAll} title={t('header.refresh_all')}>
|
<Button
|
||||||
|
variant="ghost"
|
||||||
|
size="sm"
|
||||||
|
onClick={handleRefreshAll}
|
||||||
|
title={t('header.refresh_all')}
|
||||||
|
>
|
||||||
{headerIcons.refresh}
|
{headerIcons.refresh}
|
||||||
</Button>
|
</Button>
|
||||||
<Button variant="ghost" size="sm" onClick={handleVersionCheck} loading={checkingVersion} title={t('system_info.version_check_button')}>
|
<Button
|
||||||
|
variant="ghost"
|
||||||
|
size="sm"
|
||||||
|
onClick={handleVersionCheck}
|
||||||
|
loading={checkingVersion}
|
||||||
|
title={t('system_info.version_check_button')}
|
||||||
|
>
|
||||||
{headerIcons.update}
|
{headerIcons.update}
|
||||||
</Button>
|
</Button>
|
||||||
<Button variant="ghost" size="sm" onClick={toggleLanguage} title={t('language.switch')}>
|
<Button variant="ghost" size="sm" onClick={toggleLanguage} title={t('language.switch')}>
|
||||||
{headerIcons.language}
|
{headerIcons.language}
|
||||||
</Button>
|
</Button>
|
||||||
<Button variant="ghost" size="sm" onClick={toggleTheme} title={t('theme.switch')}>
|
<Button variant="ghost" size="sm" onClick={cycleTheme} title={t('theme.switch')}>
|
||||||
{theme === 'dark' ? headerIcons.sun : headerIcons.moon}
|
{theme === 'auto'
|
||||||
|
? headerIcons.autoTheme
|
||||||
|
: theme === 'dark'
|
||||||
|
? headerIcons.moon
|
||||||
|
: headerIcons.sun}
|
||||||
</Button>
|
</Button>
|
||||||
<Button variant="ghost" size="sm" onClick={logout} title={t('header.logout')}>
|
<Button variant="ghost" size="sm" onClick={logout} title={t('header.logout')}>
|
||||||
{headerIcons.logout}
|
{headerIcons.logout}
|
||||||
@@ -423,7 +484,9 @@ export function MainLayout() {
|
|||||||
</header>
|
</header>
|
||||||
|
|
||||||
<div className="main-body">
|
<div className="main-body">
|
||||||
<aside className={`sidebar ${sidebarOpen ? 'open' : ''} ${sidebarCollapsed ? 'collapsed' : ''}`}>
|
<aside
|
||||||
|
className={`sidebar ${sidebarOpen ? 'open' : ''} ${sidebarCollapsed ? 'collapsed' : ''}`}
|
||||||
|
>
|
||||||
<div className="nav-section">
|
<div className="nav-section">
|
||||||
{navItems.map((item) => (
|
{navItems.map((item) => (
|
||||||
<NavLink
|
<NavLink
|
||||||
@@ -454,7 +517,9 @@ export function MainLayout() {
|
|||||||
</span>
|
</span>
|
||||||
<span>
|
<span>
|
||||||
{t('footer.build_date')}:{' '}
|
{t('footer.build_date')}:{' '}
|
||||||
{serverBuildDate ? new Date(serverBuildDate).toLocaleString(i18n.language) : t('system_info.version_unknown')}
|
{serverBuildDate
|
||||||
|
? new Date(serverBuildDate).toLocaleString(i18n.language)
|
||||||
|
: t('system_info.version_unknown')}
|
||||||
</span>
|
</span>
|
||||||
</footer>
|
</footer>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -589,6 +589,7 @@
|
|||||||
"error_log_button": "Select Error Log",
|
"error_log_button": "Select Error Log",
|
||||||
"error_logs_modal_title": "Error Request Logs",
|
"error_logs_modal_title": "Error Request Logs",
|
||||||
"error_logs_description": "Pick an error request log file to download (only generated when request logging is off).",
|
"error_logs_description": "Pick an error request log file to download (only generated when request logging is off).",
|
||||||
|
"error_logs_request_log_enabled": "Request logging is enabled, so this list will always be empty. Disable request logging and refresh to view error logs.",
|
||||||
"error_logs_empty": "No error request log files found",
|
"error_logs_empty": "No error request log files found",
|
||||||
"error_logs_load_error": "Failed to load error log list",
|
"error_logs_load_error": "Failed to load error log list",
|
||||||
"error_logs_size": "Size",
|
"error_logs_size": "Size",
|
||||||
|
|||||||
@@ -589,6 +589,7 @@
|
|||||||
"error_log_button": "选择错误日志",
|
"error_log_button": "选择错误日志",
|
||||||
"error_logs_modal_title": "错误请求日志",
|
"error_logs_modal_title": "错误请求日志",
|
||||||
"error_logs_description": "请选择要下载的错误请求日志文件(仅在关闭请求日志时生成)。",
|
"error_logs_description": "请选择要下载的错误请求日志文件(仅在关闭请求日志时生成)。",
|
||||||
|
"error_logs_request_log_enabled": "当前已开启请求日志,按接口约定错误请求日志列表会始终为空。关闭请求日志后再刷新即可查看。",
|
||||||
"error_logs_empty": "暂无错误请求日志文件",
|
"error_logs_empty": "暂无错误请求日志文件",
|
||||||
"error_logs_load_error": "加载错误日志列表失败",
|
"error_logs_load_error": "加载错误日志列表失败",
|
||||||
"error_logs_size": "大小",
|
"error_logs_size": "大小",
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ import styles from './AuthFilesPage.module.scss';
|
|||||||
|
|
||||||
type ThemeColors = { bg: string; text: string; border?: string };
|
type ThemeColors = { bg: string; text: string; border?: string };
|
||||||
type TypeColorSet = { light: ThemeColors; dark?: ThemeColors };
|
type TypeColorSet = { light: ThemeColors; dark?: ThemeColors };
|
||||||
|
type ResolvedTheme = 'light' | 'dark';
|
||||||
|
|
||||||
// 标签类型颜色配置(对齐重构前 styles.css 的 file-type-badge 颜色)
|
// 标签类型颜色配置(对齐重构前 styles.css 的 file-type-badge 颜色)
|
||||||
const TYPE_COLORS: Record<string, TypeColorSet> = {
|
const TYPE_COLORS: Record<string, TypeColorSet> = {
|
||||||
@@ -129,7 +130,7 @@ export function AuthFilesPage() {
|
|||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const { showNotification } = useNotificationStore();
|
const { showNotification } = useNotificationStore();
|
||||||
const connectionStatus = useAuthStore((state) => state.connectionStatus);
|
const connectionStatus = useAuthStore((state) => state.connectionStatus);
|
||||||
const theme = useThemeStore((state) => state.theme);
|
const resolvedTheme: ResolvedTheme = useThemeStore((state) => state.resolvedTheme);
|
||||||
|
|
||||||
const [files, setFiles] = useState<AuthFileItem[]>([]);
|
const [files, setFiles] = useState<AuthFileItem[]>([]);
|
||||||
const [loading, setLoading] = useState(true);
|
const [loading, setLoading] = useState(true);
|
||||||
@@ -488,7 +489,7 @@ export function AuthFilesPage() {
|
|||||||
// 获取类型颜色
|
// 获取类型颜色
|
||||||
const getTypeColor = (type: string): ThemeColors => {
|
const getTypeColor = (type: string): ThemeColors => {
|
||||||
const set = TYPE_COLORS[type] || TYPE_COLORS.unknown;
|
const set = TYPE_COLORS[type] || TYPE_COLORS.unknown;
|
||||||
return theme === 'dark' && set.dark ? set.dark : set.light;
|
return resolvedTheme === 'dark' && set.dark ? set.dark : set.light;
|
||||||
};
|
};
|
||||||
|
|
||||||
// OAuth 排除相关方法
|
// OAuth 排除相关方法
|
||||||
@@ -547,7 +548,7 @@ export function AuthFilesPage() {
|
|||||||
{existingTypes.map((type) => {
|
{existingTypes.map((type) => {
|
||||||
const isActive = filter === type;
|
const isActive = filter === type;
|
||||||
const color = type === 'all' ? { bg: 'var(--bg-tertiary)', text: 'var(--text-primary)' } : getTypeColor(type);
|
const color = type === 'all' ? { bg: 'var(--bg-tertiary)', text: 'var(--text-primary)' } : getTypeColor(type);
|
||||||
const activeTextColor = theme === 'dark' ? '#111827' : '#fff';
|
const activeTextColor = resolvedTheme === 'dark' ? '#111827' : '#fff';
|
||||||
return (
|
return (
|
||||||
<button
|
<button
|
||||||
key={type}
|
key={type}
|
||||||
|
|||||||
@@ -134,8 +134,8 @@
|
|||||||
|
|
||||||
.editorWrapper {
|
.editorWrapper {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
flex: 1;
|
flex: 0 0 auto;
|
||||||
min-height: 200px;
|
height: 480px;
|
||||||
border: 1px solid var(--border-color);
|
border: 1px solid var(--border-color);
|
||||||
border-radius: $radius-lg;
|
border-radius: $radius-lg;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
@@ -238,3 +238,26 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@media (max-height: 820px) {
|
||||||
|
.pageTitle {
|
||||||
|
font-size: 24px;
|
||||||
|
margin-bottom: $spacing-sm;
|
||||||
|
}
|
||||||
|
|
||||||
|
.description {
|
||||||
|
margin-bottom: $spacing-lg;
|
||||||
|
}
|
||||||
|
|
||||||
|
.content {
|
||||||
|
gap: $spacing-md;
|
||||||
|
}
|
||||||
|
|
||||||
|
.configCard {
|
||||||
|
padding: $spacing-md;
|
||||||
|
}
|
||||||
|
|
||||||
|
.editorWrapper {
|
||||||
|
height: 360px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ export function ConfigPage() {
|
|||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const { showNotification } = useNotificationStore();
|
const { showNotification } = useNotificationStore();
|
||||||
const connectionStatus = useAuthStore((state) => state.connectionStatus);
|
const connectionStatus = useAuthStore((state) => state.connectionStatus);
|
||||||
const theme = useThemeStore((state) => state.theme);
|
const resolvedTheme = useThemeStore((state) => state.resolvedTheme);
|
||||||
|
|
||||||
const [content, setContent] = useState('');
|
const [content, setContent] = useState('');
|
||||||
const [loading, setLoading] = useState(true);
|
const [loading, setLoading] = useState(true);
|
||||||
@@ -289,7 +289,7 @@ export function ConfigPage() {
|
|||||||
value={content}
|
value={content}
|
||||||
onChange={handleChange}
|
onChange={handleChange}
|
||||||
extensions={extensions}
|
extensions={extensions}
|
||||||
theme={theme === 'dark' ? 'dark' : 'light'}
|
theme={resolvedTheme}
|
||||||
editable={!disableControls && !loading}
|
editable={!disableControls && !loading}
|
||||||
placeholder={t('config_management.editor_placeholder')}
|
placeholder={t('config_management.editor_placeholder')}
|
||||||
height="100%"
|
height="100%"
|
||||||
|
|||||||
@@ -161,8 +161,8 @@
|
|||||||
background: var(--bg-secondary);
|
background: var(--bg-secondary);
|
||||||
border: 1px solid var(--border-color);
|
border: 1px solid var(--border-color);
|
||||||
border-radius: $radius-md;
|
border-radius: $radius-md;
|
||||||
flex: 1;
|
flex: 0 0 auto;
|
||||||
min-height: 200px;
|
height: 480px;
|
||||||
overflow: auto;
|
overflow: auto;
|
||||||
position: relative;
|
position: relative;
|
||||||
-webkit-overflow-scrolling: touch;
|
-webkit-overflow-scrolling: touch;
|
||||||
@@ -170,6 +170,13 @@
|
|||||||
overscroll-behavior: contain;
|
overscroll-behavior: contain;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.errorPanel {
|
||||||
|
height: 480px;
|
||||||
|
overflow: auto;
|
||||||
|
-webkit-overflow-scrolling: touch;
|
||||||
|
overscroll-behavior: contain;
|
||||||
|
}
|
||||||
|
|
||||||
.loadMoreBanner {
|
.loadMoreBanner {
|
||||||
position: sticky;
|
position: sticky;
|
||||||
top: 0;
|
top: 0;
|
||||||
@@ -371,3 +378,34 @@
|
|||||||
color: var(--text-secondary);
|
color: var(--text-secondary);
|
||||||
word-break: break-word;
|
word-break: break-word;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@media (max-height: 820px) {
|
||||||
|
.pageTitle {
|
||||||
|
font-size: 24px;
|
||||||
|
margin-bottom: $spacing-md;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tabBar {
|
||||||
|
margin-bottom: $spacing-md;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tabItem {
|
||||||
|
padding: 10px 16px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.content {
|
||||||
|
gap: $spacing-md;
|
||||||
|
}
|
||||||
|
|
||||||
|
.logCard {
|
||||||
|
padding: $spacing-md;
|
||||||
|
}
|
||||||
|
|
||||||
|
.logPanel {
|
||||||
|
height: 360px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.errorPanel {
|
||||||
|
height: 360px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ import {
|
|||||||
IconTrash2,
|
IconTrash2,
|
||||||
IconX,
|
IconX,
|
||||||
} from '@/components/ui/icons';
|
} from '@/components/ui/icons';
|
||||||
import { useNotificationStore, useAuthStore } from '@/stores';
|
import { useAuthStore, useConfigStore, useNotificationStore } from '@/stores';
|
||||||
import { logsApi } from '@/services/api/logs';
|
import { logsApi } from '@/services/api/logs';
|
||||||
import { MANAGEMENT_API_PREFIX } from '@/utils/constants';
|
import { MANAGEMENT_API_PREFIX } from '@/utils/constants';
|
||||||
import { formatUnixTimestamp } from '@/utils/format';
|
import { formatUnixTimestamp } from '@/utils/format';
|
||||||
@@ -361,6 +361,7 @@ export function LogsPage() {
|
|||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const { showNotification } = useNotificationStore();
|
const { showNotification } = useNotificationStore();
|
||||||
const connectionStatus = useAuthStore((state) => state.connectionStatus);
|
const connectionStatus = useAuthStore((state) => state.connectionStatus);
|
||||||
|
const requestLogEnabled = useConfigStore((state) => state.config?.requestLog ?? false);
|
||||||
|
|
||||||
const [activeTab, setActiveTab] = useState<TabType>('logs');
|
const [activeTab, setActiveTab] = useState<TabType>('logs');
|
||||||
const [logState, setLogState] = useState<LogState>({ buffer: [], visibleFrom: 0 });
|
const [logState, setLogState] = useState<LogState>({ buffer: [], visibleFrom: 0 });
|
||||||
@@ -372,6 +373,7 @@ export function LogsPage() {
|
|||||||
const [hideManagementLogs, setHideManagementLogs] = useState(false);
|
const [hideManagementLogs, setHideManagementLogs] = useState(false);
|
||||||
const [errorLogs, setErrorLogs] = useState<ErrorLogItem[]>([]);
|
const [errorLogs, setErrorLogs] = useState<ErrorLogItem[]>([]);
|
||||||
const [loadingErrors, setLoadingErrors] = useState(false);
|
const [loadingErrors, setLoadingErrors] = useState(false);
|
||||||
|
const [errorLogsError, setErrorLogsError] = useState('');
|
||||||
|
|
||||||
const logViewerRef = useRef<HTMLDivElement | null>(null);
|
const logViewerRef = useRef<HTMLDivElement | null>(null);
|
||||||
const pendingScrollToBottomRef = useRef(false);
|
const pendingScrollToBottomRef = useRef(false);
|
||||||
@@ -488,14 +490,18 @@ export function LogsPage() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
setLoadingErrors(true);
|
setLoadingErrors(true);
|
||||||
|
setErrorLogsError('');
|
||||||
try {
|
try {
|
||||||
const res = await logsApi.fetchErrorLogs();
|
const res = await logsApi.fetchErrorLogs();
|
||||||
// API 返回 { files: [...] }
|
// API 返回 { files: [...] }
|
||||||
setErrorLogs(Array.isArray(res.files) ? res.files : []);
|
setErrorLogs(Array.isArray(res.files) ? res.files : []);
|
||||||
} catch (err: unknown) {
|
} catch (err: unknown) {
|
||||||
console.error('Failed to load error logs:', err);
|
console.error('Failed to load error logs:', err);
|
||||||
// 静默失败,不影响主日志显示
|
|
||||||
setErrorLogs([]);
|
setErrorLogs([]);
|
||||||
|
const message = getErrorMessage(err);
|
||||||
|
setErrorLogsError(
|
||||||
|
message ? `${t('logs.error_logs_load_error')}: ${message}` : t('logs.error_logs_load_error')
|
||||||
|
);
|
||||||
} finally {
|
} finally {
|
||||||
setLoadingErrors(false);
|
setLoadingErrors(false);
|
||||||
}
|
}
|
||||||
@@ -525,11 +531,17 @@ export function LogsPage() {
|
|||||||
if (connectionStatus === 'connected') {
|
if (connectionStatus === 'connected') {
|
||||||
latestTimestampRef.current = 0;
|
latestTimestampRef.current = 0;
|
||||||
loadLogs(false);
|
loadLogs(false);
|
||||||
loadErrorLogs();
|
|
||||||
}
|
}
|
||||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
}, [connectionStatus]);
|
}, [connectionStatus]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (activeTab !== 'errors') return;
|
||||||
|
if (connectionStatus !== 'connected') return;
|
||||||
|
void loadErrorLogs();
|
||||||
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
|
}, [activeTab, connectionStatus, requestLogEnabled]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!autoRefresh || connectionStatus !== 'connected') {
|
if (!autoRefresh || connectionStatus !== 'connected') {
|
||||||
return;
|
return;
|
||||||
@@ -877,37 +889,60 @@ export function LogsPage() {
|
|||||||
{activeTab === 'errors' && (
|
{activeTab === 'errors' && (
|
||||||
<Card
|
<Card
|
||||||
extra={
|
extra={
|
||||||
<Button variant="secondary" size="sm" onClick={loadErrorLogs} loading={loadingErrors}>
|
<Button
|
||||||
|
variant="secondary"
|
||||||
|
size="sm"
|
||||||
|
onClick={loadErrorLogs}
|
||||||
|
loading={loadingErrors}
|
||||||
|
disabled={disableControls}
|
||||||
|
>
|
||||||
{t('common.refresh')}
|
{t('common.refresh')}
|
||||||
</Button>
|
</Button>
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
{errorLogs.length === 0 ? (
|
<div className="stack">
|
||||||
<div className="hint">{t('logs.error_logs_empty')}</div>
|
<div className="hint">{t('logs.error_logs_description')}</div>
|
||||||
) : (
|
|
||||||
<div className="item-list">
|
{requestLogEnabled && (
|
||||||
{errorLogs.map((item) => (
|
<div>
|
||||||
<div key={item.name} className="item-row">
|
<div className="status-badge warning">{t('logs.error_logs_request_log_enabled')}</div>
|
||||||
<div className="item-meta">
|
</div>
|
||||||
<div className="item-title">{item.name}</div>
|
)}
|
||||||
<div className="item-subtitle">
|
|
||||||
{item.size ? `${(item.size / 1024).toFixed(1)} KB` : ''}{' '}
|
{errorLogsError && <div className="error-box">{errorLogsError}</div>}
|
||||||
{item.modified ? formatUnixTimestamp(item.modified) : ''}
|
|
||||||
|
<div className={styles.errorPanel}>
|
||||||
|
{loadingErrors ? (
|
||||||
|
<div className="hint">{t('common.loading')}</div>
|
||||||
|
) : errorLogs.length === 0 ? (
|
||||||
|
<div className="hint">{t('logs.error_logs_empty')}</div>
|
||||||
|
) : (
|
||||||
|
<div className="item-list">
|
||||||
|
{errorLogs.map((item) => (
|
||||||
|
<div key={item.name} className="item-row">
|
||||||
|
<div className="item-meta">
|
||||||
|
<div className="item-title">{item.name}</div>
|
||||||
|
<div className="item-subtitle">
|
||||||
|
{item.size ? `${(item.size / 1024).toFixed(1)} KB` : ''}{' '}
|
||||||
|
{item.modified ? formatUnixTimestamp(item.modified) : ''}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div className="item-actions">
|
||||||
|
<Button
|
||||||
|
variant="secondary"
|
||||||
|
size="sm"
|
||||||
|
onClick={() => downloadErrorLog(item.name)}
|
||||||
|
disabled={disableControls}
|
||||||
|
>
|
||||||
|
{t('logs.error_logs_download')}
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
))}
|
||||||
<div className="item-actions">
|
|
||||||
<Button
|
|
||||||
variant="secondary"
|
|
||||||
size="sm"
|
|
||||||
onClick={() => downloadErrorLog(item.name)}
|
|
||||||
>
|
|
||||||
{t('logs.error_logs_download')}
|
|
||||||
</Button>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
))}
|
)}
|
||||||
</div>
|
</div>
|
||||||
)}
|
</div>
|
||||||
</Card>
|
</Card>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ const getIcon = (icon: string | { light: string; dark: string }, theme: 'light'
|
|||||||
export function OAuthPage() {
|
export function OAuthPage() {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const { showNotification } = useNotificationStore();
|
const { showNotification } = useNotificationStore();
|
||||||
const { theme } = useThemeStore();
|
const resolvedTheme = useThemeStore((state) => state.resolvedTheme);
|
||||||
const [states, setStates] = useState<Record<OAuthProvider, ProviderState>>({} as Record<OAuthProvider, ProviderState>);
|
const [states, setStates] = useState<Record<OAuthProvider, ProviderState>>({} as Record<OAuthProvider, ProviderState>);
|
||||||
const [iflowCookie, setIflowCookie] = useState<IFlowCookieState>({ cookie: '', loading: false });
|
const [iflowCookie, setIflowCookie] = useState<IFlowCookieState>({ cookie: '', loading: false });
|
||||||
const timers = useRef<Record<string, number>>({});
|
const timers = useRef<Record<string, number>>({});
|
||||||
@@ -229,7 +229,11 @@ export function OAuthPage() {
|
|||||||
<Card
|
<Card
|
||||||
title={
|
title={
|
||||||
<span className={styles.cardTitle}>
|
<span className={styles.cardTitle}>
|
||||||
<img src={getIcon(provider.icon, theme)} alt="" className={styles.cardTitleIcon} />
|
<img
|
||||||
|
src={getIcon(provider.icon, resolvedTheme)}
|
||||||
|
alt=""
|
||||||
|
className={styles.cardTitleIcon}
|
||||||
|
/>
|
||||||
{t(provider.titleKey)}
|
{t(provider.titleKey)}
|
||||||
</span>
|
</span>
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -64,8 +64,8 @@ interface UsagePayload {
|
|||||||
export function UsagePage() {
|
export function UsagePage() {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const isMobile = useMediaQuery('(max-width: 768px)');
|
const isMobile = useMediaQuery('(max-width: 768px)');
|
||||||
const theme = useThemeStore((state) => state.theme);
|
const resolvedTheme = useThemeStore((state) => state.resolvedTheme);
|
||||||
const isDark = theme === 'dark';
|
const isDark = resolvedTheme === 'dark';
|
||||||
|
|
||||||
const [usage, setUsage] = useState<UsagePayload | null>(null);
|
const [usage, setUsage] = useState<UsagePayload | null>(null);
|
||||||
const [loading, setLoading] = useState(true);
|
const [loading, setLoading] = useState(true);
|
||||||
|
|||||||
@@ -8,63 +8,79 @@ import { persist } from 'zustand/middleware';
|
|||||||
import type { Theme } from '@/types';
|
import type { Theme } from '@/types';
|
||||||
import { STORAGE_KEY_THEME } from '@/utils/constants';
|
import { STORAGE_KEY_THEME } from '@/utils/constants';
|
||||||
|
|
||||||
|
type ResolvedTheme = 'light' | 'dark';
|
||||||
|
|
||||||
interface ThemeState {
|
interface ThemeState {
|
||||||
theme: Theme;
|
theme: Theme;
|
||||||
|
resolvedTheme: ResolvedTheme;
|
||||||
setTheme: (theme: Theme) => void;
|
setTheme: (theme: Theme) => void;
|
||||||
toggleTheme: () => void;
|
cycleTheme: () => void;
|
||||||
initializeTheme: () => void;
|
initializeTheme: () => () => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const getSystemTheme = (): ResolvedTheme => {
|
||||||
|
if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) {
|
||||||
|
return 'dark';
|
||||||
|
}
|
||||||
|
return 'light';
|
||||||
|
};
|
||||||
|
|
||||||
|
const applyTheme = (resolved: ResolvedTheme) => {
|
||||||
|
if (resolved === 'dark') {
|
||||||
|
document.documentElement.setAttribute('data-theme', 'dark');
|
||||||
|
} else {
|
||||||
|
document.documentElement.removeAttribute('data-theme');
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
export const useThemeStore = create<ThemeState>()(
|
export const useThemeStore = create<ThemeState>()(
|
||||||
persist(
|
persist(
|
||||||
(set, get) => ({
|
(set, get) => ({
|
||||||
theme: 'light',
|
theme: 'auto',
|
||||||
|
resolvedTheme: 'light',
|
||||||
|
|
||||||
setTheme: (theme) => {
|
setTheme: (theme) => {
|
||||||
// 应用主题到 DOM
|
const resolved: ResolvedTheme = theme === 'auto' ? getSystemTheme() : theme;
|
||||||
if (theme === 'dark') {
|
applyTheme(resolved);
|
||||||
document.documentElement.setAttribute('data-theme', 'dark');
|
set({ theme, resolvedTheme: resolved });
|
||||||
} else {
|
|
||||||
document.documentElement.removeAttribute('data-theme');
|
|
||||||
}
|
|
||||||
|
|
||||||
set({ theme });
|
|
||||||
},
|
},
|
||||||
|
|
||||||
toggleTheme: () => {
|
cycleTheme: () => {
|
||||||
const { theme, setTheme } = get();
|
const { theme, setTheme } = get();
|
||||||
const newTheme: Theme = theme === 'light' ? 'dark' : 'light';
|
const order: Theme[] = ['light', 'dark', 'auto'];
|
||||||
setTheme(newTheme);
|
const currentIndex = order.indexOf(theme);
|
||||||
|
const nextTheme = order[(currentIndex + 1) % order.length];
|
||||||
|
setTheme(nextTheme);
|
||||||
},
|
},
|
||||||
|
|
||||||
initializeTheme: () => {
|
initializeTheme: () => {
|
||||||
const { theme, setTheme } = get();
|
const { theme, setTheme } = get();
|
||||||
|
|
||||||
// 检查系统偏好
|
|
||||||
if (
|
|
||||||
!localStorage.getItem(STORAGE_KEY_THEME) &&
|
|
||||||
window.matchMedia &&
|
|
||||||
window.matchMedia('(prefers-color-scheme: dark)').matches
|
|
||||||
) {
|
|
||||||
setTheme('dark');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 应用已保存的主题
|
// 应用已保存的主题
|
||||||
setTheme(theme);
|
setTheme(theme);
|
||||||
|
|
||||||
// 监听系统主题变化(仅在用户未手动设置时)
|
// 监听系统主题变化(仅在 auto 模式下生效)
|
||||||
if (window.matchMedia) {
|
if (!window.matchMedia) {
|
||||||
window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', (e) => {
|
return () => {};
|
||||||
if (!localStorage.getItem(STORAGE_KEY_THEME)) {
|
|
||||||
setTheme(e.matches ? 'dark' : 'light');
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
const mediaQuery = window.matchMedia('(prefers-color-scheme: dark)');
|
||||||
|
const listener = () => {
|
||||||
|
const { theme: currentTheme } = get();
|
||||||
|
if (currentTheme === 'auto') {
|
||||||
|
const resolved = getSystemTheme();
|
||||||
|
applyTheme(resolved);
|
||||||
|
set({ resolvedTheme: resolved });
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
mediaQuery.addEventListener('change', listener);
|
||||||
|
|
||||||
|
return () => mediaQuery.removeEventListener('change', listener);
|
||||||
|
},
|
||||||
}),
|
}),
|
||||||
{
|
{
|
||||||
name: STORAGE_KEY_THEME
|
name: STORAGE_KEY_THEME,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -331,13 +331,11 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.main-content {
|
.main-content {
|
||||||
flex: 1;
|
flex: 0 0 auto;
|
||||||
padding: $spacing-lg;
|
padding: $spacing-lg;
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
gap: $spacing-lg;
|
gap: $spacing-lg;
|
||||||
min-height: 0;
|
|
||||||
overflow-y: auto;
|
|
||||||
overflow-x: hidden;
|
overflow-x: hidden;
|
||||||
|
|
||||||
@media (max-width: $breakpoint-mobile) {
|
@media (max-width: $breakpoint-mobile) {
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
* 通用类型定义
|
* 通用类型定义
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export type Theme = 'light' | 'dark';
|
export type Theme = 'light' | 'dark' | 'auto';
|
||||||
|
|
||||||
export type Language = 'zh-CN' | 'en';
|
export type Language = 'zh-CN' | 'en';
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user