From dc05cd481f186b13375192be965000e6b4b429a5 Mon Sep 17 00:00:00 2001 From: xiaojunnuo Date: Fri, 18 Apr 2025 15:23:51 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E4=BC=98=E5=8C=96/api=E7=BC=93?= =?UTF-8?q?=E5=AD=98=E4=B8=BA0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/views/certd/pipeline/crud.tsx | 2 +- packages/ui/certd-server/plugin-doc-gen.mjs | 53 +++++++++++++++++++ packages/ui/certd-server/src/configuration.ts | 2 +- 3 files changed, 55 insertions(+), 2 deletions(-) create mode 100644 packages/ui/certd-server/plugin-doc-gen.mjs diff --git a/packages/ui/certd-client/src/views/certd/pipeline/crud.tsx b/packages/ui/certd-client/src/views/certd/pipeline/crud.tsx index c710d8b8..4273db52 100644 --- a/packages/ui/certd-client/src/views/certd/pipeline/crud.tsx +++ b/packages/ui/certd-client/src/views/certd/pipeline/crud.tsx @@ -418,7 +418,7 @@ export default function ({ crudExpose, context: { certdFormRef, groupDictRef, se show: false, }, column: { - sorter: true, + sorter: false, width: 150, align: "center", }, diff --git a/packages/ui/certd-server/plugin-doc-gen.mjs b/packages/ui/certd-server/plugin-doc-gen.mjs new file mode 100644 index 00000000..f9b885ab --- /dev/null +++ b/packages/ui/certd-server/plugin-doc-gen.mjs @@ -0,0 +1,53 @@ +// 扫描目录,列出文件,然后加载为模块 + +import { join } from 'path'; +import fs from 'fs' +import { pathToFileURL } from "node:url"; +import path from 'path' +function scanDir(dir) { + const files = fs.readdirSync(dir); + const result = []; + // 扫描目录及子目录 + for (const file of files) { + if (file.includes("index.js")) { + continue; + } + + const filePath = join(dir, file); + const stat = fs.statSync(filePath); + if (stat.isDirectory()) { + result.push(...scanDir(filePath)); + } else { + if (!file.endsWith(".js")) { + continue; + } + result.push(filePath); + } + } + return result +} + +export default async function loadModules(dir) { + const files = scanDir(dir); + const modules = {} + for (const file of files) { + + try { + // 转换为 file:// URL(Windows 必需) + const moduleUrl = pathToFileURL(file).href + const module = await import(moduleUrl) + + // 如果模块有默认导出,优先使用 + modules[file] = module.default || module + } catch (err) { + console.error(`加载模块 ${file} 失败:`, err) + } + } + return modules; +} + +const modules = await loadModules('./dist/plugins'); + +for (const key in modules) { + console.log(key) +} diff --git a/packages/ui/certd-server/src/configuration.ts b/packages/ui/certd-server/src/configuration.ts index ebf6aa08..00d4ddff 100644 --- a/packages/ui/certd-server/src/configuration.ts +++ b/packages/ui/certd-server/src/configuration.ts @@ -96,7 +96,7 @@ export class MainConfiguration { this.app.getMiddleware().insertFirst(async (ctx: IMidwayKoaContext, next: NextFunction) => { await next(); - if (ctx.path === '/' || ctx.path === '/index.html') { + if (ctx.path === '/' || ctx.path === '/index.html' || ctx.path.startsWith("/api")) { ctx.response.set('Cache-Control', 'public,max-age=0'); } });