blob: 0e472ee9f8dbc066c0eaab971b6c1cdbaa0c6fbe [file] [log] [blame]
86133aaa3f5d2025-04-20 21:33:29 +08001import { request } from '@umijs/max';
2import { downLoadZip } from '@/utils/downloadfile';
3import type { GenCodeType, GenCodeTableListParams } from './data.d';
4
5// 查询分页列表
6export async function getGenCodeList(params?: GenCodeTableListParams) {
7 const queryString = new URLSearchParams(params).toString();
8 return request(`/api/code/gen/list?${queryString}`, {
9 data: params,
10 method: 'get',
11 headers: {
12 'Content-Type': 'application/json;charset=UTF-8',
13 },
14 });
15}
16
17// 查询表信息
18export async function getGenCode(id?: string) {
19 return request(`/api/code/gen/${id}`, {
20 method: 'get',
21 headers: {
22 'Content-Type': 'application/json;charset=UTF-8',
23 },
24 });
25}
26
27// 查询数据表信息
28export async function queryTableList(params?: any) {
29 const queryString = new URLSearchParams(params).toString();
30 return request(`/api/code/gen/db/list?${queryString}`, {
31 data: params,
32 method: 'get',
33 headers: {
34 'Content-Type': 'application/json;charset=UTF-8',
35 },
36 });
37}
38
39// 导入数据表信息
40export async function importTables(tables?: string) {
41 return request(`/api/code/gen/importTable?tables=${tables}`, {
42 method: 'POST',
43 headers: {
44 'Content-Type': 'application/json;charset=UTF-8',
45 },
46 });
47}
48
49// 删除
50export async function removeData(params: { ids: string[] }) {
51 return request(`/api/code/gen/${params.ids}`, {
52 method: 'delete',
53 headers: {
54 'Content-Type': 'application/json;charset=UTF-8',
55 },
56 });
57}
58
59// 添加数据
60export async function addData(params: GenCodeType) {
61 return request('/api/code/gen', {
62 method: 'POST',
63 data: {
64 ...params,
65 },
66 });
67}
68
69// 更新数据
70export async function updateData(params: GenCodeType) {
71 return request('/api/code/gen', {
72 method: 'PUT',
73 data: {
74 ...params,
75 },
76 });
77}
78
79// 更新状态
80export async function syncDbInfo(tableName: string) {
81 return request(`/api/code/gen/synchDb/${tableName}`, {
82 method: 'GET',
83 });
84}
85
86// 生成代码(自定义路径)
87export async function genCode(tableName: string) {
88 return request(`/api/code/gen/genCode/${tableName}`, {
89 method: 'GET',
90 });
91}
92
93// 生成代码(压缩包)
94export async function batchGenCode(tableName: string) {
95 return downLoadZip(`/api/code/gen/batchGenCode?tables=${tableName}`);
96}
97
98// 预览
99export async function previewCode(id: string) {
100 return request(`/api/code/gen/preview/${id}`, {
101 method: 'GET',
102 headers: {
103 'Content-Type': 'application/json;charset=UTF-8',
104 },
105 });
106}