ソースを参照

swagger文档

zhangzl 2 ヶ月 前
コミット
e50c2b7129

+ 2 - 0
new-react-admin-ui/src/App.tsx

@@ -16,6 +16,7 @@ import { MenuCreate } from '@/pages/menus/MenuCreate';
 import { Dashboard } from '@/pages/Dashboard';
 import { Layout } from '@/components/Layout';
 import ErrorPage from '@/pages/ErrorPage';
+import SwaggerPage from '@/pages/swagger/SwaggerPage';
 
 // 创建主题
 const theme = createTheme({
@@ -67,6 +68,7 @@ export const App = () => {
         
         <CustomRoutes noLayout>
           <Route path="/error" element={<ErrorPage />} />
+          <Route path="/tool/swagger" element={<SwaggerPage />} />
         </CustomRoutes>
         
         {/* Dashboard通过Resource自动路由,无需CustomRoutes */}

+ 13 - 2
new-react-admin-ui/src/components/CustomMenu.tsx

@@ -32,6 +32,11 @@ const getResourceName = (fullPath: string): string => {
     return 'dashboard';
   }
   
+  // 特殊处理:swagger路径直接映射到/tool/swagger
+  if (fullPath === 'swagger') {
+    return 'tool/swagger';
+  }
+  
   // 对于其他路径,直接将最后一个路径段转换为复数形式
   const pathSegments = fullPath.split('/');
   const lastSegment = pathSegments[pathSegments.length - 1];
@@ -51,6 +56,11 @@ const getResourceName = (fullPath: string): string => {
 
 // 根据菜单类型获取图标
 const getMenuIcon = (menuType: 'M' | 'C' | 'F', customIcon?: string) => {
+  // 特殊处理:swagger图标
+  if (customIcon === 'swagger') {
+    return <SettingsIcon fontSize="small" />;
+  }
+  
   if (customIcon) {
     // 这里可以处理自定义图标,暂时使用默认图标
     return <SettingsIcon fontSize="small" />;
@@ -75,12 +85,13 @@ const renderMenuTree = (menus: MenuItem[], basePath = '', expandedItems: Set<str
     
     // 只渲染菜单类型为C(菜单)的项
     if (menu.menuType === 'C' && menu.path && fullPath) {
-      const resourceName = getResourceName(fullPath);
+      // 特殊处理:swagger菜单项直接导航到/tool/swagger
+      const toPath = menu.path === 'swagger' ? '/tool/swagger' : `/${getResourceName(fullPath)}`;
       
       return (
         <MenuItemLink
           key={`menu-${menu.menuId}`}
-          to={`/${resourceName}`}
+          to={toPath}
           primaryText={menu.menuName}
           leftIcon={getMenuIcon(menu.menuType, menu.icon)}
           sx={{

+ 44 - 0
new-react-admin-ui/src/pages/swagger/SwaggerPage.tsx

@@ -0,0 +1,44 @@
+import React from 'react';
+import { Card, CardContent, Box, Typography, Button } from '@mui/material';
+import { OpenInNew } from '@mui/icons-material';
+
+const SwaggerPage: React.FC = () => {
+  const handleOpenSwagger = () => {
+    // 在新窗口中打开Swagger UI
+    window.open('http://localhost:8080/swagger-ui.html', '_blank');
+  };
+
+  return (
+    <Box sx={{ p: 2, height: '100%' }}>
+      <Typography variant="h4" component="h1" gutterBottom>
+        API 文档
+      </Typography>
+      <Typography variant="body1" color="text.secondary" paragraph>
+        Swagger API 文档提供了系统所有接口的详细说明和测试功能。
+      </Typography>
+      
+      <Card sx={{ mt: 2, p: 4, textAlign: 'center' }}>
+        <CardContent>
+          <Typography variant="h6" gutterBottom>
+            点击下方按钮在新窗口中打开 Swagger API 文档
+          </Typography>
+          <Typography variant="body2" color="text.secondary" paragraph>
+            由于浏览器安全策略限制,无法在当前页面中嵌入 Swagger UI,
+            因此需要在新窗口中打开。
+          </Typography>
+          <Button
+            variant="contained"
+            size="large"
+            startIcon={<OpenInNew />}
+            onClick={handleOpenSwagger}
+            sx={{ mt: 2 }}
+          >
+            打开 Swagger API 文档
+          </Button>
+        </CardContent>
+      </Card>
+    </Box>
+  );
+};
+
+export default SwaggerPage;

+ 23 - 3
ruoyi-admin/src/main/resources/application.yml

@@ -124,10 +124,30 @@ springdoc:
     path: /swagger-ui.html
     tags-sorter: alpha
   group-configs:
-    - group: 'default'
-      display-name: '测试模块'
-      paths-to-match: '/**'
+    - group: 'system'
+      display-name: '系统管理'
+      paths-to-match: '/system/**'
+      packages-to-scan: com.ruoyi.web.controller.system
+    - group: 'monitor'
+      display-name: '系统监控'
+      paths-to-match: '/monitor/**'
+      packages-to-scan: com.ruoyi.web.controller.monitor
+    - group: 'tool'
+      display-name: '系统工具'
+      paths-to-match: '/tool/**'
       packages-to-scan: com.ruoyi.web.controller.tool
+    - group: 'common'
+      display-name: '通用接口'
+      paths-to-match: '/common/**'
+      packages-to-scan: com.ruoyi.web.controller.common
+    - group: 'quartz'
+      display-name: '定时任务'
+      paths-to-match: '/monitor/job/**'
+      packages-to-scan: com.ruoyi.quartz.controller
+    - group: 'generator'
+      display-name: '代码生成'
+      paths-to-match: '/tool/gen/**'
+      packages-to-scan: com.ruoyi.generator.controller
 
 # 防止XSS攻击
 xss: