From 93393138afcda975703f8c89ae1702fb62502080 Mon Sep 17 00:00:00 2001
From: zhengyiming <540361168@qq.com>
Date: 星期二, 05 八月 2025 13:11:49 +0800
Subject: [PATCH] fix: 修改功能模块

---
 src/store/modules/permission.ts |   98 +++++++++++++++++++++++++------------------------
 1 files changed, 50 insertions(+), 48 deletions(-)

diff --git a/src/store/modules/permission.ts b/src/store/modules/permission.ts
index 2fc37a5..f3aa96d 100644
--- a/src/store/modules/permission.ts
+++ b/src/store/modules/permission.ts
@@ -3,7 +3,8 @@
 // import { RouteConfigs } from "@/layout/types";
 import { constantRoutes, Route } from '@/router';
 import { addAsyncRoutes, ascending } from '@/router/utils';
-import * as baseModuleServices from '@/services/api/BaseModule';
+import * as menuServices from '@/services/api/menu';
+import { myClient } from '@/constants/query';
 
 export interface PermissonState {
   routes: Route[];
@@ -27,13 +28,20 @@
     getModuleList() {
       return new Promise<Route[]>(async (resolve, reject) => {
         try {
-          // let res = await userApiClient.apiUserUserMenusGet();
-          // let userMenuList = res.data.data;
-          // let userInfo = rootGetters['userInfo'] as Getter['userInfo'];
-          const res = await baseModuleServices.getCurrentUserModuleList({
-            showLoading: false,
+          const params: API.APIgetMenusParams = {
+            userType: EnumUserType.Operation,
+            clientType: EnumClientType.PcWeb,
+          };
+          const res = await myClient.fetchQuery({
+            queryKey: ['menuServices/getMenus', params],
+            queryFn: async () => {
+              return await menuServices.getMenus(params, {
+                showLoading: false,
+              });
+            },
+            staleTime: Infinity,
           });
-          const accessedRoutes = ascending(addAsyncRoutes(formatModuleList(res, null))); // createAccessedRoutes(userMenuList, userInfo)
+          const accessedRoutes = ascending(addAsyncRoutes(formatModuleList(res))); // createAccessedRoutes(userMenuList, userInfo)
           //@ts-ignore
           accessedRoutes.push({ path: '/:pathMatch(.*)*', redirect: '/404', hidden: true });
 
@@ -58,47 +66,41 @@
   return usePermissionStore(store);
 }
 
-function formatModuleList(moduleList: API.ModuleDto[], parentId: string | null) {
-  const treeModuleList: Route[] = [];
-  if (moduleList.length > 0) {
-    moduleList.forEach((item) => {
-      if (item.parentId === parentId) {
-        const isRootModule = !item.parentId && item.isMenu === 1;
-        //@ts-ignore
-        const asyncRoute: Route = isRootModule
-          ? {
-              path: formatPath(item.path),
-              name: item.enCode,
-              redirect: 'noRedirect',
-              alwaysShow: true,
-              hidden: item.isMenu !== 1,
-              meta: {
-                title: item.name,
-                icon: item.icon,
-                moduleId: item.id,
-                rank: item?.sortCode,
-                rootMenu: true,
-              },
-            }
-          : {
-              path: formatPath(item.path),
-              name: item.enCode,
-              hidden: item.isMenu !== 1,
-              alwaysShow: true,
-              meta: {
-                title: item.name,
-                moduleId: item.id,
-                noCache: !item.isCache,
-                rank: item?.sortCode,
-              },
-            };
-        const children = formatModuleList(moduleList, item.id);
-        asyncRoute.children = children;
-        treeModuleList.push(asyncRoute);
-      }
-    });
-  }
-  return treeModuleList;
+function formatModuleList(moduleList: API.GetMenusQueryResultItem[]) {
+  return moduleList.map((item) => {
+    const isRootModule = !item.parentId && item.type == EnumMenuType.Menu;
+    //@ts-ignore
+    let asyncRoute: Route = isRootModule
+      ? {
+          path: formatPath(item.url),
+          name: item.code,
+          redirect: 'noRedirect',
+          alwaysShow: true,
+          hidden: item.type != EnumMenuType.Menu,
+          meta: {
+            title: item.name,
+            icon: item.icon,
+            moduleId: item.id,
+            rank: item?.sort,
+            rootMenu: true,
+          },
+        }
+      : {
+          path: formatPath(item.url),
+          name: item.code,
+          hidden: item.type != EnumMenuType.Menu,
+          alwaysShow: true,
+          meta: {
+            title: item.name,
+            moduleId: item.id,
+            noCache: !item.isCache,
+            rank: item?.sort,
+          },
+        };
+    const children = formatModuleList(item.children);
+    asyncRoute.children = children;
+    return asyncRoute;
+  });
 }
 
 function formatPath(path: string) {

--
Gitblit v1.9.1