Files
xuanzhi-service/web/.ai-specs/coding-specs/pinia-store-boundary.md

25 lines
1.1 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# pinia-store-boundary
## 适用范围
- 涉及新增 store、修改共享状态、决定状态是否全局化时必读。
## 边界规则
- `src/pinia/modules` 只承载跨页面共享状态,不承载单页面临时表单态和局部弹窗态。
- store 可以协调 API 调用、登录态恢复、路由初始化和全局字典,但不要承载组件展示逻辑。
- 页面私有状态优先留在页面;仅在多个页面或守卫链路复用时再进入 store。
- 插件若只有单页临时状态,优先使用页面局部状态或 plugin 内部 composable。
## 联动检查
-`user` store同步检查 token、用户信息、401 清理和登录跳转。
-`router` store同步检查动态路由注册、默认首页、keep-alive 和菜单进入。
-`dictionary` store同步检查依赖字典的页面和表单。
## 常见错误
- 把列表筛选条件、弹窗开关、局部 loading 全部塞进全局 store。
- 新增 store 字段时没有同步补齐初始化、清理和持久化行为。
- store 内直接依赖页面组件实例或 DOM。