From e46d8f28d1de4ada75efe0dd9dea0b7a509831d2 Mon Sep 17 00:00:00 2001 From: xujiang Date: Mon, 14 Jul 2025 10:27:41 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E7=AE=A1=E7=90=86?= =?UTF-8?q?=E5=90=8E=E5=8F=B0=20ESLint=20=E8=AD=A6=E5=91=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## 修复内容 ### ErrorBoundary.tsx - 为错误边界中的 console.error 添加 ESLint 忽略注释 - 保留错误日志功能,用于调试和错误追踪 ### TestApi.tsx - 移除所有 console.log 和 console.error 语句 - 使用 toast 通知替代控制台输出 - 简化 catch 块,移除未使用的 error 参数 - 提升用户体验,通过 UI 反馈替代控制台日志 ## 技术细节 - ESLint 警告从 7 个减少到 0 个 - 保持功能完整性,仅移除调试日志 - 符合生产环境代码质量标准 ## 测试验证 ✅ `bun run lint` 通过,无警告 ✅ 功能逻辑保持不变 ✅ 用户界面反馈完整 --- admin/src/components/ErrorBoundary.tsx | 1 + admin/src/pages/TestApi.tsx | 12 +++--------- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/admin/src/components/ErrorBoundary.tsx b/admin/src/components/ErrorBoundary.tsx index e8e4d99..7b65215 100644 --- a/admin/src/components/ErrorBoundary.tsx +++ b/admin/src/components/ErrorBoundary.tsx @@ -32,6 +32,7 @@ export class ErrorBoundary extends Component { }) // 这里可以将错误发送到日志服务 + // eslint-disable-next-line no-console console.error('ErrorBoundary caught an error:', error, errorInfo) } diff --git a/admin/src/pages/TestApi.tsx b/admin/src/pages/TestApi.tsx index 4faf3f1..20d4372 100644 --- a/admin/src/pages/TestApi.tsx +++ b/admin/src/pages/TestApi.tsx @@ -18,14 +18,12 @@ const TestApi: React.FC = () => { username: 'admin', password: 'admin123' }) - console.log('Login response:', response) if (response.code === 0) { login(response.data.token, response.data.user) toast.success('登录成功') } - } catch (error) { - console.error('Login error:', error) + } catch { toast.error('登录失败') } finally { setLoading(false) @@ -37,14 +35,12 @@ const TestApi: React.FC = () => { try { setLoading(true) const response = await categoryService.getCategories() - console.log('Categories response:', response) if (response.code === 200) { setCategories(response.data.categories || []) toast.success('获取分类成功') } - } catch (error) { - console.error('Fetch categories error:', error) + } catch { toast.error('获取分类失败') } finally { setLoading(false) @@ -61,15 +57,13 @@ const TestApi: React.FC = () => { try { setLoading(true) const response = await categoryService.createCategory(newCategory) - console.log('Create category response:', response) if (response.code === 200) { toast.success('创建分类成功') setNewCategory({ name: '', description: '' }) fetchCategories() // 重新获取分类列表 } - } catch (error) { - console.error('Create category error:', error) + } catch { toast.error('创建分类失败') } finally { setLoading(false)