feat: 统一调试模块 debug.ts,VITE_DEBUG 环境变量控制调试面板显隐

- 新增 services/debug.ts: isDebug()/debugLog()/getDebugLogs()
- .env 中 VITE_DEBUG=true 开启调试,false 关闭
- LoginPage 使用 debugLog() 记录登录流程
- ProfilePage 通过 isDebug() 控制调试面板显隐
- .env.example 同步更新
This commit is contained in:
2026-05-27 20:19:12 +08:00
parent 27b58564e3
commit 150dafc72f
4 changed files with 77 additions and 12 deletions

View File

@@ -24,6 +24,7 @@ import { Button } from "../components/ui/button";
import { Card } from "../components/ui/card";
import { Badge } from "../components/ui/badge";
import { useUser, getPregnancyStage } from "../context/UserContext";
import { isDebug, getDebugLogs } from "../services/debug";
interface UserInfo {
name: string;
@@ -187,8 +188,23 @@ export function ProfilePage() {
</div>
);
// 🐞 调试面板(VITE_DEBUG=true 时显示)
const [debugLog] = useState<string[]>(() => isDebug() ? getDebugLogs() : []);
const [showDebug, setShowDebug] = useState(false);
return (
<div className="min-h-dvh bg-morandi-50">
<div className="min-h-dvh bg-morandi-50 pb-20">
{/* 🐞 调试面板 */}
{debugLog.length > 0 && (
<div className="bg-black/80 text-white text-xs font-mono p-3">
<button onClick={() => setShowDebug(!showDebug)} className="text-yellow-400 font-bold mb-1">
🐞 {showDebug ? '收起' : '展开'}调试日志 ({debugLog.length}条)
</button>
{showDebug && debugLog.map((line, i) => (
<div key={i} className="text-green-300 break-all">{line}</div>
))}
</div>
)}
{/* 顶部导航 */}
<div className="bg-white border-b border-gray-100 sticky top-0 z-10">
<div className="mx-auto px-4 py-4 flex items-center justify-between">