- 版本详情:关联需求Tab(从需求池添加已采纳需求/移除释放) - 版本详情:调研/产品方案/UI设计Tab(计划CRUD、完成提交成果、耗时统计) - 版本详情:超期校验(结束日期超版本截止需填写原因) - 版本详情:概览统计卡片(加班时长/排名/原因占比) - 数据串联:产品→项目→版本→需求→加班全链路贯通 - 版本管理:规划中版本可删除,删除释放关联需求 - 数据清理:仅保留翻台宝/值班,需求池10条值班待评审需求 - 修复:列表页overflow裁剪菜单问题(4个页面统一修复) - 新增:登录模块、AuthGuard、VersionPlan store Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
34 lines
900 B
TypeScript
34 lines
900 B
TypeScript
'use client';
|
|
|
|
import { useEffect, useState } from 'react';
|
|
import { usePathname, useRouter } from 'next/navigation';
|
|
import { useAuthStore } from '@/stores/useAuthStore';
|
|
|
|
export function AuthGuard({ children }: { children: React.ReactNode }) {
|
|
const pathname = usePathname();
|
|
const router = useRouter();
|
|
const { isAuthenticated, checkAuth } = useAuthStore();
|
|
const [checked, setChecked] = useState(false);
|
|
|
|
useEffect(() => {
|
|
checkAuth();
|
|
setChecked(true);
|
|
}, [checkAuth]);
|
|
|
|
useEffect(() => {
|
|
if (!checked) return;
|
|
if (!isAuthenticated && pathname !== '/login') {
|
|
router.replace('/login');
|
|
}
|
|
if (isAuthenticated && pathname === '/login') {
|
|
router.replace('/products');
|
|
}
|
|
}, [checked, isAuthenticated, pathname, router]);
|
|
|
|
if (!checked) return null;
|
|
|
|
if (!isAuthenticated && pathname !== '/login') return null;
|
|
|
|
return <>{children}</>;
|
|
}
|