diff --git a/templates/vue/api.ts.j2 b/templates/vue/api.ts.j2 new file mode 100644 index 0000000..7b5ea03 --- /dev/null +++ b/templates/vue/api.ts.j2 @@ -0,0 +1,42 @@ +/** + * 自动生成 API + * 负责调用后端接口 + */ + +import { requestClient } from '#/api/request'; +import { useAppConfig } from '@vben/hooks'; + +export namespace {{entity}}Api { + + const applicationConfig = useAppConfig(import.meta.env, import.meta.env.PROD); + console.log('=== 接口域名 ===', applicationConfig.javaURL) + + /** + * 分页查询 + */ + export function page(params: any) { + return requestClient.post(applicationConfig.javaURL+'/{{table}}/page', { params }); + } + + /** + * 获取详情 + */ + export function get(id: number) { + return requestClient.get(applicationConfig.javaURL+'/{{table}}/' + id); + } + + /** + * 新增 / 修改 + */ + export function save(data: any) { + return requestClient.post(applicationConfig.javaURL+'/{{table}}', data); + } + + /** + * 删除 + */ + export function remove(id: number) { + return requestClient.delete(applicationConfig.javaURL+'/{{table}}/' + id); + } + +} \ No newline at end of file