mirror of
https://github.com/flipped-aurora/gin-vue-admin.git
synced 2026-10-10 03:14:13 +00:00
* feat: 调整AI工作模式,更符合harness基准 * feat: 添加BusinessDB字段到PluginInitializeGorm结构体,并增加相关测试用例 * [middleware/jwt.go]: fix #2192 issues bug * docs: add auto plugin design spec * chore: ignore worktrees directory * feat: 调整代码辅助能力至插件 * feat: 添加警告条组件,提示授权用户访问限制 * fix: 修正商业用途版权声明链接 * feat: 调整agent.md 更加节省token * fix: 修改casbin版本为v3 * feat: 更新JSONMap和JSONSlice类型,优化GORM数据类型处理 * feat: 添加数据库就绪通知机制,优化插件注册流程 * feat: 重构API路径和描述,优化代码生成器和模板配置分组 * feat: 优化 person 页面的 css 作用域限制 * feat: 更新 vite 至 vite8 * 新增:MCP工具为指定URL的角色ID授权 * fix: 增加文件名合法性检查,拒绝包含非法字符的文件写入 * chore: 更新CI配置,升级Node.js和Go版本,调整checkout和setup动作版本 * feat: 为数据库连接增加最大复用时间配置 * feat: 为各数据库连接配置增加最大连接生命周期设置 * feat: 更新插件注册逻辑并优化API和菜单组件的标签显示 * feat: 更新版本号至v2.9.2并添加新插件路径信息 --------- Co-authored-by: taincheng <zhangtc@gmail.com> Co-authored-by: Azir-11 <2075125282@qq.com> Co-authored-by: lanxi <1220lanxi@gmail.com>
1.6 KiB
1.6 KiB
Pinia 示例
这个文件负责什么
Pinia store 负责全局状态、异步动作和跨页面共享数据,不负责页面渲染细节。
什么时候应该这样写
- 用户信息、路由、字典、系统参数等共享状态
- 多页面都会用到的业务状态
- 需要统一缓存或集中副作用的场景
推荐写法示例
import { defineStore } from 'pinia'
import { ref, computed } from 'vue'
import { getOrderList } from '@/api/order'
export const useOrderStore = defineStore('order', () => {
const list = ref([])
const total = ref(0)
const loading = ref(false)
const hasData = computed(() => list.value.length > 0)
const fetchList = async (params) => {
loading.value = true
try {
const res = await getOrderList(params)
if (res.code === 0) {
list.value = res.data.list
total.value = res.data.total
}
return res
} finally {
loading.value = false
}
}
const reset = () => {
list.value = []
total.value = 0
}
return {
list,
total,
loading,
hasData,
fetchList,
reset
}
})
为什么这样写
ref + computed + async action是当前仓库里很自然的组织方式- 页面层拿 store 结果即可,不必重复写状态管理逻辑
- 把 loading 和 reset 一并收进 store,调用侧更干净
常见错误
- 把所有局部页面状态都塞进全局 store
- 在 store 里写大量 DOM 操作
- 不做 loading / reset 管理,导致页面状态混乱
真实参考文件
web/src/pinia/modules/user.jsweb/src/pinia/modules/router.jsweb/src/pinia/modules/dictionary.js