登录后默认进入总体概况页

- 将 Zustand 默认 activeModule 从 workspace 调整为 dashboard,登录后默认展示总体概况页。

- 同步测试 resetStore 的默认模块,避免测试环境与真实默认入口不一致。

- 补充 useStore 默认模块回归测试,固定 dashboard 初始入口行为。

- 更新 AGENTS 和前端实现文档,记录登录后的默认模块。
This commit is contained in:
2026-05-04 03:19:12 +08:00
parent 628bce23e0
commit f558f3b3c7
5 changed files with 8 additions and 3 deletions

View File

@@ -181,7 +181,7 @@ uvicorn main:app --host 0.0.0.0 --port 8000 --reload
- 单页应用,无路由库;模块切换由 `useStore().activeModule` 控制。 - 单页应用,无路由库;模块切换由 `useStore().activeModule` 控制。
- 模块值包括:`dashboard``projects``ai``workspace``templates` - 模块值包括:`dashboard``projects``ai``workspace``templates`
- 默认模块是 `workspace` - 默认模块是 `dashboard`,用户登录后默认进入“总体概况”页
- 未登录时渲染 `Login` - 未登录时渲染 `Login`
- 登录成功后后端返回签名 JWTtoken 写入 `localStorage`Axios request interceptor 会附加 `Authorization: Bearer <token>` - 登录成功后后端返回签名 JWTtoken 写入 `localStorage`Axios request interceptor 会附加 `Authorization: Bearer <token>`
- `App.tsx` 在已有 token 或登录成功后调用 `/api/auth/me` 恢复当前用户,再调用 `getProjects()` 初始化当前用户项目列表。 - `App.tsx` 在已有 token 或登录成功后调用 `/api/auth/me` 恢复当前用户,再调用 `getProjects()` 初始化当前用户项目列表。

View File

@@ -29,6 +29,7 @@
## 前端模块切换 ## 前端模块切换
`App.tsx` 使用 Zustand 中的 `activeModule` 做模块切换,没有使用路由库。 `App.tsx` 使用 Zustand 中的 `activeModule` 做模块切换,没有使用路由库。
`useStore` 默认 `activeModule``dashboard`,因此用户登录后默认进入“总体概况”页。
| activeModule | 组件 | 页面 | | activeModule | 组件 | 页面 |
|--------------|------|------| |--------------|------|------|

View File

@@ -7,6 +7,10 @@ describe('useStore', () => {
resetStore(); resetStore();
}); });
it('defaults to the dashboard module after login state is initialized', () => {
expect(useStore.getState().activeModule).toBe('dashboard');
});
it('stores and clears auth state with localStorage', () => { it('stores and clears auth state with localStorage', () => {
useStore.getState().login('token-1', { id: 1, username: 'admin', role: 'admin' }); useStore.getState().login('token-1', { id: 1, username: 'admin', role: 'admin' });

View File

@@ -233,7 +233,7 @@ export const useStore = create<AppState>((set) => ({
})), })),
// Workspace // Workspace
activeModule: 'workspace', activeModule: 'dashboard',
activeTool: 'move', activeTool: 'move',
aiModel: DEFAULT_AI_MODEL_ID, aiModel: DEFAULT_AI_MODEL_ID,
frames: [], frames: [],

View File

@@ -7,7 +7,7 @@ export function resetStore() {
currentUser: null, currentUser: null,
projects: [], projects: [],
currentProject: null, currentProject: null,
activeModule: 'workspace', activeModule: 'dashboard',
activeTool: 'move', activeTool: 'move',
aiModel: DEFAULT_AI_MODEL_ID, aiModel: DEFAULT_AI_MODEL_ID,
frames: [], frames: [],