mirror of
https://github.com/fastapiadmin/FastapiAdmin.git
synced 2026-09-26 22:31:21 +00:00
style: 统一代码风格和格式 docs: 完善函数和方法的文档字符串 refactor(base_model): 移除冗余的表名和表参数生成方法 refactor(constant): 更新返回码注释格式 refactor(router_class): 添加路由处理器的详细文档 refactor(database): 完善数据库连接函数的文档 refactor(security): 添加认证类和方法的详细文档 refactor(validator): 更新验证器函数的文档格式 refactor(serialize): 优化序列化工具类的文档 refactor(response): 完善响应类的文档字符串 refactor(dependencies): 添加依赖函数的详细文档 refactor(initialize): 完善初始化脚本的文档 refactor(plugin): 添加生命周期和中间件注册的文档 refactor(service): 完善服务层方法的文档 refactor(controller): 添加控制器方法的详细文档 refactor(crud): 完善CRUD操作的文档字符串 refactor(schema): 简化模型类并移除冗余字段 refactor(param): 更新查询参数类的注释格式 refactor(template): 优化代码生成模板的格式 refactor(console): 添加控制台输出功能的实现 refactor(util): 完善工具函数的文档字符串
125 lines
3.5 KiB
Django/Jinja
125 lines
3.5 KiB
Django/Jinja
import request from "@/utils/request";
|
||
|
||
const API_PATH = "/{{ module_name }}/{{ business_name }}";
|
||
|
||
// 参考 demo.ts 的风格,提供标准的 CRUD 与导入/导出 API(TypeScript)
|
||
const {{ business_name|replace('_', ' ')|title|replace(' ', '') }}API = {
|
||
// 列表查询
|
||
list(query: {{ business_name|replace('_', ' ')|title|replace(' ', '') }}PageQuery) {
|
||
return request<ApiResponse<PageResult<{{ business_name|replace('_', ' ')|title|replace(' ', '') }}Table[]>>>({
|
||
url: `${API_PATH}/list`,
|
||
method: "get",
|
||
params: query,
|
||
});
|
||
},
|
||
|
||
// 详情查询
|
||
detail(id: number) {
|
||
return request<ApiResponse<{{ business_name|replace('_', ' ')|title|replace(' ', '') }}Table>>({
|
||
url: `${API_PATH}/detail/${id}`,
|
||
method: "get",
|
||
});
|
||
},
|
||
|
||
// 新增
|
||
create(data: {{ business_name|replace('_', ' ')|title|replace(' ', '') }}Form) {
|
||
return request<ApiResponse>({
|
||
url: `${API_PATH}/create`,
|
||
method: "post",
|
||
data,
|
||
});
|
||
},
|
||
|
||
// 修改(带主键)
|
||
update(id: number, data: {{ business_name|replace('_', ' ')|title|replace(' ', '') }}Form) {
|
||
return request<ApiResponse>({
|
||
url: `${API_PATH}/update/${id}`,
|
||
method: "put",
|
||
data,
|
||
});
|
||
},
|
||
|
||
// 删除(支持批量)
|
||
delete(ids: number[]) {
|
||
return request<ApiResponse>({
|
||
url: `${API_PATH}/delete`,
|
||
method: "delete",
|
||
data: ids,
|
||
});
|
||
},
|
||
|
||
// 导出
|
||
export(query: {{ business_name|replace('_', ' ')|title|replace(' ', '') }}PageQuery) {
|
||
return request<Blob>({
|
||
url: `${API_PATH}/export`,
|
||
method: "post",
|
||
data: query,
|
||
responseType: "blob",
|
||
});
|
||
},
|
||
|
||
// 下载导入模板
|
||
downloadTemplate() {
|
||
return request<ApiResponse>({
|
||
url: `${API_PATH}/download/template`,
|
||
method: "post",
|
||
responseType: "blob",
|
||
});
|
||
},
|
||
|
||
// 导入
|
||
import(data: any) {
|
||
return request<ApiResponse>({
|
||
url: `${API_PATH}/import`,
|
||
method: "post",
|
||
data,
|
||
headers: { "Content-Type": "multipart/form-data" },
|
||
});
|
||
},
|
||
};
|
||
|
||
export default {{ business_name|replace('_', ' ')|title|replace(' ', '') }}API;
|
||
|
||
// ------------------------------
|
||
// TS 类型声明
|
||
// ------------------------------
|
||
|
||
export interface {{ business_name|replace('_', ' ')|title|replace(' ', '') }}PageQuery extends PageQuery {
|
||
{% for column in columns %}
|
||
{% if column.is_query == "1" and column.query_type != "BETWEEN" %}
|
||
{{ column.python_field }}?: {{
|
||
'boolean' if ('status' in (column.python_field|lower)) or (column.html_type == 'radio')
|
||
else 'number' if column.is_pk == '1'
|
||
else 'string'
|
||
}};
|
||
{% endif %}
|
||
{% endfor %}
|
||
// 时间范围查询(按示例统一字段名,如需按字段拆分可在页面层处理)
|
||
start_time?: string;
|
||
end_time?: string;
|
||
}
|
||
|
||
export interface {{ business_name|replace('_', ' ')|title|replace(' ', '') }}Table {
|
||
{% for column in columns %}
|
||
{{ column.python_field }}?: {{
|
||
'boolean' if ('status' in (column.python_field|lower)) or (column.html_type == 'radio')
|
||
else 'number' if column.is_pk == '1'
|
||
else 'string'
|
||
}};
|
||
{% endfor %}
|
||
creator?: creatorType;
|
||
}
|
||
|
||
export interface {{ business_name|replace('_', ' ')|title|replace(' ', '') }}Form {
|
||
id?: number;
|
||
{% for column in columns %}
|
||
{% if column.is_insert == "1" or column.is_edit == "1" %}
|
||
{{ column.python_field }}?: {{
|
||
'boolean' if ('status' in (column.python_field|lower)) or (column.html_type == 'radio')
|
||
else 'number' if column.is_pk == '1'
|
||
else 'string'
|
||
}};
|
||
{% endif %}
|
||
{% endfor %}
|
||
}
|