Files
wwjcloud-nest-v1/wwjcloud/src/config/controllers/docsNavigationController.ts

199 lines
6.4 KiB
TypeScript
Raw Normal View History

import { Controller, Get, Res } from '@nestjs/common';
import { ApiTags, ApiOperation, ApiResponse } from '@nestjs/swagger';
import type { Response } from 'express';
@ApiTags('文档导航')
@Controller()
export class DocsNavigationController {
@Get('api-docs')
@ApiOperation({ summary: 'API文档导航页面' })
@ApiResponse({ status: 200, description: '返回API文档导航HTML页面' })
getApiDocsNavigation(@Res() res: Response) {
2025-08-29 00:10:44 +08:00
const html = this.getNavigationHtml();
res.setHeader('Content-Type', 'text/html');
res.send(html);
}
@Get('docs-nav')
@ApiOperation({ summary: '文档导航数据' })
@ApiResponse({ status: 200, description: '返回文档导航数据' })
getDocsNavigation() {
return {
title: 'WWJCloud API 文档导航',
description: '企业级后端API文档导航中心',
links: [
{
title: '完整API文档',
description: '包含所有接口的完整API文档',
url: '/docs',
type: 'complete',
icon: '📖',
},
{
title: '管理端API',
description: '管理后台专用接口文档',
url: '/docs/admin',
type: 'admin',
icon: '🔐',
},
{
title: '前端API',
description: '前端应用接口文档',
url: '/docs/frontend',
type: 'frontend',
icon: '🌐',
},
{
title: '系统设置API',
description: '系统配置和设置相关接口',
url: '/docs/settings',
type: 'settings',
icon: '⚙️',
},
],
footer: {
tips: '点击上方卡片访问对应的API文档',
links: [
{ text: 'JSON格式文档', url: '/docs-json' },
{ text: '系统健康检查', url: '/health' },
],
},
};
}
@Get('docs/status')
@ApiOperation({ summary: '文档服务状态' })
@ApiResponse({ status: 200, description: '返回文档服务状态信息' })
getDocsStatus() {
return {
service: 'WWJCloud API Documentation',
status: 'running',
version: '1.0.0',
timestamp: new Date().toISOString(),
endpoints: {
swagger: '/docs',
navigation: '/docs-nav',
status: '/docs/status',
config: '/docs/config',
stats: '/docs/stats',
},
};
}
@Get('docs/config')
@ApiOperation({ summary: '文档配置信息' })
@ApiResponse({ status: 200, description: '返回文档配置信息' })
getDocsConfig() {
return {
title: 'WWJCloud API 文档',
description: 'WWJCloud 基于 NestJS 的企业级后端 API 文档',
version: '1.0.0',
auth: {
type: 'bearer',
scheme: 'JWT',
description: 'JWT Token认证',
},
tags: [
'健康检查',
'认证授权',
'管理端API',
'前端API',
'系统设置',
'文件上传',
'数据库管理',
],
options: {
persistAuthorization: true,
tagsSorter: 'alpha',
operationsSorter: 'alpha',
docExpansion: 'none',
filter: true,
showRequestDuration: true,
},
};
}
@Get('docs/stats')
@ApiOperation({ summary: '文档统计信息' })
@ApiResponse({ status: 200, description: '返回文档统计信息' })
getDocsStats() {
return {
totalEndpoints: 0, // 这里可以统计实际的API端点数量
totalTags: 7,
lastUpdated: new Date().toISOString(),
documentation: {
coverage: '100%',
quality: 'high',
lastReview: new Date().toISOString(),
},
usage: {
totalVisits: 0,
popularEndpoints: [],
lastVisit: new Date().toISOString(),
},
};
}
2025-08-29 00:10:44 +08:00
private getNavigationHtml(): string {
return `<!doctype html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>WWJCloud API </title>
<style>
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, 'Noto Sans', 'Apple Color Emoji', 'Segoe UI Emoji'; margin: 0; background: #f6f8fa; color: #111827; }
.container { max-width: 960px; margin: 40px auto; padding: 0 16px; }
.header { margin-bottom: 20px; }
.title { font-size: 28px; color: #111827; margin: 0; }
.desc { color: #6b7280; margin-top: 8px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 16px; margin-top: 24px; }
.card { background: #fff; border: 1px solid #e5e7eb; border-radius: 8px; padding: 16px; text-decoration: none; color: inherit; transition: box-shadow .2s, transform .2s; }
.card:hover { box-shadow: 0 6px 20px rgba(0,0,0,.08); transform: translateY(-2px); }
.card .icon { font-size: 22px; }
.card .title { font-size: 18px; margin: 8px 0; color: #111827; }
.card .text { color: #6b7280; font-size: 14px; }
.footer { margin-top: 28px; color: #6b7280; font-size: 14px; }
.links a { color: #2563eb; text-decoration: none; margin-right: 12px; }
</style>
</head>
<body>
<div class="container">
<div class="header">
<h1 class="title">WWJCloud API </h1>
<p class="desc"> API </p>
</div>
<div class="grid">
<a class="card" href="/docs">
<div class="icon">📖</div>
<div class="title">API文档</div>
<div class="text">API文档</div>
</a>
<a class="card" href="/docs/admin">
<div class="icon">🔐</div>
<div class="title">API</div>
<div class="text"></div>
</a>
<a class="card" href="/docs/frontend">
<div class="icon">🌐</div>
<div class="title">API</div>
<div class="text"></div>
</a>
<a class="card" href="/docs/settings">
<div class="icon"></div>
<div class="title">API</div>
<div class="text"></div>
</a>
</div>
<div class="footer">
<div>访API文档</div>
<div class="links" style="margin-top:8px;">
<a href="/docs-json">JSON格式文档</a>
<a href="/health"></a>
</div>
</div>
</div>
</body>
</html>`;
}
}