1.1 KiB
1.1 KiB
name, description, globs
| name | description | globs | ||
|---|---|---|---|---|
| frontend-admin-api | Admin 前端 API 层规范,基于项目 request/BaseService 的 API 调用模式 |
|
文件位置
frontend/admin/src/api/{module}/index.ts
代码模板
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}
检查清单
- 函数命名是否小驼峰
- 路径是否与后端路由一致
- 参数类型是否正确
- 是否处理了异常情况