现象:审计日志里 logout 记录数恒为 0,退出动作完全不可见。
根因有两处,缺一不可:
1. 移动端(App)根本没有发起过上报
settings.vue 的 handleLogout 只做 removeStorageSync + reLaunch,
一个请求都没发。而 uni.reLaunch 会销毁页面上下文、直接掐断未完成的
uni.request —— 所以必须「先 await 上报、再清 token 与跳转」。
2. PC 端存在时序竞态
axios 的请求拦截器在微任务里执行、现读 localStorage 取 token;
而原实现同步清空 localStorage 并立刻 navigate,拦截器跑到时 token
已经没了 → 请求不带 Authorization → 后端只能记成「未认证」。
注:只改 AuthContext 不够,调用方 AdminLayout / ProfilePage 原来是
`logout(); navigate(...)`,不等就跳转照样会掐断请求 —— 三处都得改。
改动:
- 移动端 handleLogout 改 async,await post("/auth/logout") 后再清 token
- AuthContext.logout 改 async(类型同步为 () => Promise<void>),
先 await 上报再清 token;失败静默,绝不阻断退出
- AdminLayout / ProfilePage 两个调用点补 await
- 全部用 try-catch 兜住:断网/超时也照退不误(JWT 无状态,
服务端本就不需要它成功)
React + TypeScript + Vite
This template provides a minimal setup to get React working in Vite with HMR and some Oxlint rules.
Currently, two official plugins are available:
- @vitejs/plugin-react uses Oxc
- @vitejs/plugin-react-swc uses SWC
React Compiler
The React Compiler is not enabled on this template because of its impact on dev & build performances. To add it, see this documentation.
Expanding the Oxlint configuration
If you are developing a production application, we recommend enabling type-aware lint rules by installing oxlint-tsgolint and editing .oxlintrc.json:
{
"$schema": "./node_modules/oxlint/configuration_schema.json",
"plugins": ["react", "typescript", "oxc"],
"options": {
"typeAware": true
},
"rules": {
"react/rules-of-hooks": "error",
"react/only-export-components": ["warn", { "allowConstantExport": true }]
}
}
See the Oxlint rules documentation for the full list of rules and categories.