feat: 新增代码生成

This commit is contained in:
Solution_Lin
2024-04-19 00:57:27 +00:00
committed by Charles7c
parent 4a40ab0e7e
commit 6321de7cac
7 changed files with 499 additions and 0 deletions

View File

@@ -3,9 +3,11 @@ export * from './auth'
export * from './common'
export * from './monitor'
export * from './system'
export * from './tool'
export * from './area/type'
export * from './auth/type'
export * from './common/type'
export * from './monitor/type'
export * from './system/type'
export * from './tool/type'

View File

@@ -0,0 +1,38 @@
import http from '@/utils/http'
import type * as Tool from './type'
const BASE_URL = '/generator'
/** @desc 查询代码生成列表 */
export function listGenerator(query: Tool.TablePageQuery) {
return http.get<PageRes<Tool.TableResp[]>>(`${BASE_URL}/table`, query)
}
/** @desc 查询字段配置列表 */
export function listFieldConfig(tableName: string, requireSync: boolean) {
return http.get<Tool.FieldConfigResp[]>(`${BASE_URL}/field/${tableName}?requireSync=${requireSync}`)
}
/** @desc 查询生成配置信息 */
export function getGenConfig(tableName: string) {
return http.get<Tool.GenConfigResp>(`${BASE_URL}/config/${tableName}`)
}
/** @desc 保存配置信息 */
export function saveGenConfig(tableName: string, req: Tool.GeneratorConfigResp) {
return http.post(`${BASE_URL}/config/${tableName}`, req)
}
/** @desc 生成预览 */
export function genPreview(tableName: string) {
return http.get<Tool.GeneratePreviewResp[]>(`${BASE_URL}/preview/${tableName}`)
}
/** @desc 生成代码 */
export function generate(tableNames: Array<string>) {
return http.requestNative({
url: `${BASE_URL}/${tableNames}`,
method: 'post',
responseType: 'blob'
})
}

1
src/apis/tool/index.ts Normal file
View File

@@ -0,0 +1 @@
export * from './generator'

49
src/apis/tool/type.ts Normal file
View File

@@ -0,0 +1,49 @@
/** 工具代码生成类型 */
export interface TableResp {
tableName: string
comment?: string
engine: string
charset: string
createTime?: string
isConfiged: boolean
disabled: boolean
}
export interface TableQuery {
tableName?: string
}
export interface TablePageQuery extends PageQuery, TableQuery {}
export interface FieldConfigResp {
tableName: string
columnName: string
columnType: string
fieldName: string
fieldType: string
fieldSort: number
comment: string
isRequired: boolean
showInList: boolean
showInForm: boolean
showInQuery: boolean
formType: string
queryType: string
createTime?: string
}
export interface GenConfigResp {
tableName: string
moduleName: string
packageName: string
businessName: string
author: string
tablePrefix: string
isOverride: boolean
createTime?: string
updateTime?: string
}
export interface GeneratorConfigResp {
genConfig: GenConfigResp
fieldConfigs: FieldConfigResp[]
}
export interface GeneratePreviewResp {
fileName: string
content: string
}