86133 | aaa3f5d | 2025-04-20 21:33:29 +0800 | [diff] [blame] | 1 | import { request } from '@umijs/max'; |
| 2 | import { downLoadZip } from '@/utils/downloadfile'; |
| 3 | import type { GenCodeType, GenCodeTableListParams } from './data.d'; |
| 4 | |
| 5 | // 查询分页列表 |
| 6 | export 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 | // 查询表信息 |
| 18 | export 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 | // 查询数据表信息 |
| 28 | export 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 | // 导入数据表信息 |
| 40 | export 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 | // 删除 |
| 50 | export 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 | // 添加数据 |
| 60 | export async function addData(params: GenCodeType) { |
| 61 | return request('/api/code/gen', { |
| 62 | method: 'POST', |
| 63 | data: { |
| 64 | ...params, |
| 65 | }, |
| 66 | }); |
| 67 | } |
| 68 | |
| 69 | // 更新数据 |
| 70 | export async function updateData(params: GenCodeType) { |
| 71 | return request('/api/code/gen', { |
| 72 | method: 'PUT', |
| 73 | data: { |
| 74 | ...params, |
| 75 | }, |
| 76 | }); |
| 77 | } |
| 78 | |
| 79 | // 更新状态 |
| 80 | export async function syncDbInfo(tableName: string) { |
| 81 | return request(`/api/code/gen/synchDb/${tableName}`, { |
| 82 | method: 'GET', |
| 83 | }); |
| 84 | } |
| 85 | |
| 86 | // 生成代码(自定义路径) |
| 87 | export async function genCode(tableName: string) { |
| 88 | return request(`/api/code/gen/genCode/${tableName}`, { |
| 89 | method: 'GET', |
| 90 | }); |
| 91 | } |
| 92 | |
| 93 | // 生成代码(压缩包) |
| 94 | export async function batchGenCode(tableName: string) { |
| 95 | return downLoadZip(`/api/code/gen/batchGenCode?tables=${tableName}`); |
| 96 | } |
| 97 | |
| 98 | // 预览 |
| 99 | export 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 | } |