浏览代码

fix: 菜单拖拽排序后自动刷新侧边栏路由顺序

排序成功后调用 initRouter() 完整重建路由和侧边栏菜单,
确保左侧菜单即时反映排序变动。

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
skyline 1 周之前
父节点
当前提交
b5a8483fc0

+ 7 - 0
haha-admin-web/src/views/system/menu/utils/hook.tsx

@@ -8,6 +8,7 @@ import { reactive, ref, onMounted, h } from "vue";
 import type { FormItemProps } from "../utils/types";
 import { useRenderIcon } from "@/components/ReIcon/src/hooks";
 import { cloneDeep, isAllEmpty, deviceDetection } from "@pureadmin/utils";
+import { initRouter } from "@/router/utils";
 import Sortable from "sortablejs";
 
 export function useMenu() {
@@ -303,6 +304,12 @@ export function useMenu() {
         try {
           await updateMenuSort(sortData);
           message("排序更新成功", { type: "success" });
+          // 刷新侧边栏路由顺序
+          try {
+            await initRouter();
+          } catch (e) {
+            console.error("侧边栏路由刷新失败:", e);
+          }
         } catch {
           message("排序更新失败", { type: "error" });
         }

+ 1 - 1
haha-admin-web/src/views/system/role/utils/hook.tsx

@@ -42,7 +42,7 @@ export function useRole() {
   const isDataLoaded = ref(false);
   const { switchStyle } = usePublicHooks();
   const menuTree = ref([]);
-  const checkedMenuIds = ref<number[]>([]);
+  const checkedMenuIds = ref<string[]>([]);
   const roleMenuTreeRef = ref();
   const pagination = reactive<PaginationProps>({
     total: 0,