登录后默认进入总体概况页
- 将 Zustand 默认 activeModule 从 workspace 调整为 dashboard,登录后默认展示总体概况页。 - 同步测试 resetStore 的默认模块,避免测试环境与真实默认入口不一致。 - 补充 useStore 默认模块回归测试,固定 dashboard 初始入口行为。 - 更新 AGENTS 和前端实现文档,记录登录后的默认模块。
This commit is contained in:
@@ -181,7 +181,7 @@ uvicorn main:app --host 0.0.0.0 --port 8000 --reload
|
||||
|
||||
- 单页应用,无路由库;模块切换由 `useStore().activeModule` 控制。
|
||||
- 模块值包括:`dashboard`、`projects`、`ai`、`workspace`、`templates`。
|
||||
- 默认模块是 `workspace`。
|
||||
- 默认模块是 `dashboard`,用户登录后默认进入“总体概况”页。
|
||||
- 未登录时渲染 `Login`。
|
||||
- 登录成功后后端返回签名 JWT,token 写入 `localStorage`,Axios request interceptor 会附加 `Authorization: Bearer <token>`。
|
||||
- `App.tsx` 在已有 token 或登录成功后调用 `/api/auth/me` 恢复当前用户,再调用 `getProjects()` 初始化当前用户项目列表。
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
## 前端模块切换
|
||||
|
||||
`App.tsx` 使用 Zustand 中的 `activeModule` 做模块切换,没有使用路由库。
|
||||
`useStore` 默认 `activeModule` 为 `dashboard`,因此用户登录后默认进入“总体概况”页。
|
||||
|
||||
| activeModule | 组件 | 页面 |
|
||||
|--------------|------|------|
|
||||
|
||||
@@ -7,6 +7,10 @@ describe('useStore', () => {
|
||||
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', () => {
|
||||
useStore.getState().login('token-1', { id: 1, username: 'admin', role: 'admin' });
|
||||
|
||||
|
||||
@@ -233,7 +233,7 @@ export const useStore = create<AppState>((set) => ({
|
||||
})),
|
||||
|
||||
// Workspace
|
||||
activeModule: 'workspace',
|
||||
activeModule: 'dashboard',
|
||||
activeTool: 'move',
|
||||
aiModel: DEFAULT_AI_MODEL_ID,
|
||||
frames: [],
|
||||
|
||||
@@ -7,7 +7,7 @@ export function resetStore() {
|
||||
currentUser: null,
|
||||
projects: [],
|
||||
currentProject: null,
|
||||
activeModule: 'workspace',
|
||||
activeModule: 'dashboard',
|
||||
activeTool: 'move',
|
||||
aiModel: DEFAULT_AI_MODEL_ID,
|
||||
frames: [],
|
||||
|
||||
Reference in New Issue
Block a user