Browse Source

feat(菜单管理): 修复详情路由无法跳转问题

xieyonghong 3 years atrás
parent
commit
ad4dea264d
3 changed files with 16 additions and 5 deletions
  1. 1 0
      src/app.tsx
  2. 2 5
      src/pages/system/Menu/index.tsx
  3. 13 0
      src/utils/menu.ts

+ 1 - 0
src/app.tsx

@@ -210,6 +210,7 @@ export const layout: RunTimeLayoutConfig = ({ initialState }) => {
 
 export function patchRoutes(routes: any) {
   if (extraRoutes && extraRoutes.length) {
+    console.log(getRoutes(extraRoutes));
     routes.routes[1].routes = [...routes.routes[1].routes, ...getRoutes(extraRoutes)];
   }
 }

+ 2 - 5
src/pages/system/Menu/index.tsx

@@ -4,7 +4,7 @@ import ProTable from '@jetlinks/pro-table';
 import type { ActionType, ProColumns } from '@jetlinks/pro-table';
 import { useRef, useState } from 'react';
 import { useIntl } from '@@/plugin-locale/localeExports';
-import { Button, message, Popconfirm, Tooltip, Card, Divider, Modal, Form, Input } from 'antd';
+import { Button, message, Popconfirm, Tooltip, Modal, Form, Input } from 'antd';
 import {
   SearchOutlined,
   PlusOutlined,
@@ -218,10 +218,7 @@ export default observer(() => {
 
   return (
     <PageContainer>
-      <Card>
-        <SearchComponent field={columns} onSearch={searchFn} />
-      </Card>
-      <Divider />
+      <SearchComponent field={columns} onSearch={searchFn} />
       <ProTable<MenuItem>
         columns={columns}
         actionRef={actionRef}

+ 13 - 0
src/utils/menu.ts

@@ -156,6 +156,7 @@ const getRoutes = (extraRoutes: MenuItem[], level: number = 1) => {
     }
     if (component) {
       _route.component = component;
+      _route.exact = true;
       Menus.push(_route);
     }
   });
@@ -210,7 +211,19 @@ export const saveMenusCache = (routes: MenuItem[]) => {
 export const getMenuPathByCode = (code: string): string => {
   const menusStr = localStorage.getItem(MENUS_DATA_CACHE) || '{}';
   const menusData = JSON.parse(menusStr);
+  console.log(code, menusData);
   return menusData[code];
 };
 
+/**
+ * 通过缓存的数据取出相应的路由url
+ * @param code 路由Code
+ * @param id 路由携带参数
+ * @param regStr 路由参数code
+ */
+export const getMenuPathByParams = (code: string, id: string, regStr: string = ':id') => {
+  const menusData = getMenuPathByCode(code);
+  return menusData.replace(regStr, id);
+};
+
 export default getRoutes;