This commit is contained in:
hero920103 committed 2026-11-14 07:54:01 +08:00
1 parent 4ab63e77ed
commit eb9b7beff5
16 files changed
+1031 -91

No files matched your search

+6 -3
View File
@@ -132,9 +132,11 @@ export const useMenuStore = defineStore('menu', () => {
// 用户登录,使用 getMenus 接口
res = await getMenus(userInfo.id);
// 检查响应格式
// 检查响应格式:HTTP 200 但 body 为空(后端/网关异常)会走到这里,
// 打印原始值便于区分「服务挂了」和「返回了空内容」
if (!res) {
throw new Error('获取菜单失败:服务器无响应');
console.error('菜单接口返回空响应:', { res, url: `/backend/menu/${userInfo.id}` });
throw new Error('获取菜单失败:接口返回空响应(后端服务或网关异常)');
}
// 检查后端返回的 code 字段
@@ -215,8 +217,9 @@ export const useMenuStore = defineStore('menu', () => {
};
// 刷新菜单(强制从 API 获取)
// 不预先清缓存:接口异常时 fetchMenus 还能回退到上一份菜单,避免整个应用没菜单可用;
// 请求成功后 saveToCache 会直接覆盖旧缓存。
const refreshMenus = async () => {
clearCache();
return await fetchMenus(true);
};