GPU_GUARD_MONOREPO/docs/code-wiki/entities/cool-admin-framework.md
2026-05-20 21:39:12 +08:00

65 lines
1.6 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
title: Cool Admin 框架
created: 2026-04-13
updated: 2026-04-13
type: entity
tags: [architecture, backend, frontend, convention]
sources: [packages/backend/package.json, packages/frontend/package.json]
---
# Cool Admin 框架
项目基于 Cool Admin 8.0 二次开发,提供自动 CRUD、动态路由、Service 代理等基础能力。
## 后端自动 CRUD
使用 `@CoolController` 装饰器自动生成标准接口:
```typescript
@CoolController({
api: ['add', 'delete', 'update', 'info', 'list', 'page'],
entity: SomeEntity,
pageQueryOp: {
keyWordLikeFields: ['name'],
fieldEq: ['status'],
addOrderBy: { createTime: 'DESC' },
},
})
```
自动生成的接口:
- `POST /admin/{module}/{entity}/add`
- `POST /admin/{module}/{entity}/delete`
- `POST /admin/{module}/{entity}/update`
- `GET /admin/{module}/{entity}/info`
- `POST /admin/{module}/{entity}/list`
- `POST /admin/{module}/{entity}/page`
## 前端 Service 代理
Cool Admin 自动将后端 Controller 映射为前端 service
```
后端: modules/project/controller/admin/info.ts
前端: service.project.info.page() / .add() / .update() / .delete()
```
自定义接口:
```typescript
service.request({ url: '/admin/project/task/ganttData', params: { projectId: 1 } })
```
## BaseEntity 通用字段
所有 Entity 继承 `BaseEntity`
- `id`(自增主键)
- `createTime`(自动填充)
- `updateTime`(自动更新)
- `tenantId`(多租户)
## 相关页面
- [[project-overview]] — 项目总览
- [[base-module]] — 基础模块使用此框架
- [[frontend-architecture]] — 前端路由和 Service 代理