Преглед изворни кода

fix: 增加 API 原始数据诊断,对比 store 中的 rank

排序后先打印 GET /menu/routes 的原始 rank,
再打印 wholeMenus 中经过 ascending 处理后的 rank,
帮助定位 rank 丢失发生在哪个环节。

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
skyline пре 1 недеља
родитељ
комит
fec4f50e7a
1 измењених фајлова са 9 додато и 6 уклоњено
  1. 9 6
      haha-admin-web/src/views/system/menu/utils/hook.tsx

+ 9 - 6
haha-admin-web/src/views/system/menu/utils/hook.tsx

@@ -2,6 +2,7 @@ import editForm from "../form.vue";
 import { handleTree } from "@/utils/tree";
 import { message } from "@/utils/message";
 import { getMenuList, createMenu, updateMenu, deleteMenuApi, updateMenuSort } from "@/api/system";
+import { getAsyncRoutes } from "@/api/routes";
 import { usePermissionStoreHook } from "@/store/modules/permission";
 import { transformI18n } from "@/plugins/i18n";
 import { addDialog } from "@/components/ReDialog";
@@ -308,16 +309,18 @@ export function useMenu() {
           message("排序更新成功", { type: "success" });
           // 刷新侧边栏路由顺序
           try {
+            // 先直接查 API 返回的原始数据
+            const routesRes = await getAsyncRoutes();
+            const apiRanks = (routesRes as any).data?.map((m: any) => `${m.meta?.title}(${m.meta?.rank},${m.path})`);
+            console.log("[menu-sort] API 原始一级菜单:", apiRanks);
+
             await initRouter();
             await nextTick();
-            // 诊断:输出所有一级菜单的路径、标题和 rank
+            // 诊断:输出 store 中的一级菜单
             const topMenus = usePermissionStoreHook().wholeMenus
               .map((m: any) => `${m.meta?.title || "?"}(${m.meta?.rank},${m.path})`);
-            console.log("[menu-sort] wholeMenus 一级菜单:", topMenus);
-            // 检查重复路径
-            const paths = usePermissionStoreHook().wholeMenus.map((m: any) => m.path);
-            const dupes = paths.filter((p, i) => paths.indexOf(p) !== i);
-            if (dupes.length > 0) console.warn("[menu-sort] 重复路径:", dupes);
+            console.log("[menu-sort] store中一级菜单:", topMenus);
+
             emitter.emit("menuRefresh");
           } catch (e) {
             console.error("侧边栏路由刷新失败:", e);