初始化本地仓库
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
---
|
||||
name: frontend-admin-api
|
||||
description: Admin 前端 API 层规范,基于项目 request/BaseService 的 API 调用模式
|
||||
globs:
|
||||
- "frontend/admin/src/api/**/*.ts"
|
||||
- "apps/**/src/api/**/*.ts"
|
||||
---
|
||||
|
||||
## 文件位置
|
||||
|
||||
```
|
||||
frontend/admin/src/api/{module}/index.ts
|
||||
```
|
||||
|
||||
## 代码模板
|
||||
|
||||
```typescript
|
||||
import BaseService from '@/api/core/base';
|
||||
import request from '@/utils/http';
|
||||
|
||||
const baseUrl = '/{module}/{model}';
|
||||
|
||||
export const {Model}Service = {
|
||||
...BaseService<{Model}Row>({ baseUrl, allowedMethods: ['list', 'get', 'delete'] }),
|
||||
|
||||
customAction(id: string | number) {
|
||||
return request.post({ url: `${baseUrl}/${id}/custom-action` });
|
||||
},
|
||||
};
|
||||
```
|
||||
|
||||
## 关键约定
|
||||
|
||||
- API 服务命名:`{Model}Service`
|
||||
- CRUD 路径:`/{module}/{model}`
|
||||
- 通用 CRUD 优先复用 `@/api/core/base` 的 `BaseService`
|
||||
- 自定义动作使用 `@/utils/http` 的 `request.get/post/put/del`
|
||||
- 响应格式:`{code: 0, msg: 'ok', data: {...}}`
|
||||
- 列表返回:`{items: [], total: N}`
|
||||
|
||||
## 检查清单
|
||||
|
||||
- [ ] 函数命名是否小驼峰
|
||||
- [ ] 路径是否与后端路由一致
|
||||
- [ ] 参数类型是否正确
|
||||
- [ ] 是否处理了异常情况
|
||||
Reference in New Issue
Block a user