mirror of
https://github.com/fastapiadmin/FastapiAdmin.git
synced 2026-09-21 04:46:26 +00:00
refactor(backend): 清理冗余模板文件并统一模板结构 fix(backend): 修复定时任务状态显示与操作逻辑 perf(backend): 优化数据库连接日志和初始化流程 style(frontend): 调整应用列表空状态显示样式 docs: 更新README中的命令说明和环境配置 chore: 添加banner.txt和统一环境变量格式
133 lines
3.2 KiB
Django/Jinja
133 lines
3.2 KiB
Django/Jinja
import request from "@/utils/request";
|
||
|
||
const API_PATH = "/{{ module_name }}/{{ business_name|lower }}";
|
||
|
||
// 参考 demo.ts 的风格,提供标准的 CRUD 与导入/导出 API(TypeScript)
|
||
const {{ class_name }}API = {
|
||
// 列表查询
|
||
list(query: {{ class_name }}PageQuery) {
|
||
return request<ApiResponse<PageResult<{{ class_name }}Table[]>>>({
|
||
url: `${API_PATH}/list`,
|
||
method: "get",
|
||
params: query,
|
||
});
|
||
},
|
||
|
||
// 详情查询
|
||
detail(id: number) {
|
||
return request<ApiResponse<{{ class_name }}Table>>({
|
||
url: `${API_PATH}/detail/${id}`,
|
||
method: "get",
|
||
});
|
||
},
|
||
|
||
// 新增
|
||
create(data: {{ class_name }}Form) {
|
||
return request<ApiResponse>({
|
||
url: `${API_PATH}/create`,
|
||
method: "post",
|
||
data,
|
||
});
|
||
},
|
||
|
||
// 修改(带主键)
|
||
update(id: number, data: {{ class_name }}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: {{ class_name }}PageQuery) {
|
||
return request<Blob>({
|
||
url: `${API_PATH}/export`,
|
||
method: "post",
|
||
data: query,
|
||
responseType: "blob",
|
||
});
|
||
},
|
||
|
||
// 下载导入模板
|
||
downloadTemplate() {
|
||
return request<Blob>({
|
||
url: `${API_PATH}/download/template`,
|
||
method: "post",
|
||
responseType: "blob",
|
||
});
|
||
},
|
||
|
||
// 导入
|
||
import(data: FormData) {
|
||
return request<ApiResponse>({
|
||
url: `${API_PATH}/import`,
|
||
method: "post",
|
||
data,
|
||
headers: { "Content-Type": "multipart/form-data" },
|
||
});
|
||
},
|
||
// 批量启用/停用
|
||
batchAvailable(body: { ids: number[]; status: boolean }) {
|
||
return request<ApiResponse>({
|
||
url: `${API_PATH}/available/setting`,
|
||
method: "patch",
|
||
data: body,
|
||
});
|
||
},
|
||
};
|
||
|
||
export default {{ class_name }}API;
|
||
|
||
// ------------------------------
|
||
// TS 类型声明
|
||
// ------------------------------
|
||
|
||
export interface {{ class_name }}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 {{ class_name }}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 {{ class_name }}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 %}
|
||
}
|